Created
September 21, 2011 21:01
-
-
Save varnit/1233303 to your computer and use it in GitHub Desktop.
Revisions
-
varnit revised this gist
Sep 22, 2011 . 2 changed files with 26 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,20 +5,30 @@ int main() { char* key = "secret key"; char* data = "my data"; char tmp[3]; unsigned int result_len, i; unsigned char* result = malloc(sizeof(unsigned char) * result_len); HMAC_CTX ctx; HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char*) key, strlen(key), EVP_sha1(), NULL); HMAC_Update(&ctx, (unsigned char*) data, strlen(data)); HMAC_Final(&ctx, result, &result_len); HMAC_CTX_cleanup(&ctx); char* output = malloc(sizeof(char) * result_len); for (i = 0; i != result_len; i++) { //printf("Got %02X at byte %d\n", result[i], i); sprintf(tmp, "%02x", result[i]); strcat(output, tmp); } printf("output : %s\n", output); printf("expected: %s\n", "97a62219092f3ddab3707cc9e85e63e926f45c87"); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,5 +2,5 @@ $ perl hmac.pl 97a62219092f3ddab3707cc9e85e63e926f45c87 $ gcc -Wall -lcrypto hmac.c -o hmac && ./hmac output : 97a62219092f3ddab3707cc9e85e63e926f45c87 expected: 97a62219092f3ddab3707cc9e85e63e926f45c87 -
varnit revised this gist
Sep 21, 2011 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
varnit revised this gist
Sep 21, 2011 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
varnit revised this gist
Sep 21, 2011 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,8 @@ int main() { char* key = "secret key"; char* data = "my data"; unsigned int result_len = 40; unsigned char* result = malloc(sizeof(unsigned char) * result_len); HMAC_CTX ctx; HMAC_CTX_init(&ctx); @@ -22,4 +21,4 @@ int main() { printf("expected: %s\n", "97a62219092f3ddab3707cc9e85e63e926f45c87"); return 0; } -
varnit created this gist
Sep 21, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ $ perl hmac.pl 97a62219092f3ddab3707cc9e85e63e926f45c87 $ gcc -Wall -lcrypto hmac.c -o hmac && ./hmac output : ��" /=ڳp|��^c�&�\� expected: 97a62219092f3ddab3707cc9e85e63e926f45c87 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <openssl/hmac.h> int main() { char* key = "secret key"; char* data = "my data"; unsigned char* result; unsigned int result_len = 40; result = (unsigned char*) malloc(sizeof(char) * result_len); HMAC_CTX ctx; HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char*) key, strlen(key), EVP_sha1(), NULL); HMAC_Update(&ctx, (unsigned char*) data, strlen(data)); HMAC_Final(&ctx, result, &result_len); HMAC_CTX_cleanup(&ctx); printf("output : %s\n", (char*)result); printf("expected: %s\n", "97a62219092f3ddab3707cc9e85e63e926f45c87"); return 0; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ #!/usr/bin/perl use strict; use warnings; use Digest::SHA qw(hmac_sha1_hex); print hmac_sha1_hex("my data", "secret key") . "\n";