Created
March 21, 2012 09:31
-
-
Save l4u/2145807 to your computer and use it in GitHub Desktop.
engine initialization in OpenSSL
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 characters
// http://stackoverflow.com/questions/242665/understanding-engine-initialization-in-openssl | |
unsigned char* key = (unsigned char*) "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; | |
unsigned char* data = (unsigned char*) "\x48\x69\x20\x54\x68\x65\x72\x65"; | |
unsigned char* expected = (unsigned char*) "\x49\x2c\xe0\x20\xfe\x25\x34\xa5\x78\x9d\xc3\x84\x88\x06\xc7\x8f\x4f\x67\x11\x39\x7f\x08\xe7\xe7\xa1\x2c\xa5\xa4\x48\x3c\x8a\xa6"; | |
HMAC_CTX ctx; | |
unsigned char* result; | |
unsigned int result_len = 32; | |
int i; | |
result = (unsigned char*) malloc(sizeof(char) * result_len); | |
ENGINE_load_builtin_engines(); | |
ENGINE_register_all_complete(); | |
HMAC_CTX_init(&ctx); | |
HMAC_Init_ex(&ctx, key, 16, EVP_sha256(), NULL); | |
HMAC_Update(&ctx, data, 8); | |
HMAC_Final(&ctx, result, &result_len); | |
for (i=0; i!=result_len; i++) | |
{ | |
if (expected[i]!=result[i]) | |
{ | |
//("Got %02X instead of %02X at byte %d!\n", result[i], expected[i], i); | |
break; | |
} | |
} | |
HMAC_CTX_cleanup(&ctx); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment