diff options
author | Jack Lloyd <[email protected]> | 2018-03-10 10:24:25 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-10 10:27:12 -0500 |
commit | 9141f982c7679a27a265a84ba34d9695017883c9 (patch) | |
tree | 2853c6c86ab7ac70dde74692a82ec01c15bbbb20 /src/tests | |
parent | ea0f46dfcab59938fc863ca8d01552392c3c5a34 (diff) |
Add PointGFp::encode as replacement for EC2OSP
Literally every single call to EC2OSP is converting the returned
secure_vector to a std::vector. Which makes sense since private
points are not really a thing in any protocol I know of.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_ecies.cpp | 3 | ||||
-rw-r--r-- | src/tests/test_pkcs11_high_level.cpp | 33 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 16 |
3 files changed, 31 insertions, 21 deletions
diff --git a/src/tests/test_ecies.cpp b/src/tests/test_ecies.cpp index 2ce931bae..911d0c3a3 100644 --- a/src/tests/test_ecies.cpp +++ b/src/tests/test_ecies.cpp @@ -137,8 +137,7 @@ class ECIES_ISO_Tests final : 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<uint8_t> eph_public_key_bin = Botan::unlock( - Botan::EC2OSP(eph_public_key_point, compression_type)); + const std::vector<uint8_t> eph_public_key_bin = eph_public_key_point.encode(compression_type); result.test_eq("encoded (ephemeral) public key", eph_public_key_bin, c0); // test secret derivation: ISO 18033 test vectors use KDF1 from ISO 18033 diff --git a/src/tests/test_pkcs11_high_level.cpp b/src/tests/test_pkcs11_high_level.cpp index e89715189..b8ed97a54 100644 --- a/src/tests/test_pkcs11_high_level.cpp +++ b/src/tests/test_pkcs11_high_level.cpp @@ -980,9 +980,12 @@ Test::Result test_ecdsa_pubkey_import() ECDSA_PrivateKey priv_key(Test::rng(), EC_Group("secp256r1")); priv_key.set_parameter_encoding(EC_Group_Encoding::EC_DOMPAR_ENC_OID); + const std::vector<uint8_t> enc_point = DER_Encoder().encode( + priv_key.public_point().encode(PointGFp::UNCOMPRESSED), OCTET_STRING). + get_contents_unlocked(); + // import to card - EC_PublicKeyImportProperties props(priv_key.DER_domain(), DER_Encoder().encode(EC2OSP(priv_key.public_point(), - PointGFp::UNCOMPRESSED), OCTET_STRING).get_contents_unlocked()); + EC_PublicKeyImportProperties props(priv_key.DER_domain(), enc_point); props.set_token(true); props.set_verify(true); props.set_private(false); @@ -1008,9 +1011,12 @@ Test::Result test_ecdsa_pubkey_export() ECDSA_PrivateKey priv_key(Test::rng(), EC_Group("secp256r1")); priv_key.set_parameter_encoding(EC_Group_Encoding::EC_DOMPAR_ENC_OID); + const std::vector<uint8_t> enc_point = DER_Encoder().encode( + priv_key.public_point().encode(PointGFp::UNCOMPRESSED), OCTET_STRING). + get_contents_unlocked(); + // import to card - EC_PublicKeyImportProperties props(priv_key.DER_domain(), DER_Encoder().encode(EC2OSP(priv_key.public_point(), - PointGFp::UNCOMPRESSED), OCTET_STRING).get_contents_unlocked()); + EC_PublicKeyImportProperties props(priv_key.DER_domain(), enc_point); props.set_token(true); props.set_verify(true); props.set_private(false); @@ -1216,9 +1222,12 @@ Test::Result test_ecdh_pubkey_import() ECDH_PrivateKey priv_key(Test::rng(), EC_Group("secp256r1")); priv_key.set_parameter_encoding(EC_Group_Encoding::EC_DOMPAR_ENC_OID); + const std::vector<uint8_t> enc_point = DER_Encoder().encode( + priv_key.public_point().encode(PointGFp::UNCOMPRESSED), OCTET_STRING). + get_contents_unlocked(); + // import to card - EC_PublicKeyImportProperties props(priv_key.DER_domain(), DER_Encoder().encode(EC2OSP(priv_key.public_point(), - PointGFp::UNCOMPRESSED), OCTET_STRING).get_contents_unlocked()); + EC_PublicKeyImportProperties props(priv_key.DER_domain(), enc_point); props.set_token(true); props.set_private(false); props.set_derive(true); @@ -1244,9 +1253,12 @@ Test::Result test_ecdh_pubkey_export() ECDH_PrivateKey priv_key(Test::rng(), EC_Group("secp256r1")); priv_key.set_parameter_encoding(EC_Group_Encoding::EC_DOMPAR_ENC_OID); + const std::vector<uint8_t> enc_point = DER_Encoder().encode( + priv_key.public_point().encode(PointGFp::UNCOMPRESSED), OCTET_STRING). + get_contents_unlocked(); + // import to card - EC_PublicKeyImportProperties props(priv_key.DER_domain(), DER_Encoder().encode(EC2OSP(priv_key.public_point(), - PointGFp::UNCOMPRESSED), OCTET_STRING).get_contents_unlocked()); + EC_PublicKeyImportProperties props(priv_key.DER_domain(), enc_point); props.set_token(true); props.set_derive(true); props.set_private(false); @@ -1332,9 +1344,8 @@ Test::Result test_ecdh_derive() Botan::PK_Key_Agreement ka(keypair.second, Test::rng(), "Raw"); Botan::PK_Key_Agreement kb(keypair2.second, Test::rng(), "Raw"); - Botan::SymmetricKey alice_key = ka.derive_key(32, unlock(EC2OSP(keypair2.first.public_point(), - PointGFp::UNCOMPRESSED))); - Botan::SymmetricKey bob_key = kb.derive_key(32, unlock(EC2OSP(keypair.first.public_point(), PointGFp::UNCOMPRESSED))); + Botan::SymmetricKey alice_key = ka.derive_key(32, keypair2.first.public_point().encode(PointGFp::UNCOMPRESSED)); + Botan::SymmetricKey bob_key = kb.derive_key(32, keypair.first.public_point().encode(PointGFp::UNCOMPRESSED)); bool eq = alice_key == bob_key; result.test_eq("same secret key derived", eq, true); diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp index cbff3ff4f..f3a163435 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -429,13 +429,13 @@ Test::Result test_zeropoint_enc_dec() Botan::PointGFp p = secp160r1.zero_point(); result.confirm("zero point is zero", p.is_zero()); - std::vector<uint8_t> sv_p = unlock(EC2OSP(p, Botan::PointGFp::UNCOMPRESSED)); + std::vector<uint8_t> sv_p = p.encode(Botan::PointGFp::UNCOMPRESSED); result.test_eq("encoded/decode rt works", secp160r1.OS2ECP(sv_p), p); - sv_p = unlock(EC2OSP(p, Botan::PointGFp::COMPRESSED)); + sv_p = p.encode(Botan::PointGFp::COMPRESSED); result.test_eq("encoded/decode compressed rt works", secp160r1.OS2ECP(sv_p), p); - sv_p = unlock(EC2OSP(p, Botan::PointGFp::HYBRID)); + sv_p = p.encode(Botan::PointGFp::HYBRID); result.test_eq("encoded/decode hybrid rt works", secp160r1.OS2ECP(sv_p), p); return result; } @@ -572,7 +572,7 @@ Test::Result test_enc_dec_compressed_160() const Botan::PointGFp p = secp160r1.OS2ECP(G_comp); - std::vector<uint8_t> sv_result = unlock(Botan::EC2OSP(p, Botan::PointGFp::COMPRESSED)); + std::vector<uint8_t> sv_result = p.encode(Botan::PointGFp::COMPRESSED); result.test_eq("result", sv_result, G_comp); return result; @@ -588,7 +588,7 @@ Test::Result test_enc_dec_compressed_256() const std::vector<uint8_t> sv_G_secp_comp = Botan::hex_decode(G_secp_comp); Botan::PointGFp p_G = group.OS2ECP(sv_G_secp_comp); - std::vector<uint8_t> sv_result = unlock(EC2OSP(p_G, Botan::PointGFp::COMPRESSED)); + std::vector<uint8_t> sv_result = p_G.encode(Botan::PointGFp::COMPRESSED); result.test_eq("compressed_256", sv_result, sv_G_secp_comp); return result; @@ -619,7 +619,7 @@ Test::Result test_enc_dec_uncompressed_112() const std::vector<uint8_t> sv_G_secp_uncomp = Botan::hex_decode(G_secp_uncomp); Botan::PointGFp p_G = group.OS2ECP(sv_G_secp_uncomp); - std::vector<uint8_t> sv_result = unlock(EC2OSP(p_G, Botan::PointGFp::UNCOMPRESSED)); + std::vector<uint8_t> sv_result = p_G.encode(Botan::PointGFp::UNCOMPRESSED); result.test_eq("uncompressed_112", sv_result, sv_G_secp_uncomp); return result; @@ -640,7 +640,7 @@ Test::Result test_enc_dec_uncompressed_521() Botan::PointGFp p_G = group.OS2ECP(sv_G_secp_uncomp); - std::vector<uint8_t> sv_result = unlock(EC2OSP(p_G, Botan::PointGFp::UNCOMPRESSED)); + std::vector<uint8_t> sv_result = p_G.encode(Botan::PointGFp::UNCOMPRESSED); result.test_eq("expected", sv_result, sv_G_secp_uncomp); return result; @@ -654,7 +654,7 @@ Test::Result test_gfp_store_restore() Botan::EC_Group dom_pars("secp160r1"); Botan::PointGFp p = dom_pars.get_base_point(); - std::vector<uint8_t> sv_mes = unlock(EC2OSP(p, Botan::PointGFp::COMPRESSED)); + std::vector<uint8_t> sv_mes = p.encode(Botan::PointGFp::COMPRESSED); Botan::PointGFp new_p = dom_pars.OS2ECP(sv_mes); result.test_eq("original and restored points are same", p, new_p); |