mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
crypto: Use secure_allocator
for AES256CBC*::iv
This commit is contained in:
parent
28d15152f5
commit
15d8500f99
2 changed files with 8 additions and 4 deletions
|
@ -123,6 +123,7 @@ static int CBCDecrypt(const T& dec, const unsigned char iv[AES_BLOCKSIZE], const
|
||||||
AES256CBCEncrypt::AES256CBCEncrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn)
|
AES256CBCEncrypt::AES256CBCEncrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn)
|
||||||
: enc(key), pad(padIn)
|
: enc(key), pad(padIn)
|
||||||
{
|
{
|
||||||
|
iv = allocator.allocate(AES_BLOCKSIZE);
|
||||||
memcpy(iv, ivIn, AES_BLOCKSIZE);
|
memcpy(iv, ivIn, AES_BLOCKSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,12 +134,13 @@ int AES256CBCEncrypt::Encrypt(const unsigned char* data, int size, unsigned char
|
||||||
|
|
||||||
AES256CBCEncrypt::~AES256CBCEncrypt()
|
AES256CBCEncrypt::~AES256CBCEncrypt()
|
||||||
{
|
{
|
||||||
memset(iv, 0, sizeof(iv));
|
allocator.deallocate(iv, AES_BLOCKSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
AES256CBCDecrypt::AES256CBCDecrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn)
|
AES256CBCDecrypt::AES256CBCDecrypt(const unsigned char key[AES256_KEYSIZE], const unsigned char ivIn[AES_BLOCKSIZE], bool padIn)
|
||||||
: dec(key), pad(padIn)
|
: dec(key), pad(padIn)
|
||||||
{
|
{
|
||||||
|
iv = allocator.allocate(AES_BLOCKSIZE);
|
||||||
memcpy(iv, ivIn, AES_BLOCKSIZE);
|
memcpy(iv, ivIn, AES_BLOCKSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,5 +152,5 @@ int AES256CBCDecrypt::Decrypt(const unsigned char* data, int size, unsigned char
|
||||||
|
|
||||||
AES256CBCDecrypt::~AES256CBCDecrypt()
|
AES256CBCDecrypt::~AES256CBCDecrypt()
|
||||||
{
|
{
|
||||||
memset(iv, 0, sizeof(iv));
|
allocator.deallocate(iv, AES_BLOCKSIZE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,10 @@ public:
|
||||||
int Encrypt(const unsigned char* data, int size, unsigned char* out) const;
|
int Encrypt(const unsigned char* data, int size, unsigned char* out) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
secure_allocator<unsigned char> allocator;
|
||||||
const AES256Encrypt enc;
|
const AES256Encrypt enc;
|
||||||
const bool pad;
|
const bool pad;
|
||||||
unsigned char iv[AES_BLOCKSIZE];
|
unsigned char *iv;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AES256CBCDecrypt
|
class AES256CBCDecrypt
|
||||||
|
@ -62,9 +63,10 @@ public:
|
||||||
int Decrypt(const unsigned char* data, int size, unsigned char* out) const;
|
int Decrypt(const unsigned char* data, int size, unsigned char* out) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
secure_allocator<unsigned char> allocator;
|
||||||
const AES256Decrypt dec;
|
const AES256Decrypt dec;
|
||||||
const bool pad;
|
const bool pad;
|
||||||
unsigned char iv[AES_BLOCKSIZE];
|
unsigned char *iv;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_CRYPTO_AES_H
|
#endif // BITCOIN_CRYPTO_AES_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue