AnsweredAssumed Answered

Crypto library SHA1 problem.

Question asked by francescato.diego on Feb 23, 2015
Latest reply on Feb 23, 2015 by francescato.diego
I am starting using the crypto library and with a STM32F407 device
I don't have the hw hash peripheral and I must use the software library
My version: M4_CryptoFW_RngHW_2_0_6.a

My code
bool Lib_SHA1_hash (uint8_t* hash, uint32_t hash_len, uint8_t* p, uint32_t len)
{
  SHA1ctx_stt SHA1ctx_st;
 
  bool result ;
 
  /* Initialize context */
  memset (&SHA1ctx_st, 0, sizeof(SHA1ctx_st)) ;
 
  /* Set the size of the desired hash digest */
  /* Set flag field to default value */
  SHA1ctx_st.mTagSize = 20;
  SHA1ctx_st.mFlags   = E_HASH_DEFAULT;
  result = SHA1_Init(&SHA1ctx_st);
  if (result != HASH_SUCCESS) return false ;
 
  result = SHA1_Append(&SHA1ctx_st, p, len) ;
  if (result != HASH_SUCCESS) return false ;
 
  result = SHA1_Finish(&SHA1ctx_st, hash, &hash_len);
  if (result != HASH_SUCCESS) return false ;
 
  return true ;
}

The library manual say the SHA1_Finish must return the hash value in hash buffer and the length of data written in hash buffer in hash_len
the hash buffer contain correct data but my hash_len is always a random value
(The library is precompiled and I see only the asm code)

Outcomes