ECU/GSM/src/00- SERVICES/02- Security Stack/HMAC_interface/main.c
int32_t STM32_SHA256_HMAC_Compute(uint8_t* InputMessage,
                          uint32_t InputMessageLength,
                          uint8_t *HMAC_key,
                          uint32_t HMAC_keyLength,
                          uint8_t *MessageDigest,
                          int32_t* MessageDigestLength)
{
  HMAC_SHA256ctx_stt HMAC_SHA256ctx;
  uint32_t error_status = HASH_SUCCESS;

  /* Set the size of the desired MAC*/
  HMAC_SHA256ctx.mTagSize = CRL_SHA256_SIZE;

  /* Set flag field to default value */
  HMAC_SHA256ctx.mFlags = E_HASH_DEFAULT;

  /* Set the key pointer in the context*/
  HMAC_SHA256ctx.pmKey = HMAC_key;

  /* Set the size of the key */
  HMAC_SHA256ctx.mKeySize = HMAC_keyLength;

  /* Initialize the context */
  error_status = HMAC_SHA256_Init(&HMAC_SHA256ctx);

  /* check for initialization errors */
  if (error_status == HASH_SUCCESS)
  {
    /* Add data to be hashed */
    error_status = HMAC_SHA256_Append(&HMAC_SHA256ctx,
                                    InputMessage,
                                    InputMessageLength);

    if (error_status == HASH_SUCCESS)
    {
      /* retrieve */
      error_status = HMAC_SHA256_Finish(&HMAC_SHA256ctx, MessageDigest, MessageDigestLength);
    }
  }

  return error_status;
}
/**
  * @brief  SHA1 HMAC compute example.
  * @param  InputMessage: pointer to input message to be hashed.
  * @param  InputMessageLength: input data message length in byte.
  * @param  HMAC_key: pointer to key used in the HMAC computation
  * @param  HMAC_keyLength: HMAC key length in byte.
  * @param  MessageDigest: pointer to output parameter that will handle message digest
  * @param  MessageDigestLength: pointer to output digest length.
  * @retval error status: can be HASH_SUCCESS if success or one of
  *         HASH_ERR_BAD_PARAMETER, HASH_ERR_BAD_CONTEXT,
  *         HASH_ERR_BAD_OPERATION if error occured.
  */
@brief  SHA1 HMAC compute example.
@param  InputMessage: pointer to input message to be hashed.
@param  InputMessageLength: input data message length in byte.
@param  HMAC_key: pointer to key used in the HMAC computation
@param  HMAC_keyLength: HMAC key length in byte.
@param  MessageDigest: pointer to output parameter that will handle message digest
@param  MessageDigestLength: pointer to output digest length.
@retval error status: can be HASH_SUCCESS if success or one of
HASH_ERR_BAD_PARAMETER, HASH_ERR_BAD_CONTEXT,
HASH_ERR_BAD_OPERATION if error occured.
@brief SHA1 HMAC compute example . @param InputMessage : pointer to input message to be hashed . @param InputMessageLength : input data message length in byte . @param HMAC_key : pointer to key used in the HMAC computation @param HMAC_keyLength : HMAC key length in byte . @param MessageDigest : pointer to output parameter that will handle message digest @param MessageDigestLength : pointer to output digest length . @retval error status : can be HASH_SUCCESS if success or one of HASH_ERR_BAD_PARAMETER HASH_ERR_BAD_CONTEXT HASH_ERR_BAD_OPERATION if error occured .
int32_t STM32_SHA256_HMAC_Compute(uint8_t* InputMessage,
                          uint32_t InputMessageLength,
                          uint8_t *HMAC_key,
                          uint32_t HMAC_keyLength,
                          uint8_t *MessageDigest,
                          int32_t* MessageDigestLength)
{
  HMAC_SHA256ctx_stt HMAC_SHA256ctx;
  uint32_t error_status = HASH_SUCCESS;
  HMAC_SHA256ctx.mTagSize = CRL_SHA256_SIZE;
  HMAC_SHA256ctx.mFlags = E_HASH_DEFAULT;
  HMAC_SHA256ctx.pmKey = HMAC_key;
  HMAC_SHA256ctx.mKeySize = HMAC_keyLength;
  error_status = HMAC_SHA256_Init(&HMAC_SHA256ctx);
  if (error_status == HASH_SUCCESS)
  {
    error_status = HMAC_SHA256_Append(&HMAC_SHA256ctx,
                                    InputMessage,
                                    InputMessageLength);
    if (error_status == HASH_SUCCESS)
    {
      error_status = HMAC_SHA256_Finish(&HMAC_SHA256ctx, MessageDigest, MessageDigestLength);
    }
  }
  return error_status;
}
int32_t STM32_SHA256_HMAC_Compute ( uint8_t * InputMessage , uint32_t InputMessageLength , uint8_t * HMAC_key , uint32_t HMAC_keyLength , uint8_t * MessageDigest , int32_t * MessageDigestLength ) { HMAC_SHA256ctx_stt HMAC_SHA256ctx ; uint32_t error_status = HASH_SUCCESS ; HMAC_SHA256ctx . mTagSize = CRL_SHA256_SIZE ; HMAC_SHA256ctx . mFlags = E_HASH_DEFAULT ; HMAC_SHA256ctx . pmKey = HMAC_key ; HMAC_SHA256ctx . mKeySize = HMAC_keyLength ; error_status = HMAC_SHA256_Init ( & HMAC_SHA256ctx ) ; if ( error_status == HASH_SUCCESS ) { error_status = HMAC_SHA256_Append ( & HMAC_SHA256ctx , InputMessage , InputMessageLength ) ; if ( error_status == HASH_SUCCESS ) { error_status = HMAC_SHA256_Finish ( & HMAC_SHA256ctx , MessageDigest , MessageDigestLength ) ; } } return error_status ; }
@brief  SHA1 HMAC compute example.
@brief SHA1 HMAC compute example .
/* Set the size of the desired MAC*/ /* Set flag field to default value */ /* Set the key pointer in the context*/ /* Set the size of the key */ /* Initialize the context */ /* check for initialization errors */ /* Add data to be hashed */ /* retrieve */