From f3cb3edb512bdcab498d825886c3366c341b3f78 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 11 Dec 2016 15:28:38 -0500 Subject: Convert to using standard uintN_t integer types Renames a couple of functions for somewhat better name consistency, eg make_u32bit becomes make_uint32. The old typedefs remain for now since probably lots of application code uses them. --- src/lib/misc/cryptobox/cryptobox.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/lib/misc/cryptobox/cryptobox.cpp') diff --git a/src/lib/misc/cryptobox/cryptobox.cpp b/src/lib/misc/cryptobox/cryptobox.cpp index 95cdda149..944adef49 100644 --- a/src/lib/misc/cryptobox/cryptobox.cpp +++ b/src/lib/misc/cryptobox/cryptobox.cpp @@ -25,7 +25,7 @@ namespace { First 24 bits of SHA-256("Botan Cryptobox"), followed by 8 0 bits for later use as flags, etc if needed */ -const u32bit CRYPTOBOX_VERSION_CODE = 0xEFC22400; +const uint32_t CRYPTOBOX_VERSION_CODE = 0xEFC22400; const size_t VERSION_CODE_LEN = 4; const size_t CIPHER_KEY_LEN = 32; @@ -39,11 +39,11 @@ const size_t PBKDF_OUTPUT_LEN = CIPHER_KEY_LEN + CIPHER_IV_LEN + MAC_KEY_LEN; } -std::string encrypt(const byte input[], size_t input_len, +std::string encrypt(const uint8_t input[], size_t input_len, const std::string& passphrase, RandomNumberGenerator& rng) { - secure_vector pbkdf_salt(PBKDF_SALT_LEN); + secure_vector pbkdf_salt(PBKDF_SALT_LEN); rng.randomize(pbkdf_salt.data(), pbkdf_salt.size()); PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512)); @@ -55,7 +55,7 @@ std::string encrypt(const byte input[], size_t input_len, pbkdf_salt.size(), PBKDF_ITERATIONS); - const byte* mk = master_key.begin(); + const uint8_t* mk = master_key.begin(); SymmetricKey cipher_key(mk, CIPHER_KEY_LEN); SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN); @@ -78,7 +78,7 @@ std::string encrypt(const byte input[], size_t input_len, */ const size_t ciphertext_len = pipe.remaining(0); - std::vector out_buf(VERSION_CODE_LEN + + std::vector out_buf(VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN + ciphertext_len); @@ -99,11 +99,11 @@ std::string encrypt(const byte input[], size_t input_len, return PEM_Code::encode(out_buf, "BOTAN CRYPTOBOX MESSAGE"); } -std::string decrypt(const byte input[], size_t input_len, +std::string decrypt(const uint8_t input[], size_t input_len, const std::string& passphrase) { DataSource_Memory input_src(input, input_len); - secure_vector ciphertext = + secure_vector ciphertext = PEM_Code::decode_check_label(input_src, "BOTAN CRYPTOBOX MESSAGE"); @@ -114,7 +114,7 @@ std::string decrypt(const byte input[], size_t input_len, if(ciphertext[i] != get_byte(i, CRYPTOBOX_VERSION_CODE)) throw Decoding_Error("Bad CryptoBox version"); - const byte* pbkdf_salt = &ciphertext[VERSION_CODE_LEN]; + const uint8_t* pbkdf_salt = &ciphertext[VERSION_CODE_LEN]; PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512)); @@ -125,7 +125,7 @@ std::string decrypt(const byte input[], size_t input_len, PBKDF_SALT_LEN, PBKDF_ITERATIONS); - const byte* mk = master_key.begin(); + const uint8_t* mk = master_key.begin(); SymmetricKey cipher_key(mk, CIPHER_KEY_LEN); SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN); @@ -142,7 +142,7 @@ std::string decrypt(const byte input[], size_t input_len, pipe.process_msg(&ciphertext[ciphertext_offset], ciphertext.size() - ciphertext_offset); - byte computed_mac[MAC_OUTPUT_LEN]; + uint8_t computed_mac[MAC_OUTPUT_LEN]; BOTAN_ASSERT_EQUAL(MAC_OUTPUT_LEN, pipe.read(computed_mac, MAC_OUTPUT_LEN, 1), "MAC size"); if(!same_mem(computed_mac, @@ -156,7 +156,7 @@ std::string decrypt(const byte input[], size_t input_len, std::string decrypt(const std::string& input, const std::string& passphrase) { - return decrypt(reinterpret_cast(input.data()), + return decrypt(reinterpret_cast(input.data()), input.size(), passphrase); } -- cgit v1.2.3