Botan::AES_256_Intel Class Reference

#include <aes_intel.h>

Inheritance diagram for Botan::AES_256_Intel:

Botan::BlockCipher Botan::SymmetricAlgorithm

List of all members.

Public Member Functions

 AES_256_Intel ()
void clear ()
BlockCipherclone () const
void decrypt (byte block[]) const
void decrypt (const byte in[], byte out[]) const
void decrypt_n (const byte in[], byte out[], u32bit blocks) const
void encrypt (byte block[]) const
void encrypt (const byte in[], byte out[]) const
void encrypt_n (const byte in[], byte out[], u32bit blocks) const
std::string name () const
u32bit parallel_bytes () const
u32bit parallelism () const
void set_key (const byte key[], u32bit length)
void set_key (const SymmetricKey &key)
bool valid_keylength (u32bit length) const

Public Attributes

const u32bit BLOCK_SIZE
const u32bit KEYLENGTH_MULTIPLE
const u32bit MAXIMUM_KEYLENGTH
const u32bit MINIMUM_KEYLENGTH


Detailed Description

AES-256 using AES-NI

Definition at line 62 of file aes_intel.h.


Constructor & Destructor Documentation

Botan::AES_256_Intel::AES_256_Intel (  )  [inline]

Definition at line 74 of file aes_intel.h.

00074 : BlockCipher(16, 32) { }


Member Function Documentation

void Botan::AES_256_Intel::clear (  )  [virtual]

Zeroize internal state

Implements Botan::BlockCipher.

Definition at line 773 of file aes_intel.cpp.

References Botan::MemoryRegion< T >::clear().

00774    {
00775    EK.clear();
00776    DK.clear();
00777    }

BlockCipher* Botan::AES_256_Intel::clone (  )  const [inline, virtual]

Get a new object representing the same algorithm as *this

Implements Botan::BlockCipher.

Definition at line 72 of file aes_intel.h.

00072 { return new AES_256_Intel; }

void Botan::BlockCipher::decrypt ( byte  block[]  )  const [inline, inherited]

Decrypt a block.

Parameters:
block the ciphertext block to be decrypted Must be of length BLOCK_SIZE. Will hold the result when the function has finished.

Definition at line 89 of file block_cipher.h.

00089 { decrypt_n(block, block, 1); }

void Botan::BlockCipher::decrypt ( const byte  in[],
byte  out[] 
) const [inline, inherited]

Decrypt a block.

Parameters:
in The ciphertext block to be decypted as a byte array. Must be of length BLOCK_SIZE.
out The byte array designated to hold the decrypted block. Must be of length BLOCK_SIZE.

Definition at line 72 of file block_cipher.h.

Referenced by Botan::DESX::decrypt_n().

00073          { decrypt_n(in, out, 1); }

void Botan::AES_256_Intel::decrypt_n ( const byte  in[],
byte  out[],
u32bit  blocks 
) const [virtual]

Decrypt one or more blocks

Parameters:
in the input buffer (multiple of BLOCK_SIZE)
out the output buffer (same size as in)
blocks the number of blocks to process

Implements Botan::BlockCipher.

Definition at line 620 of file aes_intel.cpp.

References AES_DEC_4_LAST_ROUNDS, and AES_DEC_4_ROUNDS.

