diff options
author | Damien Bergamini <damien@cvs.openbsd.org> | 2008-08-12 15:49:09 +0000 |
---|---|---|
committer | Damien Bergamini <damien@cvs.openbsd.org> | 2008-08-12 15:49:09 +0000 |
commit | 31b5a37fa02f6bd597b9975d407c1228ca26a35c (patch) | |
tree | 40ccbc188fc3d839e7a6d49e61c633e94b840771 /regress/sys/crypto/hmac/hmac_test.c | |
parent | 2fcb64222ee15913fadca59e342e93b3d41857ad (diff) |
test vectors for HMAC-MD5, HMAC-SHA1, HMAC-SHA256, AES-128-CMAC,
AES Key Wrap.
ok djm@
Diffstat (limited to 'regress/sys/crypto/hmac/hmac_test.c')
-rw-r--r-- | regress/sys/crypto/hmac/hmac_test.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/regress/sys/crypto/hmac/hmac_test.c b/regress/sys/crypto/hmac/hmac_test.c new file mode 100644 index 00000000000..83495aa8e83 --- /dev/null +++ b/regress/sys/crypto/hmac/hmac_test.c @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <crypto/md5.h> +#include <crypto/sha1.h> +#include <crypto/sha2.h> +#include <crypto/hmac.h> + +void +print_hex(unsigned char *buf, int len) +{ + int i; + + printf("digest = 0x"); + for (i = 0; i < len; i++) + printf("%02x", buf[i]); + printf("\n"); +} + +int +main(void) +{ + HMAC_MD5_CTX md5; + HMAC_SHA1_CTX sha1; + HMAC_SHA256_CTX sha256; + u_int8_t data[50], output[32]; + int i; + + HMAC_MD5_Init(&md5, "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16); + HMAC_MD5_Update(&md5, "Hi There", 8); + HMAC_MD5_Final(output, &md5); + print_hex(output, MD5_DIGEST_LENGTH); + + HMAC_MD5_Init(&md5, "Jefe", 4); + HMAC_MD5_Update(&md5, "what do ya want for nothing?", 28); + HMAC_MD5_Final(output, &md5); + print_hex(output, MD5_DIGEST_LENGTH); + + HMAC_MD5_Init(&md5, "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA", 16); + memset(data, 0xDD, sizeof data); + HMAC_MD5_Update(&md5, data, sizeof data); + HMAC_MD5_Final(output, &md5); + print_hex(output, MD5_DIGEST_LENGTH); + + HMAC_SHA1_Init(&sha1, "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16); + HMAC_SHA1_Update(&sha1, "Hi There", 8); + HMAC_SHA1_Final(output, &sha1); + print_hex(output, SHA1_DIGEST_LENGTH); + + HMAC_SHA1_Init(&sha1, "Jefe", 4); + HMAC_SHA1_Update(&sha1, "what do ya want for nothing?", 28); + HMAC_SHA1_Final(output, &sha1); + print_hex(output, SHA1_DIGEST_LENGTH); + + HMAC_SHA1_Init(&sha1, "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA", 16); + memset(data, 0xDD, sizeof data); + HMAC_SHA1_Update(&sha1, data, sizeof data); + HMAC_SHA1_Final(output, &sha1); + print_hex(output, SHA1_DIGEST_LENGTH); + + HMAC_SHA256_Init(&sha256, "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16); + HMAC_SHA256_Update(&sha256, "Hi There", 8); + HMAC_SHA256_Final(output, &sha256); + print_hex(output, SHA256_DIGEST_LENGTH); + + HMAC_SHA256_Init(&sha256, "Jefe", 4); + HMAC_SHA256_Update(&sha256, "what do ya want for nothing?", 28); + HMAC_SHA256_Final(output, &sha256); + print_hex(output, SHA256_DIGEST_LENGTH); + + HMAC_SHA256_Init(&sha256, "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA", 16); + memset(data, 0xDD, sizeof data); + HMAC_SHA256_Update(&sha256, data, sizeof data); + HMAC_SHA256_Final(output, &sha256); + print_hex(output, SHA256_DIGEST_LENGTH); + + return 0; +} |