С TrueStudio я разрабатываю на STM32f103RB с помощью пакета криптографической библиотеки STM32 'STM32CubeExpansion_Crypto_V3.1.0'.Я хотел бы использовать sha-1 из lib, но по какой-то причине я не получаю правильный результат.
Вот мой тест ...
Мой входной буфер: "('1543409074.11', '1702635382a7b4243308035dfecc1e5e31678356bdfa39f92b6409a2')"
Из SHA1 и других онлайн-генераторов хеш-функций , результат для sha1: c6818ce06b79c91cda7cc89f1af243e3d1373c1f
С помощью библиотеки шифрования STM32 я не могу сгенерировать правильныйША-1 сум.Например, я вызываю хеш-функцию SHA-1 со следующим кодом:
SHA1ctx_stt SHA1ctx_st; // The SHA1 context
membuf_stt mb_st; // structure that will contain the preallocated buffer
uint8_t Digest[CRL_SHA1_SIZE]; // Buffer that will contain the SHA-1 digest of the message
uint8_t preallocated_buffer[4096]; // buffer required for internal allocation of memory
int32_t status = HASH_SUCCESS;
int32_t outputSize;
const char* Message="('1543409074.11', '1702635382a7b4243308035dfecc1e5e31678356bdfa39f92b6409a2')";
int32_t MessageSize = strlen(Message);
// Initialize the membuf_st that must be passed to the ECC functions
mb_st.mSize = sizeof(preallocated_buffer);
mb_st.mUsed = 0;
mb_st.pmBuf = preallocated_buffer;
//Initialize it the SHA-1 Context
SHA1ctx_st.mFlags = E_HASH_DEFAULT;
// 20 byte of output
SHA1ctx_st.mTagSize = CRL_SHA1_SIZE;
// Init SHA-1
status = SHA1_Init(&SHA1ctx_st);
if (status == HASH_SUCCESS)
{
// Process the message with SHA-1
status = SHA1_Append(&SHA1ctx_st, (const uint8_t *)Message, MessageSize);
if (status == HASH_SUCCESS)
{
// Output the Digest
status = SHA1_Finish(&SHA1ctx_st, Digest, &outputSize);
if (status == HASH_SUCCESS)
{
// It's OK, but result in Digest isn't correct
}
}
}
Чего мне не хватает?Кто-нибудь знает, что может быть не так?
Спасибо,