#include "adler_32.h"

uint32_t adler_32(const uint8_t *buf, size_t buflen)
{
  constexpr uint32_t MOD_ADLER = 65521;
  uint32_t a = 1;
  uint32_t b = 0;

  while ( buflen-- )
  {
    a = (a + *buf++) % MOD_ADLER;
    b = (b + a) % MOD_ADLER;
  }

  return (b << 16) | a;
}
