aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/aes.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2015-03-20 00:49:13 -0400
committerPieter Wuille <pieter.wuille@gmail.com>2016-05-13 10:23:03 +0200
commit27a212dcb4fe842ead77d01b98f2c1a58ecca609 (patch)
tree4f1afa080592b352e84fc52d5871034cac5b5cf8 /src/crypto/aes.h
parent6bec172eb95e195847bb6dd6d4e62ada79c98c6d (diff)
crypto: add AES 128/256 CBC classes
The output should always match openssl's, even for failed operations. Even for a decrypt with broken padding, the output is always deterministic (and attemtps to be constant-time).
Diffstat (limited to 'src/crypto/aes.h')
-rw-r--r--src/crypto/aes.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/crypto/aes.h b/src/crypto/aes.h
index 4bf17a33ea..8cae357c12 100644
--- a/src/crypto/aes.h
+++ b/src/crypto/aes.h
@@ -63,4 +63,56 @@ public:
void Decrypt(unsigned char plaintext[16], const unsigned char ciphertext[16]) const;
};
+class AES256CBCEncrypt
+{
+public:
+ AES256CBCEncrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);
+ ~AES256CBCEncrypt();
+ int Encrypt(const unsigned char* data, int size, unsigned char* out) const;
+
+private:
+ const AES256Encrypt enc;
+ const bool pad;
+ unsigned char iv[AES_BLOCKSIZE];
+};
+
+class AES256CBCDecrypt
+{
+public:
+ AES256CBCDecrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);
+ ~AES256CBCDecrypt();
+ int Decrypt(const unsigned char* data, int size, unsigned char* out) const;
+
+private:
+ const AES256Decrypt dec;
+ const bool pad;
+ unsigned char iv[AES_BLOCKSIZE];
+};
+
+class AES128CBCEncrypt
+{
+public:
+ AES128CBCEncrypt(const unsigned char key[AES128_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);
+ ~AES128CBCEncrypt();
+ int Encrypt(const unsigned char* data, int size, unsigned char* out) const;
+
+private:
+ const AES128Encrypt enc;
+ const bool pad;
+ unsigned char iv[AES_BLOCKSIZE];
+};
+
+class AES128CBCDecrypt
+{
+public:
+ AES128CBCDecrypt(const unsigned char key[AES128_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn);
+ ~AES128CBCDecrypt();
+ int Decrypt(const unsigned char* data, int size, unsigned char* out) const;
+
+private:
+ const AES128Decrypt dec;
+ const bool pad;
+ unsigned char iv[AES_BLOCKSIZE];
+};
+
#endif // BITCOIN_CRYPTO_AES_H