Skip to content

Algorithms - BLAKE2

Functions

Name
int wc_InitBlake2b(Blake2b * b2b, word32 digestSz)
This function initializes a Blake2b structure for use with the Blake2 hash function.
int wc_Blake2bUpdate(Blake2b * b2b, const byte * data, word32 sz)
This function updates the Blake2b hash with the given input data. This function should be called after wc_InitBlake2b, and repeated until one is ready for the final hash: wc_Blake2bFinal.
int wc_Blake2bFinal(Blake2b * b2b, byte * final, word32 requestSz)
This function computes the Blake2b hash of the previously supplied input data. The output hash will be of length requestSz, or, if requestSz==0, the digestSz of the b2b structure. This function should be called after wc_InitBlake2b and wc_Blake2bUpdate has been processed for each piece of input data desired.

Functions Documentation

function wc_InitBlake2b

int wc_InitBlake2b(
    Blake2b * b2b,
    word32 digestSz
)

This function initializes a Blake2b structure for use with the Blake2 hash function.

Parameters:

  • b2b pointer to the Blake2b structure to initialize
  • digestSz length of the blake 2 digest to implement

See: wc_Blake2bUpdate

Return: 0 Returned upon successfully initializing the Blake2b structure and setting the digest size.

Example

Blake2b b2b;
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);

function wc_Blake2bUpdate

int wc_Blake2bUpdate(
    Blake2b * b2b,
    const byte * data,
    word32 sz
)

This function updates the Blake2b hash with the given input data. This function should be called after wc_InitBlake2b, and repeated until one is ready for the final hash: wc_Blake2bFinal.

Parameters:

  • b2b pointer to the Blake2b structure to update
  • data pointer to a buffer containing the data to append
  • sz length of the input data to append

See:

Return:

  • 0 Returned upon successfully update the Blake2b structure with the given data
  • -1 Returned if there is a failure while compressing the input data

Example

int ret;
Blake2b b2b;
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);

byte plain[] = { // initialize input };

ret = wc_Blake2bUpdate(&b2b, plain, sizeof(plain));
if( ret != 0) {
    // error updating blake2b
}

function wc_Blake2bFinal

int wc_Blake2bFinal(
    Blake2b * b2b,
    byte * final,
    word32 requestSz
)

This function computes the Blake2b hash of the previously supplied input data. The output hash will be of length requestSz, or, if requestSz==0, the digestSz of the b2b structure. This function should be called after wc_InitBlake2b and wc_Blake2bUpdate has been processed for each piece of input data desired.

Parameters:

  • b2b pointer to the Blake2b structure to update
  • final pointer to a buffer in which to store the blake2b hash. Should be of length requestSz
  • requestSz length of the digest to compute. When this is zero, b2b->digestSz will be used instead

See:

Return:

  • 0 Returned upon successfully computing the Blake2b hash
  • -1 Returned if there is a failure while parsing the Blake2b hash

Example

int ret;
Blake2b b2b;
byte hash[64];
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
... // call wc_Blake2bUpdate to add data to hash

ret = wc_Blake2bFinal(&b2b, hash, 64);
if( ret != 0) {
    // error generating blake2b hash
}

Updated on 2024-12-20 at 01:22:24 +0000