Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sha256: add wrapper #306

Merged
merged 1 commit into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
#endif

void sha1(const uint8_t *d, size_t n, uint8_t *md);
void sha256(const uint8_t *d, size_t n, uint8_t *md);
23 changes: 23 additions & 0 deletions src/sha/wrap.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @file wrap.c SHA wrappers
*
* Copyright (C) 2022 Alfred E. Heggestad
* Copyright (C) 2022 Sebastian Reimers <hallo@studio-link.de>
*/

Expand Down Expand Up @@ -33,3 +34,25 @@ void sha1(const uint8_t *d, size_t n, uint8_t *md)
#error missing SHA-1 backend
#endif
}


/**
* Calculate the SHA256 hash from a buffer
*
* @param d Data buffer (input)
* @param n Number of input bytes
* @param md Calculated SHA1 hash (output)
*/
void sha256(const uint8_t *d, size_t n, uint8_t *md)
{
#ifdef USE_OPENSSL
(void)SHA256(d, n, md);
#elif defined (__APPLE__)
CC_SHA256(d, (uint32_t)n, md);
#else
(void)d;
(void)n;
(void)md;
#error missing SHA-256 backend
#endif
}