aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--src/engine/aes_isa_eng/aes_isa_engine.cpp56
-rw-r--r--src/engine/aes_isa_eng/aes_isa_engine.h26
-rw-r--r--src/engine/aes_isa_eng/info.txt3
-rw-r--r--src/libstate/libstate.cpp8
7 files changed, 238 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>
diff --git a/src/engine/aes_isa_eng/aes_isa_engine.cpp b/src/engine/aes_isa_eng/aes_isa_engine.cpp
new file mode 100644
index 000000000..c74f8bddc
--- /dev/null
+++ b/src/engine/aes_isa_eng/aes_isa_engine.cpp
@@ -0,0 +1,56 @@
+/*
+* Engine for AES instructions
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/aes_isa_engine.h>
+#include <botan/cpuid.h>
+
+#if defined(BOTAN_HAS_AES_INTEL)
+ #include <botan/aes_intel.h>
+#endif
+
+#if defined(BOTAN_HAS_AES_VIA)
+ #include <botan/aes_via.h>
+#endif
+
+namespace Botan {
+
+BlockCipher*
+AES_ISA_Engine::find_block_cipher(const SCAN_Name& request,
+ Algorithm_Factory&) const
+ {
+#if defined(BOTAN_HAS_AES_INTEL)
+ if(CPUID::has_intel_aes())
+ {
+ if(request.algo_name() == "AES")
+ return new AES_Intel;
+ if(request.algo_name() == "AES-128")
+ return new AES_Intel_128;
+ if(request.algo_name() == "AES-192")
+ return new AES_Intel_192;
+ if(request.algo_name() == "AES-256")
+ return new AES_Intel_256;
+ }
+#endif
+
+#if defined(BOTAN_HAS_AES_VIA)
+ if(CPUID::has_via_aes())
+ {
+ if(request.algo_name() == "AES")
+ return new AES_Via;
+ if(request.algo_name() == "AES-128")
+ return new AES_Via_128;
+ if(request.algo_name() == "AES-192")
+ return new AES_Via_192;
+ if(request.algo_name() == "AES-256")
+ return new AES_Via_256;
+ }
+#endif
+
+ return 0;
+ }
+
+}
diff --git a/src/engine/aes_isa_eng/aes_isa_engine.h b/src/engine/aes_isa_eng/aes_isa_engine.h
new file mode 100644
index 000000000..602a114a9
--- /dev/null
+++ b/src/engine/aes_isa_eng/aes_isa_engine.h
@@ -0,0 +1,26 @@
+/**
+* Engine for AES instructions
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_AES_ISA_ENGINE_H__
+#define BOTAN_AES_ISA_ENGINE_H__
+
+#include <botan/engine.h>
+
+namespace Botan {
+
+class BOTAN_DLL AES_ISA_Engine : public Engine
+ {
+ public:
+ std::string provider_name() const { return "aes_isa"; }
+ private:
+ BlockCipher* find_block_cipher(const SCAN_Name&,
+ Algorithm_Factory&) const;
+ };
+
+}
+
+#endif
diff --git a/src/engine/aes_isa_eng/info.txt b/src/engine/aes_isa_eng/info.txt
new file mode 100644
index 000000000..c0695aaf3
--- /dev/null
+++ b/src/engine/aes_isa_eng/info.txt
@@ -0,0 +1,3 @@
+define ENGINE_AES_ISA
+
+load_on dep
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp
index c78bce62d..8b039a97a 100644
--- a/src/libstate/libstate.cpp
+++ b/src/libstate/libstate.cpp
@@ -37,6 +37,10 @@
#include <botan/eng_amd64.h>
#endif
+#if defined(BOTAN_HAS_ENGINE_AES_ISA)
+ #include <botan/aes_isa_engine.h>
+#endif
+
#if defined(BOTAN_HAS_ENGINE_SIMD)
#include <botan/simd_engine.h>
#endif
@@ -288,6 +292,10 @@ void Library_State::initialize(bool thread_safe)
engines.push_back(new OpenSSL_Engine);
#endif
+#if defined(BOTAN_HAS_ENGINE_AES_ISA)
+ engines.push_back(new AES_ISA_Engine);
+#endif
+
#if defined(BOTAN_HAS_ENGINE_SIMD)
engines.push_back(new SIMD_Engine);
#endif