00621    {
00622    const __m128i* in_mm = (const __m128i*)in;
00623    __m128i* out_mm = (__m128i*)out;
00624 
00625    const __m128i* key_mm = (const __m128i*)&DK[0];
00626 
00627    __m128i K0  = _mm_loadu_si128(key_mm);
00628    __m128i K1  = _mm_loadu_si128(key_mm + 1);
00629    __m128i K2  = _mm_loadu_si128(key_mm + 2);
00630    __m128i K3  = _mm_loadu_si128(key_mm + 3);
00631    __m128i K4  = _mm_loadu_si128(key_mm + 4);
00632    __m128i K5  = _mm_loadu_si128(key_mm + 5);
00633    __m128i K6  = _mm_loadu_si128(key_mm + 6);
00634    __m128i K7  = _mm_loadu_si128(key_mm + 7);
00635    __m128i K8  = _mm_loadu_si128(key_mm + 8);
00636    __m128i K9  = _mm_loadu_si128(key_mm + 9);
00637    __m128i K10 = _mm_loadu_si128(key_mm + 10);
00638    __m128i K11 = _mm_loadu_si128(key_mm + 11);
00639    __m128i K12 = _mm_loadu_si128(key_mm + 12);
00640    __m128i K13 = _mm_loadu_si128(key_mm + 13);
00641    __m128i K14 = _mm_loadu_si128(key_mm + 14);
00642 
00643    while(blocks >= 4)
00644       {
00645       __m128i B0 = _mm_loadu_si128(in_mm + 0);
00646       __m128i B1 = _mm_loadu_si128(in_mm + 1);
00647       __m128i B2 = _mm_loadu_si128(in_mm + 2);
00648       __m128i B3 = _mm_loadu_si128(in_mm + 3);
00649 
00650       B0 = _mm_xor_si128(B0, K0);
00651       B1 = _mm_xor_si128(B1, K0);
00652       B2 = _mm_xor_si128(B2, K0);
00653       B3 = _mm_xor_si128(B3, K0);
00654 
00655       AES_DEC_4_ROUNDS(K1);
00656       AES_DEC_4_ROUNDS(K2);
00657       AES_DEC_4_ROUNDS(K3);
00658       AES_DEC_4_ROUNDS(K4);
00659       AES_DEC_4_ROUNDS(K5);
00660       AES_DEC_4_ROUNDS(K6);
00661       AES_DEC_4_ROUNDS(K7);
00662       AES_DEC_4_ROUNDS(K8);
00663       AES_DEC_4_ROUNDS(K9);
00664       AES_DEC_4_ROUNDS(K10);
00665       AES_DEC_4_ROUNDS(K11);
00666       AES_DEC_4_ROUNDS(K12);
00667       AES_DEC_4_ROUNDS(K13);
00668       AES_DEC_4_LAST_ROUNDS(K14);
00669 
00670       _mm_storeu_si128(out_mm + 0, B0);
00671       _mm_storeu_si128(out_mm + 1, B1);
00672       _mm_storeu_si128(out_mm + 2, B2);
00673       _mm_storeu_si128(out_mm + 3, B3);
00674 
00675       blocks -= 4;
00676       in_mm += 4;
00677       out_mm += 4;
00678       }
00679 
00680    for(u32bit i = 0; i != blocks; ++i)
00681       {
00682       __m128i B = _mm_loadu_si128(in_mm + i);
00683 
00684       B = _mm_xor_si128(B, K0);
00685 
00686       B = _mm_aesdec_si128(B, K1);
00687       B = _mm_aesdec_si128(B, K2);
00688       B = _mm_aesdec_si128(B, K3);
00689       B = _mm_aesdec_si128(B, K4);
00690       B = _mm_aesdec_si128(B, K5);
00691       B = _mm_aesdec_si128(B, K6);
00692       B = _mm_aesdec_si128(B, K7);
00693       B = _mm_aesdec_si128(B, K8);
00694       B = _mm_aesdec_si128(B, K9);
00695       B = _mm_aesdec_si128(B, K10);
00696       B = _mm_aesdec_si128(B, K11);
00697       B = _mm_aesdec_si128(B, K12);
00698       B = _mm_aesdec_si128(B, K13);
00699       B = _mm_aesdeclast_si128(B, K14);
00700 
00701       _mm_storeu_si128(out_mm + i, B);
00702       }
00703    }

void Botan::BlockCipher::encrypt ( byte  block[]  )  const [inline, inherited]

Encrypt a block.

