<div dir="auto">Hi Jacob, thanks for the input. </div><br><div class="gmail_quote"><div dir="ltr">On Tue 11 Dec, 2018, 4:24 PM Jakob Bohm via openssl-users, <<a href="mailto:openssl-users@openssl.org">openssl-users@openssl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 10/12/2018 11:30, Hemant Ranvir wrote:<br>
> Dear all,<br>
>     After extracting openssl-1.1.1.tar.gz, openssl can be configured <br>
> without asm by passing no-asm flag during config command.<br>
><br>
>     The expanded key can be obtained like follows:<br>
> //Getting expanded key from inside openssl<br>
> //Copied from crypto/evp/e_aes.c<br>
> typedef struct {<br>
>   union {<br>
>       double align;<br>
>       AES_KEY ks;<br>
>   } ks;<br>
>   block128_f block;<br>
>   union {<br>
>       cbc128_f cbc;<br>
>       ctr128_f ctr;<br>
>   } stream;<br>
> } EVP_AES_KEY;<br>
><br>
> EVP_CIPHER_CTX *cipher_ctx = ssl->enc_write_ctx;<br>
> EVP_AES_KEY * cipher_data = EVP_CIPHER_CTX_get_cipher_data(cipher_ctx);<br>
> printf("Encrypted Expanded Key is : ");<br>
> for(i=0;i<((cipher_ctx->cipher->key_len)/sizeof(cipher_data->ks.ks.rd_key[0])*11);i++) <br>
> {<br>
>     printf("%08x", cipher_data->ks.ks.rd_key[i]);<br>
> }<br>
> printf("\n");<br>
><br>
>  To get the 128 bit encrypted key :<br>
> unsigned char* key = unsigned char* malloc(16);<br>
>   int i;<br>
>   for (i=0; i<4; i++) {<br>
>       key[4*i]   = cipher_data->ks.ks.rd_key[i] >> 24;<br>
>       key[4*i+1] = cipher_data->ks.ks.rd_key[i] >> 16;<br>
>       key[4*i+2] = cipher_data->ks.ks.rd_key[i] >> 8;<br>
>       key[4*i+3] = cipher_data->ks.ks.rd_key[i];<br>
>   }<br>
><br>
> I am using this 128 bit key and using it in *Rijndael* Key Schedule <br>
> function to get the expanded key. The expanded key will be 128*11 bit <br>
> long.<br>
> This expanded key is equal to the expanded key obtained from accessing <br>
> structures inside openssl(shown in section "Getting expanded key from <br>
> inside openssl" ) which is expected.<br>
><br>
> Now if I configure openssl without no-asm flag and get the expanded <br>
> key from inside openssl and compare it with the expanded key <br>
> calculated using the function I wrote. They are not equal. As far as I <br>
> know there is only one way to calculate expanded key. I have even <br>
> checked whether the expanded key inside openssl is inverse cipher <br>
> expanded key but yet it is different.<br>
> Can someone point me in the right direction.<br>
> Thanks!<br>
><br>
><br>
There have always been multiple ways to store the expanded AES<br>
key, each optimized a different implementation of the inner<br>
loops in the encryption block function.  It is highly likely<br>
the assembler implementation for any given processor uses a<br>
different inner loop, and thus a different expanded key data<br>
layout, than the generic C code.<br>
<br>
<br>
Enjoy<br>
<br>
Jakob<br>
-- <br>
Jakob Bohm, CIO, Partner, WiseMo A/S.  <a href="https://www.wisemo.com" rel="noreferrer noreferrer" target="_blank">https://www.wisemo.com</a><br>
Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10<br>
This public discussion message is non-binding and may contain errors.<br>
WiseMo - Remote Service Management for PCs, Phones and Embedded<br>
<br>
-- <br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer noreferrer" target="_blank">https://mta.openssl.org/mailman/listinfo/openssl-users</a><br>
</blockquote></div>