Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2015-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.4//5// C++ wrapper around ctaes, a constant-time AES implementation7#ifndef BITCOIN_CRYPTO_AES_H8#define BITCOIN_CRYPTO_AES_H10#include <support/allocators/secure.h>11extern "C" {12#include <crypto/ctaes/ctaes.h>13}15inline constexpr int AES_BLOCKSIZE = 16;16inline constexpr int AES256_KEYSIZE = 32;18/** An encryption class for AES-256. */19class AES256Encrypt20{21private:22secure_allocator<AES256_ctx> allocator;23AES256_ctx *ctx;25public:26explicit AES256Encrypt(const unsigned char key[32]);27~AES256Encrypt();28void Encrypt(unsigned char ciphertext[16], const unsigned char plaintext[16]) const;29};31/** A decryption class for AES-256. */32class AES256Decrypt33{34private:35secure_allocator<AES256_ctx> allocator;36AES256_ctx *ctx;38public:39explicit AES256Decrypt(const unsigned char key[32]);40~AES256Decrypt();41void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;42};44class AES256CBCEncrypt45{46public:47AES256CBCEncrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);48~AES256CBCEncrypt();49int Encrypt(const unsigned char* data, int size, unsigned char* out) const;51private:52secure_allocator<unsigned char> allocator;53const AES256Encrypt enc;54const bool pad;55unsigned char *iv;56};58class AES256CBCDecrypt59{60public:61AES256CBCDecrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);62~AES256CBCDecrypt();63int Decrypt(const unsigned char* data, int size, unsigned char* out) const;65private:66secure_allocator<unsigned char> allocator;67const AES256Decrypt dec;68const bool pad;69unsigned char *iv;70};72#endif // BITCOIN_CRYPTO_AES_H