|
24 | 24 |
|
25 | 25 | namespace libbitcoin { |
26 | 26 | namespace system { |
27 | | -namespace aes256 { |
28 | | - |
29 | | -/// This is an implementation of AES256 (in ECB mode). |
30 | | -/// ECB mode is the simplest block cipher mode but is insecure for most |
31 | | -/// applications because it doesn't hide patterns in the plaintext. |
32 | | -/// NIST selected three members of the Rijndael family, each with a block |
33 | | -/// size of 128 bits, but three different key lengths: 128, 192 and 256 bits. |
34 | 27 |
|
35 | | -constexpr size_t block_size = bytes<128>; |
36 | | -typedef data_array<block_size> block; |
| 28 | +/// Advanced Encryption Standard (AES) 256. |
| 29 | +class BC_API aes256 final |
| 30 | +{ |
| 31 | +public: |
| 32 | + /// AES block is always 128 bits. |
| 33 | + typedef data_array<bytes<128>> block; |
37 | 34 |
|
38 | | -constexpr size_t secret_size = bytes<256>; |
39 | | -typedef data_array<secret_size> secret; |
| 35 | + /// AES-256 secret is always 256 bits. |
| 36 | + typedef data_array<bytes<256>> secret; |
40 | 37 |
|
41 | | -/// Perform aes256 encryption/decryption on a data block. |
42 | | -void encrypt(block& bytes, const secret& key) NOEXCEPT; |
43 | | -void decrypt(block& bytes, const secret& key) NOEXCEPT; |
| 38 | + /// nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197-upd1.pdf |
| 39 | + static void encrypt_ecb(block& bytes, const secret& key) NOEXCEPT; |
| 40 | + static void decrypt_ecb(block& bytes, const secret& key) NOEXCEPT; |
| 41 | + |
| 42 | +private: |
| 43 | + struct context |
| 44 | + { |
| 45 | + secret key; |
| 46 | + secret enckey; |
| 47 | + secret deckey; |
| 48 | + }; |
| 49 | + |
| 50 | + static void initialize(context& context, const secret& key) NOEXCEPT; |
| 51 | + static void encrypt_ecb(context& context, block& bytes) NOEXCEPT; |
| 52 | + static void decrypt_ecb(context& context, block& bytes) NOEXCEPT; |
| 53 | +}; |
44 | 54 |
|
45 | | -} // namespace aes256 |
46 | 55 | } // namespace system |
47 | 56 | } // namespace libbitcoin |
48 | 57 |
|
|
0 commit comments