Skip to content

Commit

Permalink
openssl_mbedtls_wrapper: Implement SHA1 Interface
Browse files Browse the repository at this point in the history
Signed-off-by: makejian <[email protected]>
  • Loading branch information
makejian authored and xiaoxiang781216 committed Oct 27, 2024
1 parent 42e0e4c commit fbcc320
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crypto/openssl_mbedtls_wrapper/mbedtls/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,42 @@
* Included Files
****************************************************************************/

#include <mbedtls/sha1.h>
#include <openssl/sha.h>

/****************************************************************************
* 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;
Expand Down

0 comments on commit fbcc320

Please sign in to comment.