1 /**
2 * SIMD Assembly Engine
3 * 
4 * Copyright:
5 * (C) 1999-2009 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 *
8 * License:
9 * Botan is released under the Simplified BSD License (see LICENSE.md)
10 */
11 module botan.engine.simd_engine;
12 
13 import botan.constants;
14 static if (BOTAN_HAS_ENGINE_SIMD):
15 
16 import botan.engine.engine;
17 import botan.simd.simd_32;
18 import botan.utils.cpuid;
19 
20 static if (BOTAN_HAS_AES_SSSE3)          import botan.block.aes_ssse3;
21 static if (BOTAN_HAS_SERPENT_SIMD)       import botan.block.serp_simd;
22 static if (BOTAN_HAS_THREEFISH_512_AVX2) import botan.block.threefish_avx2;
23 static if (BOTAN_HAS_NOEKEON_SIMD)       import botan.block.noekeon_simd;
24 static if (BOTAN_HAS_XTEA_SIMD)          import botan.block.xtea_simd;
25 static if (BOTAN_HAS_IDEA_SSE2)          import botan.block.idea_sse2;
26 static if (BOTAN_HAS_SHA1_SSE2)          import botan.hash.sha1_sse2;
27 
28 /**
29 * Engine for implementations that use some kind of SIMD
30 */
31 final class SIMDEngine : Engine
32 {
33 public:
34     string providerName() const { return "simd"; }
35 
36     BlockCipher findBlockCipher(in SCANToken request, AlgorithmFactory) const
37     {
38         static if (BOTAN_HAS_AES_SSSE3) {
39             if (request.algoName == "AES-128" && CPUID.hasSsse3())
40                 return new AES128_SSSE3;
41             if (request.algoName == "AES-192" && CPUID.hasSsse3())
42                 return new AES192_SSSE3;
43             if (request.algoName == "AES-256" && CPUID.hasSsse3())
44                 return new AES256_SSSE3;
45         }
46         
47         static if (BOTAN_HAS_IDEA_SSE2) {
48             if (request.algoName == "IDEA" && CPUID.hasSse2())
49                 return new IDEASSE2;
50         }
51         
52         static if (BOTAN_HAS_NOEKEON_SIMD) {
53             if (request.algoName == "Noekeon" && SIMD32.enabled())
54                 return new NoekeonSIMD;
55         }
56         
57         static if (BOTAN_HAS_THREEFISH_512_AVX2) {
58             if (request.algoName == "Threefish-512" && CPUID.hasAvx2())
59                 return new Threefish512AVX2;
60         }
61         
62         static if (BOTAN_HAS_SERPENT_SIMD) {
63             if (request.algoName == "Serpent" && SIMD32.enabled())
64                 return new SerpentSIMD;
65         }
66         
67         static if (BOTAN_HAS_XTEA_SIMD) {
68             if (request.algoName == "XTEA" && SIMD32.enabled())
69                 return new XTEASIMD;
70         }
71         
72         return null;
73     }
74 
75     HashFunction findHash(in SCANToken request, AlgorithmFactory) const
76     {
77         static if (BOTAN_HAS_SHA1_SSE2) {
78             if (request.algoName == "SHA-160" && CPUID.hasSse2())
79                 return new SHA160SSE2;
80         }
81 
82         return null;
83     }
84 
85 
86     StreamCipher findStreamCipher(in SCANToken algo_spec, AlgorithmFactory af) const
87     { return null; }
88     
89     MessageAuthenticationCode findMac(in SCANToken algo_spec, AlgorithmFactory af) const
90     { return null; }
91     
92     PBKDF findPbkdf(in SCANToken algo_spec, AlgorithmFactory af) const
93     { return null; }
94     
95     KeyedFilter getCipher(in string algo_spec, CipherDir dir, AlgorithmFactory af) const
96     { return null; }
97     
98     static if (BOTAN_HAS_PUBLIC_KEY_CRYPTO):
99 
100     ModularExponentiator modExp(const ref BigInt n, PowerMod.UsageHints hints) const
101     { return null; }
102 
103     KeyAgreement getKeyAgreementOp(in PrivateKey key, RandomNumberGenerator rng) const
104     { return null; }
105     
106     Signature getSignatureOp(in PrivateKey key, RandomNumberGenerator rng) const
107     { return null; }
108     
109     Verification getVerifyOp(in PublicKey key, RandomNumberGenerator rng) const
110     { return null; }
111     
112     Encryption getEncryptionOp(in PublicKey key, RandomNumberGenerator rng) const
113     { return null; }
114     
115     Decryption getDecryptionOp(in PrivateKey key, RandomNumberGenerator rng) const
116     { return null; }
117 }