public static void generate_subkey(AES_ctx* ctx, byte* K1, byte* K2)
{
var _L = new byte[16];
var _Z = new byte[16];
var _tmp = new byte[16];
int i;
fixed (byte* tmp = _tmp)
fixed (byte* L = _L)
fixed (byte* Z = _Z)
fixed (byte* const_Rb = _const_Rb)
{
for ( i=0; i<16; i++ ) Z[i] = 0;
AES_encrypt(ctx, Z, L);
if ( (L[0] & 0x80) == 0 ) /* If MSB(L) = 0, then K1 = L << 1 */
{
leftshift_onebit(L,K1);
} else { /* Else K1 = ( L << 1 ) (+) Rb */
leftshift_onebit(L,tmp);
xor_128(tmp,const_Rb,K1);
}
if ( (K1[0] & 0x80) == 0 )
{
leftshift_onebit(K1,K2);
} else {
leftshift_onebit(K1,tmp);
xor_128(tmp,const_Rb,K2);
}
}
}