Bitcoin ABC  0.22.13
P2P Digital Currency
aes.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 //
5 // C++ wrapper around ctaes, a constant-time AES implementation
6 
7 #ifndef BITCOIN_CRYPTO_AES_H
8 #define BITCOIN_CRYPTO_AES_H
9 
10 extern "C" {
11 #include <crypto/ctaes/ctaes.h>
12 }
13 
14 static const int AES_BLOCKSIZE = 16;
15 static const int AES128_KEYSIZE = 16;
16 static const int AES256_KEYSIZE = 32;
17 
20 private:
22 
23 public:
24  explicit AES128Encrypt(const uint8_t key[16]);
26  void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const;
27 };
28 
31 private:
33 
34 public:
35  explicit AES128Decrypt(const uint8_t key[16]);
36  ~AES128Decrypt();
37  void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const;
38 };
39 
42 private:
44 
45 public:
46  explicit AES256Encrypt(const uint8_t key[32]);
47  ~AES256Encrypt();
48  void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const;
49 };
50 
53 private:
55 
56 public:
57  explicit AES256Decrypt(const uint8_t key[32]);
58  ~AES256Decrypt();
59  void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const;
60 };
61 
63 public:
64  explicit AES256CBCEncrypt(const uint8_t key[AES256_KEYSIZE],
65  const uint8_t ivIn[AES_BLOCKSIZE], bool padIn);
67  int Encrypt(const uint8_t *data, int size, uint8_t *out) const;
68 
69 private:
71  const bool pad;
72  uint8_t iv[AES_BLOCKSIZE];
73 };
74 
76 public:
77  explicit AES256CBCDecrypt(const uint8_t key[AES256_KEYSIZE],
78  const uint8_t ivIn[AES_BLOCKSIZE], bool padIn);
80  int Decrypt(const uint8_t *data, int size, uint8_t *out) const;
81 
82 private:
84  const bool pad;
85  uint8_t iv[AES_BLOCKSIZE];
86 };
87 
89 public:
90  explicit AES128CBCEncrypt(const uint8_t key[AES128_KEYSIZE],
91  const uint8_t ivIn[AES_BLOCKSIZE], bool padIn);
93  int Encrypt(const uint8_t *data, int size, uint8_t *out) const;
94 
95 private:
97  const bool pad;
98  uint8_t iv[AES_BLOCKSIZE];
99 };
100 
102 public:
103  explicit AES128CBCDecrypt(const uint8_t key[AES128_KEYSIZE],
104  const uint8_t ivIn[AES_BLOCKSIZE], bool padIn);
105  ~AES128CBCDecrypt();
106  int Decrypt(const uint8_t *data, int size, uint8_t *out) const;
107 
108 private:
110  const bool pad;
111  uint8_t iv[AES_BLOCKSIZE];
112 };
113 
114 #endif // BITCOIN_CRYPTO_AES_H
AES256_ctx ctx
Definition: aes.h:54
static const int AES256_KEYSIZE
Definition: aes.h:16
A decryption class for AES-256.
Definition: aes.h:52
const AES256Decrypt dec
Definition: aes.h:83
const AES128Encrypt enc
Definition: aes.h:96
An encryption class for AES-256.
Definition: aes.h:41
~AES128Encrypt()
Definition: aes.cpp:17
void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const
Definition: aes.cpp:21
AES128Encrypt(const uint8_t key[16])
Definition: aes.cpp:13
const bool pad
Definition: aes.h:97
const AES128Decrypt dec
Definition: aes.h:109
const bool pad
Definition: aes.h:84
A decryption class for AES-128.
Definition: aes.h:30
const AES256Encrypt enc
Definition: aes.h:70
AES256_ctx ctx
Definition: aes.h:43
static const int AES128_KEYSIZE
Definition: aes.h:15
An encryption class for AES-128.
Definition: aes.h:19
AES128_ctx ctx
Definition: aes.h:21
const bool pad
Definition: aes.h:71
static const int AES_BLOCKSIZE
Definition: aes.h:14
const bool pad
Definition: aes.h:110
AES128_ctx ctx
Definition: aes.h:32