diff options
-rw-r--r-- | common/sha1.c | 15 | ||||
-rw-r--r-- | common/sha1.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/common/sha1.c b/common/sha1.c index 0666837..d2005b9 100644 --- a/common/sha1.c +++ b/common/sha1.c @@ -161,4 +161,19 @@ void sha1_final(uchar digest[20], sha1_ctx_t* context) #endif } +void +sha1_string(unsigned char digest[SHA1_LEN], const char* str) +{ + sha1_ctx_t sha1; + sha1_init(&sha1); + sha1_update(&sha1, str, strlen(str)); + sha1_final(digest, &sha1); +} +int +sha1_strcmp(unsigned char digest[SHA1_LEN], const char* str) +{ + unsigned char other[SHA1_LEN]; + sha1_string(other, str); + return memcmp(digest, other, SHA1_LEN); +} diff --git a/common/sha1.h b/common/sha1.h index 37f734f..208b7f2 100644 --- a/common/sha1.h +++ b/common/sha1.h @@ -22,6 +22,8 @@ sha1_ctx_t; void sha1_init(sha1_ctx_t* context); void sha1_update(sha1_ctx_t* context, const void* data, unsigned int len); void sha1_final(unsigned char digest[SHA1_LEN], sha1_ctx_t* context); +void sha1_string(unsigned char digest[SHA1_LEN], const char* str); +int sha1_strcmp(unsigned char digest[SHA1_LEN], const char* str); #ifdef __cplusplus } |