diff options
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/libnetdata.c | 25 | ||||
-rw-r--r-- | libnetdata/libnetdata.h | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/libnetdata/libnetdata.c b/libnetdata/libnetdata.c index 3029b08d1c..a8f26c33b8 100644 --- a/libnetdata/libnetdata.c +++ b/libnetdata/libnetdata.c @@ -2009,3 +2009,28 @@ void timing_action(TIMING_ACTION action, TIMING_STEP step) { } } } + +int hash256_string(const unsigned char *string, size_t size, char *hash) { + EVP_MD_CTX *ctx; + ctx = EVP_MD_CTX_create(); + + if (!ctx) + return 0; + + if (!EVP_DigestInit(ctx, EVP_sha256())) { + EVP_MD_CTX_destroy(ctx); + return 0; + } + + if (!EVP_DigestUpdate(ctx, string, size)) { + EVP_MD_CTX_destroy(ctx); + return 0; + } + + if (!EVP_DigestFinal(ctx, (unsigned char *)hash, NULL)) { + EVP_MD_CTX_destroy(ctx); + return 0; + } + + return 1; +} diff --git a/libnetdata/libnetdata.h b/libnetdata/libnetdata.h index 1f164e3a07..c244949308 100644 --- a/libnetdata/libnetdata.h +++ b/libnetdata/libnetdata.h @@ -782,6 +782,7 @@ typedef enum { #endif void timing_action(TIMING_ACTION action, TIMING_STEP step); +int hash256_string(const unsigned char *string, size_t size, char *hash); # ifdef __cplusplus } # endif |