/* * This function computes Phash with the specified HMAC * engine, XORing the output with the current contents of * the outBuf[] buffer. */ static void Phash(HMAC hm, byte[] s, int soff, int slen, byte[] bufa, byte[] bufb, byte[] label, byte[] seed, byte[] outBuf, int outOff, int outLen) { /* * Set the key for HMAC. */ hm.SetKey(s, soff, slen); /* * Compute A(1) = HMAC(secret, seed). */ hm.Update(label); hm.Update(seed); hm.DoFinal(bufa, 0); while (outLen > 0) { /* * Next chunk: HMAC(secret, A(i) + label + seed) */ hm.Update(bufa); hm.Update(label); hm.Update(seed); hm.DoFinal(bufb, 0); int clen = Math.Min(hm.MACSize, outLen); for (int i = 0; i < clen; i++) { outBuf[outOff++] ^= bufb[i]; } outLen -= clen; /* * If we are not finished, then compute: * A(i+1) = HMAC(secret, A(i)) */ if (outLen > 0) { hm.Update(bufa); hm.DoFinal(bufa, 0); } } }