From e8a2cf6d1f84035a7af4766e6a7b2120ef5f16c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 24 Feb 2014 12:00:17 +0200 Subject: [PATCH] Make the SHA1Result function write the output into a byte array --- test/sha1.c | 10 ++++++++-- test/sha1.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/sha1.c b/test/sha1.c index ae3f7fb4..08a93d1d 100644 --- a/test/sha1.c +++ b/test/sha1.c @@ -111,11 +111,13 @@ void SHA1Reset(SHA1Context *context) * * Description: * This function will return the 160-bit message digest into the - * Message_Digest array within the SHA1Context provided + * digest array provided as a parameter. * * Parameters: * context: [in/out] * The context to use to calculate the SHA-1 hash. + * digest: [out] + * An array of characters where the digest is written. * * Returns: * 1 if successful, 0 if it failed. @@ -123,8 +125,9 @@ void SHA1Reset(SHA1Context *context) * Comments: * */ -int SHA1Result(SHA1Context *context) +int SHA1Result(SHA1Context *context, unsigned char *digest) { + int i; if (context->Corrupted) { @@ -137,6 +140,9 @@ int SHA1Result(SHA1Context *context) context->Computed = 1; } + for (i = 0; i < SHA_DIGEST_LENGTH; i++) + digest[i] = context->Message_Digest[i / 4] >> (8 * (3 - (i % 4))); + return 1; } diff --git a/test/sha1.h b/test/sha1.h index 3cc1bf59..50caae68 100644 --- a/test/sha1.h +++ b/test/sha1.h @@ -72,7 +72,7 @@ typedef struct SHA1Context * Function Prototypes */ void SHA1Reset(SHA1Context *); -int SHA1Result(SHA1Context *); +int SHA1Result(SHA1Context *, unsigned char *); void SHA1Input( SHA1Context *, const unsigned char *, unsigned);