aboutsummaryrefslogtreecommitdiffstats
path: root/src/constructs/cryptobox
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-13 12:28:27 +0000
committerlloyd <[email protected]>2010-09-13 12:28:27 +0000
commit27d79c87365105d6128afe9eaf8a82383976ed44 (patch)
tree9a4f0e1d5ae7ecd5c058c0293d9b546191990cdb /src/constructs/cryptobox
parent9acfc3a50b31044e48d8dee5fc8030ad7f4518d4 (diff)
Anywhere where we use MemoryRegion::begin to get access to the raw pointer
representation (rather than in an interator context), instead use &buf[0], which works for both MemoryRegion and std::vector
Diffstat (limited to 'src/constructs/cryptobox')
-rw-r--r--src/constructs/cryptobox/cryptobox.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/constructs/cryptobox/cryptobox.cpp b/src/constructs/cryptobox/cryptobox.cpp
index 61fe51a88..0c37949bc 100644
--- a/src/constructs/cryptobox/cryptobox.cpp
+++ b/src/constructs/cryptobox/cryptobox.cpp
@@ -45,18 +45,22 @@ std::string encrypt(const byte input[], u32bit input_len,
RandomNumberGenerator& rng)
{
SecureVector<byte> pbkdf_salt(PBKDF_SALT_LEN);
- rng.randomize(pbkdf_salt.begin(), pbkdf_salt.size());
+ rng.randomize(&pbkdf_salt[0], pbkdf_salt.size());
PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512));
- OctetString mk = pbkdf.derive_key(PBKDF_OUTPUT_LEN, passphrase,
- &pbkdf_salt[0], pbkdf_salt.size(),
- PBKDF_ITERATIONS);
+ OctetString master_key = pbkdf.derive_key(
+ PBKDF_OUTPUT_LEN,
+ passphrase,
+ &pbkdf_salt[0],
+ pbkdf_salt.size(),
+ PBKDF_ITERATIONS);
- SymmetricKey cipher_key(mk.begin(), CIPHER_KEY_LEN);
- SymmetricKey mac_key(mk.begin() + CIPHER_KEY_LEN, MAC_KEY_LEN);
- InitializationVector iv(mk.begin() + CIPHER_KEY_LEN + MAC_KEY_LEN,
- CIPHER_IV_LEN);
+ const byte* mk = master_key.begin();
+
+ SymmetricKey cipher_key(&mk[0], CIPHER_KEY_LEN);
+ SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN);
+ InitializationVector iv(&mk[CIPHER_KEY_LEN + MAC_KEY_LEN], CIPHER_IV_LEN);
Pipe pipe(get_cipher("Serpent/CTR-BE", cipher_key, iv, ENCRYPTION),
new Fork(
@@ -89,8 +93,7 @@ std::string encrypt(const byte input[], u32bit input_len,
pipe.read(out_buf + VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN,
ciphertext_len, 0);
- return PEM_Code::encode(out_buf.begin(), out_buf.size(),
- "BOTAN CRYPTOBOX MESSAGE");
+ return PEM_Code::encode(out_buf, "BOTAN CRYPTOBOX MESSAGE");
}
std::string decrypt(const byte input[], u32bit input_len,
@@ -112,14 +115,18 @@ std::string decrypt(const byte input[], u32bit input_len,
PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512));
- OctetString mk = pbkdf.derive_key(PBKDF_OUTPUT_LEN, passphrase,
- &pbkdf_salt[0], pbkdf_salt.size(),
- PBKDF_ITERATIONS);
+ OctetString master_key = pbkdf.derive_key(
+ PBKDF_OUTPUT_LEN,
+ passphrase,
+ &pbkdf_salt[0],
+ pbkdf_salt.size(),
+ PBKDF_ITERATIONS);
+
+ const byte* mk = master_key.begin();
- SymmetricKey cipher_key(mk.begin(), CIPHER_KEY_LEN);
- SymmetricKey mac_key(mk.begin() + CIPHER_KEY_LEN, MAC_KEY_LEN);
- InitializationVector iv(mk.begin() + CIPHER_KEY_LEN + MAC_KEY_LEN,
- CIPHER_IV_LEN);
+ SymmetricKey cipher_key(&mk[0], CIPHER_KEY_LEN);
+ SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN);
+ InitializationVector iv(&mk[CIPHER_KEY_LEN + MAC_KEY_LEN], CIPHER_IV_LEN);
Pipe pipe(new Fork(
get_cipher("Serpent/CTR-BE", cipher_key, iv, DECRYPTION),