FriendlyCaptcha / friendly-pow

The PoW challenge library used by Friendly Captcha
202 stars 20 forks source link

fix cleanup tail of ctx.b in blake2bFinal #3

Closed MaxGraey closed 4 years ago

MaxGraey commented 4 years ago

during recent improvments & refactoring I made one mistake and this original code:

  ctx.t += c;
  while (c < 128) { // fill up with zeros
    unchecked(b[c++] = 0);
  }
  ctx.c = c;

is not equivalent to:

ctx.t += ctx.c; // mark last block offset
ctx.b.fill(0, ctx.c, 128);
ctx.c += 128;

and should be instead:

ctx.t += ctx.c; // mark last block offset
const tc = 128 - ctx.c;
ctx.b.fill(0, ctx.c, tc);
ctx.c += tc;