From fbcc3203211187852804357be746f81e20d012ba Mon Sep 17 00:00:00 2001 From: makejian Date: Wed, 27 Mar 2024 17:41:46 +0800 Subject: [PATCH] openssl_mbedtls_wrapper: Implement SHA1 Interface Signed-off-by: makejian --- crypto/openssl_mbedtls_wrapper/mbedtls/sha.c | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c b/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c index 7b7efe1ebd..4541332fb5 100644 --- a/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c +++ b/crypto/openssl_mbedtls_wrapper/mbedtls/sha.c @@ -22,12 +22,42 @@ * Included Files ****************************************************************************/ +#include #include /**************************************************************************** * Public Functions ****************************************************************************/ +int SHA1_Init(SHA_CTX *sha) +{ + mbedtls_sha1_init((mbedtls_sha1_context *)sha); + mbedtls_sha1_starts((mbedtls_sha1_context *)sha); + return 0; +} + +int SHA1_Update(SHA_CTX *sha, const void *data, size_t len) +{ + return mbedtls_sha1_update((mbedtls_sha1_context *)sha, data, len); +} + +int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *sha) +{ + return mbedtls_sha1_finish((mbedtls_sha1_context *)sha, + (unsigned char *)out); +} + +uint8_t *SHA1(const uint8_t *data, size_t len, + uint8_t out[SHA_DIGEST_LENGTH]) +{ + if (mbedtls_sha1(data, len, out) != 0) + { + return NULL; + } + + return out; +} + int SHA256_Init(SHA256_CTX *sha) { return 0;