aboutsummaryrefslogtreecommitdiffstats
path: root/src/block
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-11-06 15:48:58 +0000
committerlloyd <[email protected]>2009-11-06 15:48:58 +0000
commit89da502ff80a9c63038b8b02a5062e460dff4649 (patch)
tree336208ded07cf9adcf7144d5748109fa24ad026c /src/block
parent2fa888b0147a644de0df42fe0721eeb385810714 (diff)
Stub for AES class using Intel's AES-NI instructions and an engine for
providing it. Also stubs in the engine for VIA's AES instructions, but needs CPUID checking also.
Diffstat (limited to 'src/block')
-rw-r--r--src/block/aes_intel/aes_intel.cpp62
-rw-r--r--src/block/aes_intel/aes_intel.h74
-rw-r--r--src/block/aes_intel/info.txt9
3 files changed, 145 insertions, 0 deletions
diff --git a/src/block/aes_intel/aes_intel.cpp b/src/block/aes_intel/aes_intel.cpp
new file mode 100644
index 000000000..bd814e6c8
--- /dev/null
+++ b/src/block/aes_intel/aes_intel.cpp
@@ -0,0 +1,62 @@
+/**
+* AES
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/aes_intel.h>
+
+namespace Botan {
+
+/**
+* AES Encryption
+*/
+void AES_Intel::encrypt_n(const byte in[], byte out[], u32bit blocks) const
+ {
+ for(u32bit i = 0; i != blocks; ++i)
+ {
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
+ }
+ }
+
+/**
+* AES Decryption
+*/
+void AES_Intel::decrypt_n(const byte in[], byte out[], u32bit blocks) const
+ {
+
+ for(u32bit i = 0; i != blocks; ++i)
+ {
+
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
+ }
+ }
+
+/**
+* AES Key Schedule
+*/
+void AES_Intel::key_schedule(const byte key[], u32bit length)
+ {
+ }
+
+/**
+* AES Constructor
+*/
+AES_Intel::AES_Intel(u32bit key_size) : BlockCipher(16, key_size)
+ {
+ if(key_size != 16 && key_size != 24 && key_size != 32)
+ throw Invalid_Key_Length(name(), key_size);
+ ROUNDS = (key_size / 4) + 6;
+ }
+
+/**
+* Clear memory of sensitive data
+*/
+void AES_Intel::clear()
+ {
+ }
+
+}
diff --git a/src/block/aes_intel/aes_intel.h b/src/block/aes_intel/aes_intel.h
new file mode 100644
index 000000000..b40c2d3f6
--- /dev/null
+++ b/src/block/aes_intel/aes_intel.h
@@ -0,0 +1,74 @@
+/**
+* AES using Intel's AES instructions
+* (C) 1999-2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_AES_INTEL_H__
+#define BOTAN_AES_INTEL_H__
+
+#include <botan/block_cipher.h>
+
+namespace Botan {
+
+class BOTAN_DLL AES_Intel : public BlockCipher
+ {
+ public:
+ void encrypt_n(const byte in[], byte out[], u32bit blocks) const;
+ void decrypt_n(const byte in[], byte out[], u32bit blocks) const;
+
+ void clear();
+ std::string name() const { return "AES"; }
+ BlockCipher* clone() const { return new AES_Intel; }
+
+ AES_Intel() : BlockCipher(16, 16, 32, 8) { ROUNDS = 14; }
+ AES_Intel(u32bit);
+ private:
+ void key_schedule(const byte[], u32bit);
+
+ u32bit ROUNDS;
+
+ SecureBuffer<u32bit, 56> EK;
+ SecureBuffer<byte, 16> ME;
+
+ SecureBuffer<u32bit, 56> DK;
+ SecureBuffer<byte, 16> MD;
+ };
+
+/**
+* AES-128
+*/
+class BOTAN_DLL AES_Intel_128 : public AES_Intel
+ {
+ public:
+ std::string name() const { return "AES-128"; }
+ BlockCipher* clone() const { return new AES_Intel_128; }
+ AES_Intel_128() : AES_Intel(16) {}
+ };
+
+/**
+* AES-192
+*/
+class BOTAN_DLL AES_Intel_192 : public AES_Intel
+ {
+ public:
+ std::string name() const { return "AES-192"; }
+ BlockCipher* clone() const { return new AES_Intel_192; }
+ AES_Intel_192() : AES_Intel(24) {}
+ };
+
+/**
+* AES-256
+*/
+class BOTAN_DLL AES_Intel_256 : public AES_Intel
+ {
+ public:
+ std::string name() const { return "AES-256"; }
+ BlockCipher* clone() const { return new AES_Intel_256; }
+ AES_Intel_256() : AES_Intel(32) {}
+ };
+
+}
+
+#endif
diff --git a/src/block/aes_intel/info.txt b/src/block/aes_intel/info.txt
new file mode 100644
index 000000000..1a156a635
--- /dev/null
+++ b/src/block/aes_intel/info.txt
@@ -0,0 +1,9 @@
+define AES_INTEL
+
+load_on auto
+
+#isa aes_ni
+
+<requires>
+aes_isa_eng
+</requires>