Esempio n. 1
0
void intel_AES_dec128(UCHAR *cipherText,UCHAR *plainText,UCHAR *key,size_t numBlocks)
{
    DEFINE_ROUND_KEYS
    sAesData aesData;
    aesData.in_block = cipherText;
    aesData.out_block = plainText;
    aesData.expanded_key = expandedKey;
    aesData.num_blocks = numBlocks;

    iDecExpandKey128(key,expandedKey);
    iDec128(&aesData);
}
Esempio n. 2
0
void tDecAES::m_init(nOperationModeAES opmode, const u8 key[], nKeyLengthAES keylen,
                     bool useFastASM)
{
    // Set fields.
    m_opmode = opmode;
    m_keylen = keylen;
    m_useASM = useFastASM;
    m_expandedKey = NULL;

    // Check the opmode.
    switch (opmode)
    {
        case kOpModeECB: break;
        case kOpModeCBC: break;
        default: throw eInvalidArgument("The opmode parameter is not valid!");
    }

    // Check the keylen.
    switch (keylen)
    {
        case k128bit: break;
        case k192bit: break;
        case k256bit: break;
        default: throw eInvalidArgument("The keylen parameter is not valid!");
    }

    // Fast ASM setup:
    if (m_useASM)
    {
        m_expandedKey = s_aligned_malloc(256, 16);
        switch (keylen)
        {
            case k128bit:
            {
                u8* key_copy = new u8[16];
                memcpy(key_copy, key, 16);
                iDecExpandKey128(key_copy, m_expandedKey);
                delete [] key_copy;
                break;
            }
            case k192bit:
            {
                u8* key_copy = new u8[24];
                memcpy(key_copy, key, 24);
                iDecExpandKey192(key_copy, m_expandedKey);
                delete [] key_copy;
                break;
            }
            case k256bit:
            {
                u8* key_copy = new u8[32];
                memcpy(key_copy, key, 32);
                iDecExpandKey256(key_copy, m_expandedKey);
                delete [] key_copy;
                break;
            }
            default: throw eInvalidArgument("The keylen parameter is not valid!");
        }
    }

    // Fallback setup:
    else
    {
        int keybits;
        int expectedNr;
        switch (keylen)
        {
            case k128bit: keybits = 128; expectedNr = 10; break;
            case k192bit: keybits = 192; expectedNr = 12; break;
            case k256bit: keybits = 256; expectedNr = 14; break;
            default: throw eInvalidArgument("The keylen parameter is not valid!");
        }
        m_Nr = rijndaelKeySetupDec(m_rk, key, keybits);
        if (m_Nr != expectedNr)
            throw eImpossiblePath();
    }
}