Bitcoin Core  22.99.0
P2P Digital Currency
aes.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2019 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 AES256_KEYSIZE = 32;
16 
19 {
20 private:
22 
23 public:
24  explicit AES256Encrypt(const unsigned char key[32]);
26  void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const;
27 };
28 
31 {
32 private:
34 
35 public:
36  explicit AES256Decrypt(const unsigned char key[32]);
38  void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;
39 };
40 
42 {
43 public:
44  AES256CBCEncrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);
46  int Encrypt(const unsigned char* data, int size, unsigned char* out) const;
47 
48 private:
50  const bool pad;
51  unsigned char iv[AES_BLOCKSIZE];
52 };
53 
55 {
56 public:
57  AES256CBCDecrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);
59  int Decrypt(const unsigned char* data, int size, unsigned char* out) const;
60 
61 private:
63  const bool pad;
64  unsigned char iv[AES_BLOCKSIZE];
65 };
66 
67 #endif // BITCOIN_CRYPTO_AES_H
AES256CBCDecrypt::iv
unsigned char iv[AES_BLOCKSIZE]
Definition: aes.h:64
AES256CBCEncrypt::pad
const bool pad
Definition: aes.h:50
AES256CBCEncrypt::iv
unsigned char iv[AES_BLOCKSIZE]
Definition: aes.h:51
AES256Decrypt::ctx
AES256_ctx ctx
Definition: aes.h:33
AES256Decrypt::AES256Decrypt
AES256Decrypt(const unsigned char key[32])
Definition: aes.cpp:28
AES256Encrypt::AES256Encrypt
AES256Encrypt(const unsigned char key[32])
Definition: aes.cpp:13
AES256Encrypt::Encrypt
void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const
Definition: aes.cpp:23
AES256CBCDecrypt::dec
const AES256Decrypt dec
Definition: aes.h:62
AES256Decrypt::Decrypt
void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const
Definition: aes.cpp:38
AES256CBCDecrypt::pad
const bool pad
Definition: aes.h:63
AES256Encrypt::~AES256Encrypt
~AES256Encrypt()
Definition: aes.cpp:18
AES256_KEYSIZE
static const int AES256_KEYSIZE
Definition: aes.h:15
AES256CBCDecrypt::Decrypt
int Decrypt(const unsigned char *data, int size, unsigned char *out) const
Definition: aes.cpp:144
AES256CBCDecrypt::AES256CBCDecrypt
AES256CBCDecrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:137
AES256CBCDecrypt
Definition: aes.h:54
AES256CBCEncrypt
Definition: aes.h:41
AES256CBCEncrypt::AES256CBCEncrypt
AES256CBCEncrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn)
Definition: aes.cpp:121
AES256_ctx
Definition: ctaes.h:25
AES256Encrypt
An encryption class for AES-256.
Definition: aes.h:18
AES256CBCDecrypt::~AES256CBCDecrypt
~AES256CBCDecrypt()
Definition: aes.cpp:149
AES_BLOCKSIZE
static const int AES_BLOCKSIZE
Definition: aes.h:14
AES256CBCEncrypt::Encrypt
int Encrypt(const unsigned char *data, int size, unsigned char *out) const
Definition: aes.cpp:127
AES256Decrypt::~AES256Decrypt
~AES256Decrypt()
Definition: aes.cpp:33
AES256Encrypt::ctx
AES256_ctx ctx
Definition: aes.h:21
AES256CBCEncrypt::enc
const AES256Encrypt enc
Definition: aes.h:49
ctaes.h
AES256CBCEncrypt::~AES256CBCEncrypt
~AES256CBCEncrypt()
Definition: aes.cpp:132
AES256Decrypt
A decryption class for AES-256.
Definition: aes.h:30