Bitcoin ABC 0.30.5
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
10extern "C" {
11#include <crypto/ctaes/ctaes.h>
12}
13
14static const int AES_BLOCKSIZE = 16;
15static const int AES128_KEYSIZE = 16;
16static const int AES256_KEYSIZE = 32;
17
20private:
22
23public:
24 explicit AES128Encrypt(const uint8_t key[16]);
26 void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const;
27};
28
31private:
33
34public:
35 explicit AES128Decrypt(const uint8_t key[16]);
37 void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const;
38};
39
42private:
44
45public:
46 explicit AES256Encrypt(const uint8_t key[32]);
48 void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const;
49};
50
53private:
55
56public:
57 explicit AES256Decrypt(const uint8_t key[32]);
59 void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const;
60};
61
63public:
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
69private:
71 const bool pad;
72 uint8_t iv[AES_BLOCKSIZE];
73};
74
76public:
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
82private:
84 const bool pad;
85 uint8_t iv[AES_BLOCKSIZE];
86};
87
89public:
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
95private:
97 const bool pad;
98 uint8_t iv[AES_BLOCKSIZE];
99};
100
102public:
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
108private:
110 const bool pad;
112};
113
114#endif // BITCOIN_CRYPTO_AES_H
static const int AES128_KEYSIZE
Definition: aes.h:15
static const int AES256_KEYSIZE
Definition: aes.h:16
static const int AES_BLOCKSIZE
Definition: aes.h:14
~AES128CBCDecrypt()
Definition: aes.cpp:206
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:111
const bool pad
Definition: aes.h:110
int Decrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:210
AES128CBCDecrypt(const uint8_t key[AES128_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:199
const AES128Decrypt dec
Definition: aes.h:109
int Encrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:194
AES128CBCEncrypt(const uint8_t key[AES128_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:183
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:98
const AES128Encrypt enc
Definition: aes.h:96
~AES128CBCEncrypt()
Definition: aes.cpp:190
const bool pad
Definition: aes.h:97
A decryption class for AES-128.
Definition: aes.h:30
AES128Decrypt(const uint8_t key[16])
Definition: aes.cpp:26
AES128_ctx ctx
Definition: aes.h:32
~AES128Decrypt()
Definition: aes.cpp:30
void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const
Definition: aes.cpp:34
An encryption class for AES-128.
Definition: aes.h:19
AES128Encrypt(const uint8_t key[16])
Definition: aes.cpp:13
void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const
Definition: aes.cpp:21
~AES128Encrypt()
Definition: aes.cpp:17
AES128_ctx ctx
Definition: aes.h:21
const bool pad
Definition: aes.h:84
const AES256Decrypt dec
Definition: aes.h:83
AES256CBCDecrypt(const uint8_t key[AES256_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:167
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:85
int Decrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:174
~AES256CBCDecrypt()
Definition: aes.cpp:179
uint8_t iv[AES_BLOCKSIZE]
Definition: aes.h:72
AES256CBCEncrypt(const uint8_t key[AES256_KEYSIZE], const uint8_t ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:151
const bool pad
Definition: aes.h:71
int Encrypt(const uint8_t *data, int size, uint8_t *out) const
Definition: aes.cpp:158
~AES256CBCEncrypt()
Definition: aes.cpp:163
const AES256Encrypt enc
Definition: aes.h:70
A decryption class for AES-256.
Definition: aes.h:52
AES256Decrypt(const uint8_t key[32])
Definition: aes.cpp:52
~AES256Decrypt()
Definition: aes.cpp:56
void Decrypt(uint8_t plaintext[16], const uint8_t ciphertext[16]) const
Definition: aes.cpp:60
AES256_ctx ctx
Definition: aes.h:54
An encryption class for AES-256.
Definition: aes.h:41
void Encrypt(uint8_t ciphertext[16], const uint8_t plaintext[16]) const
Definition: aes.cpp:47
~AES256Encrypt()
Definition: aes.cpp:43
AES256Encrypt(const uint8_t key[32])
Definition: aes.cpp:39
AES256_ctx ctx
Definition: aes.h:43