Parameters:
block the plaintext block to be encrypted Must be of length BLOCK_SIZE. Will hold the result when the function has finished.

Definition at line 81 of file block_cipher.h.

00081 { encrypt_n(block, block, 1); }

void Botan::BlockCipher::encrypt ( const byte  in[],
byte  out[] 
) const [inline, inherited]

Encrypt a block.

Parameters:
in The plaintext block to be encrypted as a byte array. Must be of length BLOCK_SIZE.
out The byte array designated to hold the encrypted block. Must be of length BLOCK_SIZE.

Definition at line 62 of file block_cipher.h.

Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::OFB::cipher(), Botan::DESX::encrypt_n(), Botan::OFB::set_iv(), Botan::XTS_Decryption::set_iv(), Botan::XTS_Encryption::set_iv(), Botan::CFB_Decryption::set_iv(), and Botan::CFB_Encryption::set_iv().

00063          { encrypt_n(in, out, 1); }

void Botan::AES_256_Intel::encrypt_n ( const byte  in[],
byte  out[],
u32bit  blocks 
) const [virtual]

Encrypt one or more blocks

Parameters:
in the input buffer (multiple of BLOCK_SIZE)
out the output buffer (same size as in)
blocks the number of blocks to process

Implements Botan::BlockCipher.

Definition at line 532 of file aes_intel.cpp.

References AES_ENC_4_LAST_ROUNDS, and AES_ENC_4_ROUNDS.

00533    {
00534    const __m128i* in_mm = (const __m128i*)in;
00535    __m128i* out_mm = (__m128i*)out;
00536 
00537    const __m128i* key_mm = (const __m128i*)&EK[0];
00538 
00539    __m128i K0  = _mm_loadu_si128(key_mm);
00540    __m128i K1  = _mm_loadu_si128(key_mm + 1);
00541    __m128i K2  = _mm_loadu_si128(key_mm + 2);
00542    __m128i K3  = _mm_loadu_si128(key_mm + 3);
00543    __m128i K4  = _mm_loadu_si128(key_mm + 4);
00544    __m128i K5  = _mm_loadu_si128(key_mm + 5);
00545    __m128i K6  = _mm_loadu_si128(key_mm + 6);
00546    __m128i K7  = _mm_loadu_si128(key_mm + 7);
00547    __m128i K8  = _mm_loadu_si128(key_mm + 8);
00548    __m128i K9  = _mm_loadu_si128(key_mm + 9);
00549    __m128i K10 = _mm_loadu_si128(key_mm + 10);
00550    __m128i K11 = _mm_loadu_si128(key_mm + 11);
00551    __m128i K12 = _mm_loadu_si128(key_mm + 12);
00552    __m128i K13 = _mm_loadu_si128(key_mm + 13);
00553    __m128i K14 = _mm_loadu_si128(key_mm + 14);
00554 
00555    while(blocks >= 4)
00556       {
00557       __m128i B0 = _mm_loadu_si128(in_mm + 0);
00558       __m128i B1 = _mm_loadu_si128(in_mm + 1);
00559       __m128i B2 = _mm_loadu_si128(in_mm + 2);
00560       __m128i B3 = _mm_loadu_si128(in_mm + 3);
00561 
00562       B0 = _mm_xor_si128(B0, K0);
00563       B1 = _mm_xor_si128(B1, K0);
00564       B2 = _mm_xor_si128(B2, K0);
00565       B3 = _mm_xor_si128(B3, K0);
00566 
00567       AES_ENC_4_ROUNDS(K1);
00568       AES_ENC_4_ROUNDS(K2);
00569       AES_ENC_4_ROUNDS(K3);
00570       AES_ENC_4_ROUNDS(K4);
00571       AES_ENC_4_ROUNDS(K5);
00572       AES_ENC_4_ROUNDS(K6);
00573       AES_ENC_4_ROUNDS(K7);
00574       AES_ENC_4_ROUNDS(K8);
00575       AES_ENC_4_ROUNDS(K9);
00576       AES_ENC_4_ROUNDS(K10);
00577       AES_ENC_4_ROUNDS(K11);
00578       AES_ENC_4_ROUNDS(K12);
00579       AES_ENC_4_ROUNDS(K13);
00580       AES_ENC_4_LAST_ROUNDS(K14);
00581 
00582       _mm_storeu_si128(out_mm + 0, B0);
00583       _mm_storeu_si128(out_mm + 1, B1);
00584       _mm_storeu_si128(out_mm + 2, B2);
00585       _mm_storeu_si128(out_mm + 3, B3);
00586 
00587       blocks -= 4;
00588       in_mm += 4;
00589       out_mm += 4;
00590       }
00591 
00592    for(u32bit i = 0; i != blocks; ++i)
00593       {
00594       __m128i B = _mm_loadu_si128(in_mm + i);
00595 
00596       B = _mm_xor_si128(B, K0);
00597 
00598       B = _mm_aesenc_si128(B, K1);
00599       B = _mm_aesenc_si128(B, K2);
00600       B = _mm_aesenc_si128(B, K3);
00601       B = _mm_aesenc_si128(B, K4);
00602       B = _mm_aesenc_si128(B, K5);
00603       B = _mm_aesenc_si128(B, K6);
00604       B = _mm_aesenc_si128(B, K7);
00605       B = _mm_aesenc_si128(B, K8);
00606       B = _mm_aesenc_si128(B, K9);
00607       B = _mm_aesenc_si128(B, K10);
00608       B = _mm_aesenc_si128(B, K11);
00609       B = _mm_aesenc_si128(B, K12);
00610       B = _mm_aesenc_si128(B, K13);
00611       B = _mm_aesenclast_si128(B, K14);
00612 
00613       _mm_storeu_si128(out_mm + i, B);
00614       }
00615    }

