From: Rudolf Polzer Date: Mon, 26 Jul 2010 13:01:04 +0000 (+0200) Subject: provide SHA256 as util function to outside code X-Git-Tag: xonotic-v0.1.0preview~38^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=15b63271f1b64c1dce07658278acd5454cdb16b4;p=xonotic%2Fd0_blind_id.git provide SHA256 as util function to outside code --- diff --git a/d0_blind_id.c b/d0_blind_id.c index 1775fbc..d8d90f1 100644 --- a/d0_blind_id.c +++ b/d0_blind_id.c @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA const char *sha(const char *in, size_t len) { static char h[32]; - sha256(h, in, len); + d0_blind_id_util_sha256(h, in, len); return h; } @@ -997,3 +997,11 @@ void d0_blind_id_free(d0_blind_id_t *a) d0_blind_id_clear(a); d0_free(a); } + +void d0_blind_id_util_sha256(char *out, const char *in, size_t n) +{ + SHA256_CTX context; + SHA256_Init(&context); + SHA256_Update(&context, (const unsigned char *) in, n); + return SHA256_Final((unsigned char *) out, &context); +} diff --git a/d0_blind_id.h b/d0_blind_id.h index d381898..cc5afba 100644 --- a/d0_blind_id.h +++ b/d0_blind_id.h @@ -40,4 +40,6 @@ EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_sessionkey_public_id(const d0_blind_i EXPORT void d0_blind_id_INITIALIZE(void); EXPORT void d0_blind_id_SHUTDOWN(void); +EXPORT void d0_blind_id_util_sha256(char *out, const char *in, size_t n); + #endif diff --git a/sha2.c b/sha2.c index a7b2afe..7220023 100644 --- a/sha2.c +++ b/sha2.c @@ -1062,15 +1062,3 @@ char* SHA384_Data(const sha2_byte* data, size_t len, char digest[SHA384_DIGEST_S SHA384_Update(&context, data, len); return SHA384_End(&context, digest); } - - - - - -void sha256(unsigned char *out, const unsigned char *in, int n) -{ - SHA256_CTX context; - SHA256_Init(&context); - SHA256_Update(&context, in, n); - return SHA256_Final(out, &context); -} diff --git a/sha2.h b/sha2.h index 0f4a9e7..7b47a7a 100644 --- a/sha2.h +++ b/sha2.h @@ -153,8 +153,6 @@ void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]); char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]); -void sha256(unsigned char *out, const unsigned char *in, int n); - #else /* SHA2_USE_INTTYPES_H */ void SHA256_Init(SHA256_CTX *);