Hi, I had earlier posted query on AES_Keywrap() usage and had good response on the same and got lot of things clarified. Now i am successful in using AES_wrap_key() API but i am running into a new problem. I need to wrap 512bit key with 256 bit KEK key. When i do this, i am hitting seg fault in AES_wrap_key(). When i do gdb, it points to memcpy(). From the code i didn't see any limitation of not using 512 bit key. Am i missing something? Below is my sample code which works successfully for 256 bit Key. Below code can be enabled for 512 bit with the macro KEY512.
#include <stdio.h> #include <openssl/aes.h> #include <openssl/bio.h> //#define KEYBITS 128 //#define KEYLEN 16 #define KEY512 0 #if KEY512 #define KEYLEN 64 #define KEYBITS 512 #else #define KEYLEN 32 #define KEYBITS 256 #endif static const unsigned char default_iv[] = { 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, }; static const unsigned char invalid_iv[] = { 0x16, 0xA6, 0xA6, 0xA6, 0xA6, 0x16, 0xA6, 0xA6, }; void main() { #if (!KEY512) static const unsigned char kek[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; #else static const unsigned char kek[] = { 0xbc, 0x54, 0xd8, 0xa0, 0x6e, 0xab, 0x3b, 0x4c, 0x06, 0xf5, 0xbe, 0x01, 0xc5, 0x77, 0x28, 0x3d, 0x92, 0xda, 0xfb, 0xe8, 0x3f, 0xe0, 0x59, 0x57, 0xff, 0xbe, 0xfa, 0x5b, 0xe0, 0xd4, 0xfb, 0xb7 }; #endif /* static const unsigned char key[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; */ #if (!KEY512) static const unsigned char key[] = { 0x46, 0xab, 0x1b, 0xdc, 0x89, 0x38, 0x57, 0x23, 0x47, 0x49, 0xfc, 0xc4, 0x6e, 0x26, 0xf0, 0xae, 0xbd, 0x4b, 0x0b, 0xcf, 0x51, 0x96, 0x21, 0x2c, 0xd4, 0xd0, 0x82, 0x71, 0xa3, 0x8c, 0xcb, 0x3c }; #else static const unsigned char key[] = { 0xf5, 0x96, 0x87, 0x3e, 0x53, 0x6d, 0x61, 0xf5, 0x55, 0x53, 0xca, 0x0c, 0xd8, 0xcd, 0x1d, 0x40, 0xcb, 0x66, 0x58, 0xf7, 0x8f, 0xae, 0xbf, 0x9b, 0x78, 0x4d, 0xd1, 0x0f, 0x19, 0xc2, 0x89, 0x5a, 0x47, 0xd9, 0x3c, 0x7e, 0x26, 0x18, 0x2d, 0xd0, 0xce, 0xcb, 0x3a, 0x58, 0x55, 0x59, 0x4e, 0x5b, 0x2a, 0xd3, 0x9a, 0x86, 0x9d, 0x6c, 0x5d, 0x70, 0x21, 0xa7, 0x87, 0xcb, 0xdd, 0xf5, 0xe3, 0xf5 }; #endif int ret, i; unsigned char *otmp, *dtmp; AES_KEY actx, dctx; printf("\n keylen = %d; kebits= %d", KEYLEN, KEYBITS); if (AES_set_encrypt_key(kek, KEYBITS, &actx)) printf("\n Error seeting AES key "); otmp = (unsigned char *) malloc(sizeof(char) * (KEYLEN+8)); dtmp = (unsigned char *) malloc(sizeof(char) * KEYLEN); ret = AES_wrap_key(&actx, default_iv, otmp, key, KEYLEN); printf("\n AES wrap ; ret = %d", ret); if (ret < 0) printf("\n AES wrap key failed"); printf("\n Wrapped key : "); for (i = 0; i< (KEYLEN + 8); i++) printf(" %02x", otmp[i]); if (AES_set_decrypt_key(kek, KEYBITS, &dctx)) printf("\n Error setting decrypt key "); ret = AES_unwrap_key(&dctx, default_iv, dtmp, otmp, ret); printf("\n AES unwrap ; ret = %d", ret); if (ret == 0) printf("\n AES unwrapping failed "); printf("\n Original key : "); for (i = 0; i < KEYLEN ; i++) printf(" %02x", dtmp[i]); printf("\n"); free(otmp); free(dtmp); } Output result when 256 bit key is used keylen = 32; kebits= 256 AES wrap ; ret = 40 Wrapped key : 0a f2 44 0b 98 e9 7d 65 3d 90 ea aa 4d fd 10 37 24 17 66 82 cb 60 b2 c6 56 cc 83 d9 ad 6b 32 a8 5d aa d1 b7 10 54 1b ea AES unwrap ; ret = 32 Original key : 46 ab 1b dc 89 38 57 23 47 49 fc c4 6e 26 f0 ae bd 4b 0b cf 51 96 21 2c d4 d0 82 71 a3 8c cb 3c Ouput when 512 bit is key - Here i hit seg fault keylen = 64; kebits= 512 Segmentation fault any help is highly appreciated... -- View this message in context: http://old.nabble.com/Hitting-seg-fault-in-AES_wrap_key%28%29-when-Key-is-512-bits-in-length-tp33552263p33552263.html Sent from the OpenSSL - User mailing list archive at Nabble.com. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org