Skip to content

md5.h

Functions

Name
int wc_InitMd5(wc_Md5 * )
This function initializes md5. This is automatically called by wc_Md5Hash.
int wc_Md5Update(wc_Md5 * md5, const byte * data, word32 len)
Can be called to continually hash the provided byte array of length len.
int wc_Md5Final(wc_Md5 * md5, byte * hash)
Finalizes hashing of data. Result is placed into hash. Md5 Struct is reset. Note: This function will also return the result of calling IntelQaSymMd5() in the case that HAVE_INTEL_QA is defined.
void wc_Md5Free(wc_Md5 * )
Resets the Md5 structure. Note: this is only supported if you have WOLFSSL_TI_HASH defined.
int wc_Md5GetHash(wc_Md5 * md5, byte * hash)
Gets hash data. Result is placed into hash. Md5 struct is not reset.

Functions Documentation

function wc_InitMd5

int wc_InitMd5(
    wc_Md5 * 
)

This function initializes md5. This is automatically called by wc_Md5Hash.

Parameters:

  • md5 pointer to the md5 structure to use for encryption

See:

Return:

  • 0 Returned upon successfully initializing.
  • BAD_FUNC_ARG Returned if the Md5 structure is passed as a NULL value.

Example

Md5 md5;
byte* hash;
if ((ret = wc_InitMd5(&md5)) != 0) {
   WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
   ret = wc_Md5Update(&md5, data, len);
   if (ret != 0) {
     // Md5 Update Failure Case.
   }
   ret = wc_Md5Final(&md5, hash);
  if (ret != 0) {
    // Md5 Final Failure Case.
  }
}

function wc_Md5Update

int wc_Md5Update(
    wc_Md5 * md5,
    const byte * data,
    word32 len
)

Can be called to continually hash the provided byte array of length len.

Parameters:

  • md5 pointer to the md5 structure to use for encryption
  • data the data to be hashed
  • len length of data to be hashed

See:

Return:

  • 0 Returned upon successfully adding the data to the digest.
  • BAD_FUNC_ARG Returned if the Md5 structure is NULL or if data is NULL and len is greater than zero. The function should not return an error if the data parameter is NULL and len is zero.

Example

Md5 md5;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);

if ((ret = wc_InitMd5(&md5)) != 0) {
   WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
   ret = wc_Md5Update(&md5, data, len);
   if (ret != 0) {
     // Md5 Update Error Case.
   }
   ret = wc_Md5Final(&md5, hash);
   if (ret != 0) {
    // Md5 Final Error Case.
   }
}

function wc_Md5Final

int wc_Md5Final(
    wc_Md5 * md5,
    byte * hash
)

Finalizes hashing of data. Result is placed into hash. Md5 Struct is reset. Note: This function will also return the result of calling IntelQaSymMd5() in the case that HAVE_INTEL_QA is defined.

Parameters:

  • md5 pointer to the md5 structure to use for encryption
  • hash Byte array to hold hash value.

See:

Return:

  • 0 Returned upon successfully finalizing.
  • BAD_FUNC_ARG Returned if the Md5 structure or hash pointer is passed in NULL.

Example

md5 md5[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);

if ((ret = wc_InitMd5(md5)) != 0) {
   WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
   ret = wc_Md5Update(md5, data, len);
   if (ret != 0) {
    // Md5 Update Failure Case.
   }
  ret = wc_Md5Final(md5, hash);
   if (ret != 0) {
    // Md5 Final Failure Case.
   }
}

function wc_Md5Free

void wc_Md5Free(
    wc_Md5 * 
)

Resets the Md5 structure. Note: this is only supported if you have WOLFSSL_TI_HASH defined.

Parameters:

  • md5 Pointer to the Md5 structure to be reset.

See:

Return: none No returns.

Example

Md5 md5;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);

if ((ret = wc_InitMd5(&md5)) != 0) {
    WOLFSSL_MSG("wc_InitMd5 failed");
}
else {
    wc_Md5Update(&md5, data, len);
    wc_Md5Final(&md5, hash);
    wc_Md5Free(&md5);
}

function wc_Md5GetHash

int wc_Md5GetHash(
    wc_Md5 * md5,
    byte * hash
)

Gets hash data. Result is placed into hash. Md5 struct is not reset.

Parameters:

  • md5 pointer to the md5 structure to use for encryption.
  • hash Byte array to hold hash value.

See:

Return: none No returns

Example

md5 md5[1];
if ((ret = wc_InitMd5(md5)) != 0) {
   WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
   wc_Md5Update(md5, data, len);
   wc_Md5GetHash(md5, hash);
}

Source code


int wc_InitMd5(wc_Md5*);

int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len);

int wc_Md5Final(wc_Md5* md5, byte* hash);

void wc_Md5Free(wc_Md5*);

int  wc_Md5GetHash(wc_Md5* md5, byte* hash);

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