std::string Botan::AES_256_Intel::name (  )  const [inline, virtual]

The name of the algorithm.

Returns:
name of the algorithm

Implements Botan::SymmetricAlgorithm.

Definition at line 71 of file aes_intel.h.

00071 { return "AES-256"; }

u32bit Botan::BlockCipher::parallel_bytes (  )  const [inline, inherited]

Returns:
prefererred parallelism of this cipher in bytes

Definition at line 50 of file block_cipher.h.

Referenced by Botan::CTR_BE::CTR_BE().

00051          {
00052          return parallelism() * BLOCK_SIZE * BOTAN_BLOCK_CIPHER_PAR_MULT;
00053          }

u32bit Botan::AES_256_Intel::parallelism (  )  const [inline, virtual]

Returns:
native parallelism of this cipher in blocks

Reimplemented from Botan::BlockCipher.

Definition at line 65 of file aes_intel.h.

00065 { return 4; }

void Botan::SymmetricAlgorithm::set_key ( const byte  key[],
u32bit  length 
) [inline, inherited]

Set the symmetric key of this object.

Parameters:
key the to be set as a byte array.
length in bytes of key param

Definition at line 57 of file sym_algo.h.

00058          {
00059          if(!valid_keylength(length))
00060             throw Invalid_Key_Length(name(), length);
00061          key_schedule(key, length);
00062          }

void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key  )  [inline, inherited]

bool Botan::SymmetricAlgorithm::valid_keylength ( u32bit  length  )  const [inline, inherited]

Check whether a given key length is valid for this algorithm.

Parameters:
length the key length to be checked.
Returns:
true if the key length is valid.

Definition at line 69 of file sym_algo.h.

Referenced by Botan::aont_package(), Botan::aont_unpackage(), Botan::HMAC_RNG::HMAC_RNG(), Botan::Lion::Lion(), Botan::Randpool::Randpool(), Botan::XTS_Decryption::set_key(), Botan::XTS_Encryption::set_key(), Botan::EAX_Base::valid_keylength(), Botan::MAC_Filter::valid_keylength(), and Botan::valid_keylength_for().

