コード例 #1
0
ファイル: intel_aes.c プロジェクト: mimaun/Rose
void intel_AES_dec192(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;

    iDecExpandKey192(key,expandedKey);
    iDec192(&aesData);
}
コード例 #2
0
ファイル: tDecAES.cpp プロジェクト: Rhobota/librho
void tDecAES::dec(u8* ctbuf, u8* ptbuf, u32 numblocks, u8* iv)
{
    // Fast ASM impl:
    if (m_useASM)
    {
        sAesData data;
        data.in_block = ctbuf;
        data.out_block = ptbuf;
        data.expanded_key = m_expandedKey;
        data.iv = iv;
        data.num_blocks = numblocks;
        if (m_opmode == kOpModeCBC && iv)
        {
            switch (m_keylen)
            {
                case k128bit: iDec128_CBC(&data); break;
                case k192bit: iDec192_CBC(&data); break;
                case k256bit: iDec256_CBC(&data); break;
                default: throw eInvalidArgument("The keylen parameter is not valid!");
            }
        }
        else
        {
            switch (m_keylen)
            {
                case k128bit: iDec128(&data); break;
                case k192bit: iDec192(&data); break;
                case k256bit: iDec256(&data); break;
                default: throw eInvalidArgument("The keylen parameter is not valid!");
            }
        }
    }

    // Fallback impl:
    else
    {
        u32* rk = m_rk;
        int Nr = m_Nr;
        if (m_opmode == kOpModeCBC && iv)
        {
            u8 ct[AES_BLOCK_SIZE];
            for (u32 i = 0; numblocks > 0; i+=AES_BLOCK_SIZE, --numblocks)
            {
                for (u32 j = 0; j < AES_BLOCK_SIZE; j++)
                    ct[j] = ctbuf[i+j];
                rijndaelDecrypt(rk, Nr, ct, ptbuf+i);
                for (u32 j = 0; j < AES_BLOCK_SIZE; j++)
                {
                    ptbuf[i+j] ^= iv[j];
                    iv[j] = ct[j];
                }
            }
        }
        else
        {
            for (u32 i = 0; numblocks > 0; i+=AES_BLOCK_SIZE, --numblocks)
            {
                rijndaelDecrypt(rk, Nr, ctbuf+i, ptbuf+i);
            }
        }
    }
}