diff options
author | Jack Lloyd <[email protected]> | 2016-12-11 15:28:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-18 16:48:24 -0500 |
commit | f3cb3edb512bdcab498d825886c3366c341b3f78 (patch) | |
tree | 645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/tests/test_ecies.cpp | |
parent | c1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff) |
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.
Diffstat (limited to 'src/tests/test_ecies.cpp')
-rw-r--r-- | src/tests/test_ecies.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/tests/test_ecies.cpp b/src/tests/test_ecies.cpp index 53775eda4..f900eccb0 100644 --- a/src/tests/test_ecies.cpp +++ b/src/tests/test_ecies.cpp @@ -19,7 +19,6 @@ namespace { #if defined(BOTAN_HAS_ECIES) -using byte = Botan::byte; using Flags = Botan::ECIES_Flags; Botan::PointGFp::Compression_Type get_compression_type(const std::string& format) @@ -51,7 +50,7 @@ void check_encrypt_decrypt(Test::Result& result, const Botan::ECDH_PrivateKey& p const Botan::ECDH_PrivateKey& other_private_key, const Botan::ECIES_System_Params& ecies_params, const Botan::InitializationVector& iv, const std::string& label, - const std::vector<byte>& plaintext, const std::vector<byte>& ciphertext) + const std::vector<uint8_t>& plaintext, const std::vector<uint8_t>& ciphertext) { Botan::ECIES_Encryptor ecies_enc(private_key, ecies_params, Test::rng()); ecies_enc.set_other_key(other_private_key.public_point()); @@ -69,16 +68,16 @@ void check_encrypt_decrypt(Test::Result& result, const Botan::ECDH_PrivateKey& p try { - const std::vector<byte> encrypted = ecies_enc.encrypt(plaintext, Test::rng()); + const std::vector<uint8_t> encrypted = ecies_enc.encrypt(plaintext, Test::rng()); if(!ciphertext.empty()) { result.test_eq("encrypted data", encrypted, ciphertext); } - const Botan::secure_vector<byte> decrypted = ecies_dec.decrypt(encrypted); + const Botan::secure_vector<uint8_t> decrypted = ecies_dec.decrypt(encrypted); result.test_eq("decrypted data equals plaintext", decrypted, plaintext); - std::vector<byte> invalid_encrypted = encrypted; - byte& last_byte = invalid_encrypted[invalid_encrypted.size() - 1]; + std::vector<uint8_t> invalid_encrypted = encrypted; + uint8_t& last_byte = invalid_encrypted[invalid_encrypted.size() - 1]; last_byte = ~last_byte; result.test_throws("throw on invalid ciphertext", [&ecies_dec, &invalid_encrypted] { @@ -95,9 +94,9 @@ void check_encrypt_decrypt(Test::Result& result, const Botan::ECDH_PrivateKey& p const Botan::ECDH_PrivateKey& other_private_key, const Botan::ECIES_System_Params& ecies_params, size_t iv_length = 0) { - const std::vector<byte> plaintext { 1, 2, 3 }; - check_encrypt_decrypt(result, private_key, other_private_key, ecies_params, std::vector<byte>(iv_length, 0), "", - plaintext, std::vector<byte>()); + const std::vector<uint8_t> plaintext { 1, 2, 3 }; + check_encrypt_decrypt(result, private_key, other_private_key, ecies_params, std::vector<uint8_t>(iv_length, 0), "", + plaintext, std::vector<uint8_t>()); } #if defined(BOTAN_HAS_KDF1_18033) && defined(BOTAN_HAS_SHA1) @@ -128,8 +127,8 @@ class ECIES_ISO_Tests : public Text_Based_Test const Botan::BigInt hy = get_req_bn(vars, "hy"); // y of public point of bob const Botan::BigInt x = get_req_bn(vars, "x"); // private key of bob const Botan::BigInt r = get_req_bn(vars, "r"); // (ephemeral) private key of alice - const std::vector<byte> c0 = get_req_bin(vars, "C0"); // expected encoded (ephemeral) public key - const std::vector<byte> k = get_req_bin(vars, "K"); // expected derived secret + const std::vector<uint8_t> c0 = get_req_bin(vars, "C0"); // expected encoded (ephemeral) public key + const std::vector<uint8_t> k = get_req_bin(vars, "K"); // expected derived secret const Botan::CurveGFp curve(p, a, b); const Botan::EC_Group domain(curve, Botan::PointGFp(curve, gx, gy), mu, nu); @@ -142,7 +141,7 @@ class ECIES_ISO_Tests : public Text_Based_Test // (ephemeral) keys of alice const Botan::ECDH_PrivateKey eph_private_key(Test::rng(), domain, r); const Botan::PointGFp eph_public_key_point = eph_private_key.public_point(); - const std::vector<byte> eph_public_key_bin = Botan::unlock( + const std::vector<uint8_t> eph_public_key_bin = Botan::unlock( Botan::EC2OSP(eph_public_key_point, compression_type)); result.test_eq("encoded (ephemeral) public key", eph_public_key_bin, c0); @@ -220,7 +219,7 @@ class ECIES_Tests : public Text_Based_Test const std::string kdf = get_req_str(vars, "Kdf"); const std::string dem = get_req_str(vars, "Dem"); const size_t dem_key_len = get_req_sz(vars, "DemKeyLen"); - const std::vector<byte> iv = get_req_bin(vars, "Iv"); + const std::vector<uint8_t> iv = get_req_bin(vars, "Iv"); const std::string mac = get_req_str(vars, "Mac"); const size_t mac_key_len = get_req_sz(vars, "MacKeyLen"); const Botan::PointGFp::Compression_Type compression_type = get_compression_type(get_req_str(vars, "Format")); @@ -229,8 +228,8 @@ class ECIES_Tests : public Text_Based_Test const bool check_mode = get_req_sz(vars, "CheckMode") != 0; const bool single_hash_mode = get_req_sz(vars, "SingleHashMode") != 0; const std::string label = get_req_str(vars, "Label"); - const std::vector<byte> plaintext = get_req_bin(vars, "Plaintext"); - const std::vector<byte> ciphertext = get_req_bin(vars, "Ciphertext"); + const std::vector<uint8_t> plaintext = get_req_bin(vars, "Plaintext"); + const std::vector<uint8_t> ciphertext = get_req_bin(vars, "Ciphertext"); const Flags flags = ecies_flags(cofactor_mode, old_cofactor_mode, check_mode, single_hash_mode); const Botan::EC_Group domain(curve); @@ -269,7 +268,7 @@ Test::Result test_other_key_not_set() result.test_throws("encrypt not possible without setting other public key", [ &ecies_enc ]() { - ecies_enc.encrypt(std::vector<byte>(8), Test::rng()); + ecies_enc.encrypt(std::vector<uint8_t>(8), Test::rng()); }); return result; @@ -294,7 +293,7 @@ Test::Result test_kdf_not_found() result.test_throws("kdf not found", [ &ecies_enc ]() { - ecies_enc.encrypt(std::vector<byte>(8), Test::rng()); + ecies_enc.encrypt(std::vector<uint8_t>(8), Test::rng()); }); return result; @@ -319,7 +318,7 @@ Test::Result test_mac_not_found() result.test_throws("mac not found", [ &ecies_enc ]() { - ecies_enc.encrypt(std::vector<byte>(8), Test::rng()); + ecies_enc.encrypt(std::vector<uint8_t>(8), Test::rng()); }); return result; @@ -344,7 +343,7 @@ Test::Result test_cipher_not_found() result.test_throws("cipher not found", [ &ecies_enc ]() { - ecies_enc.encrypt(std::vector<byte>(8), Test::rng()); + ecies_enc.encrypt(std::vector<uint8_t>(8), Test::rng()); }); return result; @@ -372,10 +371,10 @@ Test::Result test_system_params_short_ctor() const Botan::InitializationVector iv("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); const std::string label = "Test"; - const std::vector<byte> plaintext = Botan::hex_decode("000102030405060708090A0B0C0D0E0F"); + const std::vector<uint8_t> plaintext = Botan::hex_decode("000102030405060708090A0B0C0D0E0F"); // generated with botan - const std::vector<byte> ciphertext = Botan::hex_decode("0401519EAA0489FF9D51E98E4C22349463E2001CD06F8CE47D81D4007A" + const std::vector<uint8_t> ciphertext = Botan::hex_decode("0401519EAA0489FF9D51E98E4C22349463E2001CD06F8CE47D81D4007A" "79ACF98E92C814686477CEA666EFC277DC84E15FC95E38AFF8E16D478A" "44CD5C5F1517F8B1F300000591317F261C3D04A7207F01EAE3EC70F2360" "0F82C53CC0B85BE7AC9F6CE79EF2AB416E5934D61BA9D346385D7545C57F" |