Bitcoin ABC  0.24.7
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]);
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]);
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]);
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);
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
AES128Encrypt::ctx
AES128_ctx ctx
Definition: aes.h:21
AES256CBCEncrypt::pad
const bool pad
Definition: aes.h:71
AES128CBCDecrypt
Definition: aes.h:101
AES128CBCDecrypt::AES128CBCDecrypt
AES128CBCDecrypt(const uint8_t key[AES128_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:199
AES256Decrypt::ctx
AES256_ctx ctx
Definition: aes.h:54
AES256Decrypt::Decrypt
void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const
Definition: aes.cpp:60
AES128CBCEncrypt
Definition: aes.h:88
AES128Encrypt::Encrypt
void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const
Definition: aes.cpp:21
AES256Encrypt::AES256Encrypt
AES256Encrypt(const uint8_t key[32])
Definition: aes.cpp:39
AES256CBCDecrypt::dec
const AES256Decrypt dec
Definition: aes.h:83
AES256CBCDecrypt::pad
const bool pad
Definition: aes.h:84
AES256Encrypt::Encrypt
void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const
Definition: aes.cpp:47
AES256Encrypt::~AES256Encrypt
~AES256Encrypt()
Definition: aes.cpp:43
AES128CBCEncrypt::enc
const AES128Encrypt enc
Definition: aes.h:96
AES256_KEYSIZE
static const int AES256_KEYSIZE
Definition: aes.h:16
AES128Decrypt::~AES128Decrypt
~AES128Decrypt()
Definition: aes.cpp:30
AES256Decrypt::AES256Decrypt
AES256Decrypt(const uint8_t key[32])
Definition: aes.cpp:52
AES128Decrypt
A decryption class for AES-128.
Definition: aes.h:30
AES128Encrypt::AES128Encrypt
AES128Encrypt(const uint8_t key[16])
Definition: aes.cpp:13
AES128Encrypt::~AES128Encrypt
~AES128Encrypt()
Definition: aes.cpp:17
AES128CBCDecrypt::~AES128CBCDecrypt
~AES128CBCDecrypt()
Definition: aes.cpp:206
AES256CBCDecrypt
Definition: aes.h:75
AES256CBCEncrypt
Definition: aes.h:62
AES128CBCDecrypt::dec
const AES128Decrypt dec
Definition: aes.h:109
AES256CBCEncrypt::Encrypt
int Encrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:158
AES256_ctx
Definition: ctaes.h:25
AES128CBCDecrypt::iv
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:111
AES256Encrypt
An encryption class for AES-256.
Definition: aes.h:41
AES256CBCDecrypt::Decrypt
int Decrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:174
AES128CBCEncrypt::pad
const bool pad
Definition: aes.h:97
AES256CBCDecrypt::~AES256CBCDecrypt
~AES256CBCDecrypt()
Definition: aes.cpp:179
AES256CBCEncrypt::iv
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:72
AES_BLOCKSIZE
static const int AES_BLOCKSIZE
Definition: aes.h:14
AES128CBCEncrypt::Encrypt
int Encrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:194
AES256Decrypt::~AES256Decrypt
~AES256Decrypt()
Definition: aes.cpp:56
AES256CBCDecrypt::AES256CBCDecrypt
AES256CBCDecrypt(const uint8_t key[AES256_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:167
AES128Decrypt::Decrypt
void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const
Definition: aes.cpp:34
AES128CBCEncrypt::AES128CBCEncrypt
AES128CBCEncrypt(const uint8_t key[AES128_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:183
AES128_ctx
Definition: ctaes.h:17
AES256CBCDecrypt::iv
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:85
AES128Decrypt::ctx
AES128_ctx ctx
Definition: aes.h:32
AES256Encrypt::ctx
AES256_ctx ctx
Definition: aes.h:43
AES128_KEYSIZE
static const int AES128_KEYSIZE
Definition: aes.h:15
AES128CBCDecrypt::Decrypt
int Decrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:210
AES256CBCEncrypt::enc
const AES256Encrypt enc
Definition: aes.h:70
AES256CBCEncrypt::AES256CBCEncrypt
AES256CBCEncrypt(const uint8_t key[AES256_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:151
AES128CBCDecrypt::pad
const bool pad
Definition: aes.h:110
ctaes.h
AES128CBCEncrypt::~AES128CBCEncrypt
~AES128CBCEncrypt()
Definition: aes.cpp:190
AES128Decrypt::AES128Decrypt
AES128Decrypt(const uint8_t key[16])
Definition: aes.cpp:26
AES256CBCEncrypt::~AES256CBCEncrypt
~AES256CBCEncrypt()
Definition: aes.cpp:163
AES128Encrypt
An encryption class for AES-128.
Definition: aes.h:19
AES256Decrypt
A decryption class for AES-256.
Definition: aes.h:52
AES128CBCEncrypt::iv
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:98