diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-08-11 08:02:43 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:15:28 -0500 |
commit | 0d235919fbb1430d52913df11da1f011a65ff319 (patch) | |
tree | 52f61b84020ad9ce5e0dc59d9f720c4e07b66fde /source4/lib/crypto/hmacsha1test.c | |
parent | b26f4472a71b2a60c8120bd1307dbbd1e499fcbe (diff) | |
download | samba-0d235919fbb1430d52913df11da1f011a65ff319.tar.gz samba-0d235919fbb1430d52913df11da1f011a65ff319.tar.bz2 samba-0d235919fbb1430d52913df11da1f011a65ff319.zip |
r17488: - add SHA1 and HMACSHA1 functions, based on rfc 2104,2202,3174
- and add torture tests also based on the rfc's
metze
(This used to be commit d48930a02f9560640697fd57e4bba03dc0abe284)
Diffstat (limited to 'source4/lib/crypto/hmacsha1test.c')
-rw-r--r-- | source4/lib/crypto/hmacsha1test.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source4/lib/crypto/hmacsha1test.c b/source4/lib/crypto/hmacsha1test.c new file mode 100644 index 0000000000..2631fe1659 --- /dev/null +++ b/source4/lib/crypto/hmacsha1test.c @@ -0,0 +1,46 @@ +#include "includes.h" + +#include "lib/crypto/crypto.h" + +struct torture_context; + +BOOL torture_local_crypto_hmacsha1(struct torture_context *torture) +{ + BOOL ret = True; + uint32_t i; + struct { + DATA_BLOB key; + DATA_BLOB data; + DATA_BLOB digest; + } testarray[] = { + { + .key = strhex_to_data_blob("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"), + .data = data_blob_string_const("Hi There"), + .digest = strhex_to_data_blob("b617318655057264e28bc0b6fb378c8ef146be00") + } + }; + + for (i=0; i < ARRAY_SIZE(testarray); i++) { + struct HMACSHA1Context ctx; + uint8_t digest[SHA1HashSize]; + int e; + + hmac_sha1_init(testarray[i].key.data, testarray[i].key.length, &ctx); + hmac_sha1_update(testarray[i].data.data, testarray[i].data.length, &ctx); + hmac_sha1_final(digest, &ctx); + + e = memcmp(testarray[i].digest.data, + digest, + MIN(testarray[i].digest.length, SHA1HashSize)); + if (e != 0) { + printf("test[%u]: failed\n", i); + dump_data(0, testarray[i].key.data, testarray[i].key.length); + dump_data(0, testarray[i].data.data, testarray[i].data.length); + dump_data(0, testarray[i].digest.data, testarray[i].digest.length); + dump_data(0, digest, sizeof(digest)); + ret = False; + } + } + + return ret; +} |