<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Dear all,<div>    After extracting openssl-1.1.1.tar.gz, openssl can be configured without asm by passing no-asm flag during config command.</div><div><br></div><div>    The expanded key can be obtained like follows:</div><div>//Getting expanded key from inside openssl</div><div><div><div><span style="background-color:rgb(204,204,204)">//Copied from crypto/evp/e_aes.c</span></div><div><span style="background-color:rgb(204,204,204)">typedef struct {</span></div><div><span style="background-color:rgb(204,204,204)">    union {</span></div><div><span style="background-color:rgb(204,204,204)">        double align;</span></div><div><span style="background-color:rgb(204,204,204)">        AES_KEY ks;</span></div><div><span style="background-color:rgb(204,204,204)">    } ks;</span></div><div><span style="background-color:rgb(204,204,204)">    block128_f block;</span></div><div><span style="background-color:rgb(204,204,204)">    union {</span></div><div><span style="background-color:rgb(204,204,204)">        cbc128_f cbc;</span></div><div><span style="background-color:rgb(204,204,204)">        ctr128_f ctr;</span></div><div><span style="background-color:rgb(204,204,204)">    } stream;</span></div><div><span style="background-color:rgb(204,204,204)">} EVP_AES_KEY;</span></div></div><div><span style="background-color:rgb(204,204,204)"><br></span></div><div><div><span style="background-color:rgb(204,204,204)">  EVP_CIPHER_CTX *cipher_ctx = ssl->enc_write_ctx;</span></div><div><span style="background-color:rgb(204,204,204)">  EVP_AES_KEY * cipher_data = EVP_CIPHER_CTX_get_cipher_data(cipher_ctx);</span></div><div><span style="background-color:rgb(204,204,204)">  printf("Encrypted Expanded Key is : ");</span></div><div><span style="background-color:rgb(204,204,204)">  for(i=0;i<((cipher_ctx->cipher->key_len)/sizeof(cipher_data->ks.ks.rd_key[0])*11);i++) {</span></div><div><span style="background-color:rgb(204,204,204)">      printf("%08x", cipher_data->ks.ks.rd_key[i]);</span></div><div><span style="background-color:rgb(204,204,204)">  }</span></div><div><span style="background-color:rgb(204,204,204)">  printf("\n");</span></div></div><div><br></div><div> To get the 128 bit encrypted key :<br></div><div><span style="background-color:rgb(204,204,204)">unsigned char* key = unsigned char* malloc(16);</span></div><div><div><span style="background-color:rgb(204,204,204)">    int i;</span></div><div><span style="background-color:rgb(204,204,204)">    for (i=0; i<4; i++) {</span></div><div><span style="background-color:rgb(204,204,204)">        key[4*i]   = cipher_data->ks.ks.rd_key[i] >> 24;</span></div><div><span style="background-color:rgb(204,204,204)">        key[4*i+1] = cipher_data->ks.ks.rd_key[i] >> 16;</span></div><div><span style="background-color:rgb(204,204,204)">        key[4*i+2] = cipher_data->ks.ks.rd_key[i] >> 8;</span></div><div><span style="background-color:rgb(204,204,204)">        key[4*i+3] = cipher_data->ks.ks.rd_key[i];</span></div><div><span style="background-color:rgb(204,204,204)">    }</span><br><br><span style="background-color:rgb(255,255,255)">I am using this 128 bit key and using it in </span><b style="font-family:sans-serif;font-size:14px">Rijndael</b><span style="font-family:sans-serif;font-size:14px"> Key Schedule function to get the expanded key. The expanded key will be 128*11 bit long.</span></div></div><div><span style="font-family:sans-serif;font-size:14px">This expanded key is equal to the expanded key obtained from accessing structures inside openssl(shown in section</span> "Getting expanded key from inside openssl" <span style="font-family:sans-serif;font-size:14px">) which is expected.</span></div><div><span style="font-family:sans-serif;font-size:14px"><br></span></div><div><span style="font-family:sans-serif;font-size:14px">Now if I configure openssl without no-asm flag and get the expanded key from inside openssl and compare it with the expanded key calculated using the function I wrote. They are not equal. As far as I know there is only one way to calculate expanded key. I have even checked whether the expanded key inside openssl is inverse cipher expanded key but yet it is different.</span></div><div><span style="font-family:sans-serif;font-size:14px">Can someone point me in the right direction.</span></div><div><span style="font-family:sans-serif;font-size:14px">Thanks!</span></div><div><span style="font-family:sans-serif;font-size:14px"><br></span></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><font color="#444444">Best Regards,</font><div><font color="#444444">Hemant Ranvir</font><br><br><font size="2"><font face="arial, helvetica, sans-serif" color="#444444"><i>"<span style="line-height:21px">To live a creative life, we must lose our fear of being wrong.</span></i></font><span style="color:rgb(136,136,136);line-height:21px"><font face="arial, helvetica, sans-serif"><i><font color="#444444">" - J.C.Pearce</font></i></font></span></font><br></div></div></div></div></div></div></div></div></div></div></div></div>