Crypto library SHA1 problem.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-23 8:51 AM
Posted on February 23, 2015 at 17:51
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 codebool 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)
Labels:
- Labels:
-
Cryptography
-
STM32F4 Series
This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-23 9:21 AM
Posted on February 23, 2015 at 18:21
Perhaps you should pass in a pointer, instead of using the address of a throw away parameter on the stack?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-02-23 9:44 AM
Posted on February 23, 2015 at 18:44
Oooooooooooooopsssssssssssss!
Stupid mistake !! It work! thanks Clivebool 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 ;
}
