/* *blake2b.c-definitionsfortheblake2bhashfunction * *ThisSourceCodeFormissubjecttothetermsoftheMozillaPublic *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** *Thismacroimplementstheblake2bmixingfunctionwhichmixestwo8-byte *wordsfromthemessageintothehash.
*/ #define G(a, b, c, d, x, y) \
a += b + x; \
d = ROTR64(d ^ a, 32); \
c += d; \
b = ROTR64(b ^ c, 24); \
a += b + y; \
d = ROTR64(d ^ a, 16); \
c += d; \
b = ROTR64(b ^ c, 63)
/** *Thisfunctionupdatesblake2bctxandcanbeusedforbothkeyedandunkeyed *version.
*/
SECStatus
BLAKE2B_Update(BLAKE2BContext* ctx, constunsignedchar* in, unsignedint inlen)
{ /* Nothing to do if there's nothing. */ if (inlen == 0) { return SECSuccess;
}
if (!ctx || !in) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
}
/* Is this a reused context? */ if (ctx->f) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
}
size_t left = ctx->buflen;
PORT_Assert(left <= BLAKE2B_BLOCK_LENGTH);
size_t fill = BLAKE2B_BLOCK_LENGTH - left;
if (inlen > fill) { if (ctx->buflen) { /* There's some remaining data in ctx->buf that we have to prepend
* to in. */
PORT_Memcpy(ctx->buf + left, in, fill);
ctx->buflen = 0;
blake2b_IncrementCompress(ctx, BLAKE2B_BLOCK_LENGTH, ctx->buf);
in += fill;
inlen -= fill;
} while (inlen > BLAKE2B_BLOCK_LENGTH) {
blake2b_IncrementCompress(ctx, BLAKE2B_BLOCK_LENGTH, in);
in += BLAKE2B_BLOCK_LENGTH;
inlen -= BLAKE2B_BLOCK_LENGTH;
}
}
/* Store the remaining data from in in ctx->buf to process later. *Notethatctx->buflencanbeBLAKE2B_BLOCK_LENGTH.Wecan'tprocessthat *herebecausewehavetoupdatectx->fbeforecompressingthelastblock.
*/
PORT_Assert(inlen <= BLAKE2B_BLOCK_LENGTH);
PORT_Memcpy(ctx->buf + ctx->buflen, in, inlen);
ctx->buflen += inlen;
/* Sanity check against outlen in context. */ if (ctx->outlen < outlen) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
}
/* Is this a reused context? */ if (ctx->f != 0) {
PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure;
}
/* Process the remaining data from ctx->buf (padded with 0). */
blake2b_IncrementCounter(ctx, ctx->buflen); /* BLAKE2B_BLOCK_LENGTH - ctx->buflen can be 0. */
PORT_Memset(ctx->buf + ctx->buflen, 0, BLAKE2B_BLOCK_LENGTH - ctx->buflen);
ctx->f = UINT64_MAX;
blake2b_Compress(ctx, ctx->buf);
/* Write out the blake2b context(ctx). */ for (i = 0; i < outlen; ++i) {
out[i] = ctx->h[i / 8] >> ((i % 8) * 8);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.