src/libs/blake2b.js
function blake2bInit(outlen, key) {
    if (outlen === 0 || outlen > 64) {
        throw new Error('Illegal output length, expected 0 < length <= 64');
    }
    if (key && key.length > 64) {
        throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64');
    }
    // state, 'param block'
    var ctx = {
        b: new Uint8Array(128),
        h: new Uint32Array(16),
        t: 0,
        c: 0,
        outlen: outlen // output length in bytes
    };
    // initialize hash state
    for (var i = 0; i < 16; i++) {
        ctx.h[i] = BLAKE2B_IV32[i];
    }
    var keylen = key ? key.length : 0;
    ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
    // key the hash, if applicable
    if (key) {
        blake2bUpdate(ctx, key);
        // at the end
        ctx.c = 128;
    }
    return ctx;
}
function blake2bInit(outlen, key) {
    if (outlen === 0 || outlen > 64) {
        throw new Error('Illegal output length, expected 0 < length <= 64');
    }
    if (key && key.length > 64) {
        throw new Error('Illegal key, expected Uint8Array with 0 < length <= 64');
    }
    // state, 'param block'
    var ctx = {
        b: new Uint8Array(128),
        h: new Uint32Array(16),
        t: 0,
        c: 0,
        outlen: outlen // output length in bytes
    };
    // initialize hash state
    for (var i = 0; i < 16; i++) {
        ctx.h[i] = BLAKE2B_IV32[i];
    }
    var keylen = key ? key.length : 0;
    ctx.h[0] ^= 0x01010000 ^ (keylen << 8) ^ outlen;
    // key the hash, if applicable
    if (key) {
        blake2bUpdate(ctx, key);
        // at the end
        ctx.c = 128;
    }
    return ctx;
}
function blake2bInit ( outlen , key ) { if ( outlen === 0 || outlen > 64 ) { throw new Error ( 'Illegal output length, expected 0 < length <= 64' ) ; } if ( key && key . length > 64 ) { throw new Error ( 'Illegal key, expected Uint8Array with 0 < length <= 64' ) ; } // state, 'param block' var ctx = { b : new Uint8Array ( 128 ) , h : new Uint32Array ( 16 ) , t : 0 , c : 0 , outlen : outlen // output length in bytes } ; // initialize hash state for ( var i = 0 ; i < 16 ; i ++ ) { ctx . h [ i ] = BLAKE2B_IV32 [ i ] ; } var keylen = key ? key . length : 0 ; ctx . h [ 0 ] ^= 0x01010000 ^ ( keylen << 8 ) ^ outlen ; // key the hash, if applicable if ( key ) { blake2bUpdate ( ctx , key ) ; // at the end ctx . c = 128 ; } return ctx ; }
Creates a BLAKE2b hashing context Requires an output length between 1 and 64 bytes Takes an optional Uint8Array key
Creates a BLAKE2b hashing context Requires an output length between 1 and 64 bytes Takes an optional Uint8Array key