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

Add hmac sha1 #14

Open
wants to merge 7 commits into
base: sha1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
SQUASH ME: added all-in-one sha1 function
  • Loading branch information
OlegHahm committed Jan 28, 2016
commit 8bf273ca526ff6275c23b746bff7c259766e039c
8 changes: 8 additions & 0 deletions sys/hashes/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,11 @@ uint8_t *sha1_final(sha1_context *s)
/* Return pointer to hash (20 characters) */
return (uint8_t *) s->state;
}

void sha1(uint8_t *dst, const uint8_t *src, size_t len)
{
sha1_context ctx;
sha1_init(&ctx);
sha1_update(&ctx, (unsigned char*) src, len);
memcpy(dst, sha1_final(&ctx), SHA1_DIGEST_LENGTH);
}
9 changes: 9 additions & 0 deletions sys/include/hashes/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ void sha1_update(sha1_context *s, const unsigned char *data, size_t len);
*/
uint8_t *sha1_final(sha1_context *s);

/**
* @brief Calculate a SHA1 hash from the given data
*
* @param[out] dst Result location, must be 20 byte
* @param[in] src Input data
* @param[in] len Length of @p buf
*/
void sha1(uint8_t *dst, const uint8_t *src, size_t len);

#ifdef __cplusplus
}
#endif
Expand Down