00070          {
00071          return ((length >= MINIMUM_KEYLENGTH) &&
00072                  (length <= MAXIMUM_KEYLENGTH) &&
00073                  (length % KEYLENGTH_MULTIPLE == 0));
00074          }


Member Data Documentation

The block size of this algorithm.

Definition at line 40 of file block_cipher.h.

Referenced by Botan::ANSI_X931_RNG::ANSI_X931_RNG(), Botan::aont_package(), Botan::aont_unpackage(), Botan::Cascade_Cipher::Cascade_Cipher(), Botan::CBC_Decryption::CBC_Decryption(), Botan::CBC_Encryption::CBC_Encryption(), Botan::CFB_Decryption::CFB_Decryption(), Botan::CFB_Encryption::CFB_Encryption(), Botan::Lion::clone(), Botan::CMAC::CMAC(), Botan::CTS_Decryption::CTS_Decryption(), Botan::CTS_Encryption::CTS_Encryption(), Botan::XTEA_SIMD::decrypt_n(), Botan::XTEA::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::TEA::decrypt_n(), Botan::Square::decrypt_n(), Botan::Skipjack::decrypt_n(), Botan::Serpent_SIMD::decrypt_n(), Botan::Serpent_IA32::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::SEED::decrypt_n(), Botan::SAFER_SK::decrypt_n(), Botan::RC6::decrypt_n(), Botan::RC5::decrypt_n(), Botan::RC2::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::MISTY1::decrypt_n(), Botan::MARS::decrypt_n(), Botan::LubyRackoff::decrypt_n(), Botan::Lion::decrypt_n(), Botan::KASUMI::decrypt_n(), Botan::IDEA_SSE2::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::DESX::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::DES::decrypt_n(), Botan::CAST_256::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::Cascade_Cipher::decrypt_n(), Botan::Blowfish::decrypt_n(), Botan::AES::decrypt_n(), Botan::XTEA_SIMD::encrypt_n(), Botan::XTEA::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::TEA::encrypt_n(), Botan::Square::encrypt_n(), Botan::Skipjack::encrypt_n(), Botan::Serpent_SIMD::encrypt_n(), Botan::Serpent_IA32::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::SEED::encrypt_n(), Botan::SAFER_SK::encrypt_n(), Botan::RC6::encrypt_n(), Botan::RC5::encrypt_n(), Botan::RC2::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::MISTY1::encrypt_n(), Botan::MARS::encrypt_n(), Botan::LubyRackoff::encrypt_n(), Botan::Lion::encrypt_n(), Botan::KASUMI::encrypt_n(), Botan::IDEA_SSE2::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::DESX::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::DES::encrypt_n(), Botan::CAST_256::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::Cascade_Cipher::encrypt_n(), Botan::Blowfish::encrypt_n(), Botan::AES::encrypt_n(), Botan::get_cipher_mode(), Botan::Lion::Lion(), Botan::Lion::name(), Botan::OFB::OFB(), Botan::Randpool::Randpool(), Botan::CTR_BE::set_iv(), Botan::XTS_Decryption::set_iv(), Botan::XTS_Encryption::set_iv(), Botan::XTS_Decryption::XTS_Decryption(), and Botan::XTS_Encryption::XTS_Encryption().

A valid keylength is a multiple of this value.

Definition at line 37 of file sym_algo.h.

Referenced by Botan::keylength_multiple_of().

The maximum allowed key length.

Definition at line 27 of file sym_algo.h.

Referenced by Botan::max_keylength_of().

The minimal allowed key length.

Definition at line 32 of file sym_algo.h.

Referenced by Botan::min_keylength_of().


The documentation for this class was generated from the following files:

Generated on Tue Jun 29 08:56:41 2010 for Botan by  doxygen 1.5.8