aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-12-16 08:28:53 -0500
committerJack Lloyd <[email protected]>2020-12-16 08:28:53 -0500
commit7617345d2a208f9ab21df2e531588002b266272c (patch)
tree4cafd882fe1981f687d2af38e41441bf477efdb6 /src/lib/pubkey
parentf25fdfa30dad8a2bc5123906cd96323fd5453fe1 (diff)
parent457415bff9872e22052a8f5981163c19b1d8e81a (diff)
Merge GH #2551 Convert some enums to enum class
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/dh/dh.cpp2
-rw-r--r--src/lib/pubkey/dh/dh.h4
-rw-r--r--src/lib/pubkey/dl_algo/dl_algo.cpp4
-rw-r--r--src/lib/pubkey/dl_algo/dl_algo.h6
-rw-r--r--src/lib/pubkey/dl_group/dl_group.cpp48
-rw-r--r--src/lib/pubkey/dl_group/dl_group.h40
-rw-r--r--src/lib/pubkey/dsa/dsa.cpp2
-rw-r--r--src/lib/pubkey/dsa/dsa.h4
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp8
-rw-r--r--src/lib/pubkey/ec_group/ec_group.h12
-rw-r--r--src/lib/pubkey/ecc_key/ecc_key.cpp51
-rw-r--r--src/lib/pubkey/ecc_key/ecc_key.h2
-rw-r--r--src/lib/pubkey/elgamal/elgamal.cpp2
-rw-r--r--src/lib/pubkey/elgamal/elgamal.h4
14 files changed, 93 insertions, 96 deletions
diff --git a/src/lib/pubkey/dh/dh.cpp b/src/lib/pubkey/dh/dh.cpp
index 77ac19da4..98a05260e 100644
--- a/src/lib/pubkey/dh/dh.cpp
+++ b/src/lib/pubkey/dh/dh.cpp
@@ -58,7 +58,7 @@ DH_PrivateKey::DH_PrivateKey(RandomNumberGenerator& rng,
*/
DH_PrivateKey::DH_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits) :
- DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_42)
+ DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42)
{
if(m_y.is_zero())
{
diff --git a/src/lib/pubkey/dh/dh.h b/src/lib/pubkey/dh/dh.h
index bb6d5dae4..3b81bbf5d 100644
--- a/src/lib/pubkey/dh/dh.h
+++ b/src/lib/pubkey/dh/dh.h
@@ -22,7 +22,7 @@ class BOTAN_PUBLIC_API(2,0) DH_PublicKey : public virtual DL_Scheme_PublicKey
std::vector<uint8_t> public_value() const;
- DL_Group::Format group_format() const override { return DL_Group::ANSI_X9_42; }
+ DL_Group_Format group_format() const override { return DL_Group_Format::ANSI_X9_42; }
/**
* Create a public key.
@@ -31,7 +31,7 @@ class BOTAN_PUBLIC_API(2,0) DH_PublicKey : public virtual DL_Scheme_PublicKey
*/
DH_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits) :
- DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42) {}
+ DL_Scheme_PublicKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42) {}
/**
* Construct a public key with the specified parameters.
diff --git a/src/lib/pubkey/dl_algo/dl_algo.cpp b/src/lib/pubkey/dl_algo/dl_algo.cpp
index 15b0b175e..66efe7456 100644
--- a/src/lib/pubkey/dl_algo/dl_algo.cpp
+++ b/src/lib/pubkey/dl_algo/dl_algo.cpp
@@ -43,7 +43,7 @@ DL_Scheme_PublicKey::DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y)
DL_Scheme_PublicKey::DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits,
- DL_Group::Format format) :
+ DL_Group_Format format) :
m_group(alg_id.get_parameters(), format)
{
BER_Decoder(key_bits).decode(m_y);
@@ -56,7 +56,7 @@ secure_vector<uint8_t> DL_Scheme_PrivateKey::private_key_bits() const
DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits,
- DL_Group::Format format)
+ DL_Group_Format format)
{
m_group.BER_decode(alg_id.get_parameters(), format);
diff --git a/src/lib/pubkey/dl_algo/dl_algo.h b/src/lib/pubkey/dl_algo/dl_algo.h
index af01bc217..d3edd6bb2 100644
--- a/src/lib/pubkey/dl_algo/dl_algo.h
+++ b/src/lib/pubkey/dl_algo/dl_algo.h
@@ -64,7 +64,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PublicKey : public virtual Public_Key
* Get the underlying groups encoding format.
* @return encoding format
*/
- virtual DL_Group::Format group_format() const = 0;
+ virtual DL_Group_Format group_format() const = 0;
size_t key_length() const override;
size_t estimated_strength() const override;
@@ -82,7 +82,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PublicKey : public virtual Public_Key
*/
DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits,
- DL_Group::Format group_format);
+ DL_Group_Format group_format);
DL_Scheme_PublicKey(const DL_Group& group, const BigInt& y);
@@ -125,7 +125,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Scheme_PrivateKey : public virtual DL_Scheme_Publ
*/
DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits,
- DL_Group::Format group_format);
+ DL_Group_Format group_format);
DL_Scheme_PrivateKey() = default;
diff --git a/src/lib/pubkey/dl_group/dl_group.cpp b/src/lib/pubkey/dl_group/dl_group.cpp
index 7ff0a1958..05fe9dcf3 100644
--- a/src/lib/pubkey/dl_group/dl_group.cpp
+++ b/src/lib/pubkey/dl_group/dl_group.cpp
@@ -123,7 +123,7 @@ class DL_Group_Data final
//static
std::shared_ptr<DL_Group_Data> DL_Group::BER_decode_DL_group(const uint8_t data[], size_t data_len,
- DL_Group::Format format,
+ DL_Group_Format format,
DL_Group_Source source)
{
BigInt p, q, g;
@@ -131,21 +131,21 @@ std::shared_ptr<DL_Group_Data> DL_Group::BER_decode_DL_group(const uint8_t data[
BER_Decoder decoder(data, data_len);
BER_Decoder ber = decoder.start_cons(SEQUENCE);
- if(format == DL_Group::ANSI_X9_57)
+ if(format == DL_Group_Format::ANSI_X9_57)
{
ber.decode(p)
.decode(q)
.decode(g)
.verify_end();
}
- else if(format == DL_Group::ANSI_X9_42)
+ else if(format == DL_Group_Format::ANSI_X9_42)
{
ber.decode(p)
.decode(g)
.decode(q)
.discard_remaining();
}
- else if(format == DL_Group::PKCS_3)
+ else if(format == DL_Group_Format::PKCS_3)
{
// q is left as zero
ber.decode(p)
@@ -153,7 +153,7 @@ std::shared_ptr<DL_Group_Data> DL_Group::BER_decode_DL_group(const uint8_t data[
.discard_remaining();
}
else
- throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding");
return std::make_shared<DL_Group_Data>(p, q, g, source);
}
@@ -185,14 +185,14 @@ DL_Group::load_DL_group_info(const char* p_str,
namespace {
-DL_Group::Format pem_label_to_dl_format(const std::string& label)
+DL_Group_Format pem_label_to_dl_format(const std::string& label)
{
if(label == "DH PARAMETERS")
- return DL_Group::PKCS_3;
+ return DL_Group_Format::PKCS_3;
else if(label == "DSA PARAMETERS")
- return DL_Group::ANSI_X9_57;
+ return DL_Group_Format::ANSI_X9_57;
else if(label == "X942 DH PARAMETERS" || label == "X9.42 DH PARAMETERS")
- return DL_Group::ANSI_X9_42;
+ return DL_Group_Format::ANSI_X9_42;
else
throw Decoding_Error("DL_Group: Invalid PEM label " + label);
}
@@ -213,7 +213,7 @@ DL_Group::DL_Group(const std::string& str)
{
std::string label;
const std::vector<uint8_t> ber = unlock(PEM_Code::decode(str, label));
- Format format = pem_label_to_dl_format(label);
+ DL_Group_Format format = pem_label_to_dl_format(label);
m_data = BER_decode_DL_group(ber.data(), ber.size(), format, DL_Group_Source::ExternalSource);
}
@@ -589,15 +589,15 @@ DL_Group_Source DL_Group::source() const
/*
* DER encode the parameters
*/
-std::vector<uint8_t> DL_Group::DER_encode(Format format) const
+std::vector<uint8_t> DL_Group::DER_encode(DL_Group_Format format) const
{
- if(get_q().is_zero() && (format == ANSI_X9_57 || format == ANSI_X9_42))
+ if(get_q().is_zero() && (format != DL_Group_Format::PKCS_3))
throw Encoding_Error("Cannot encode DL_Group in ANSI formats when q param is missing");
std::vector<uint8_t> output;
DER_Encoder der(output);
- if(format == ANSI_X9_57)
+ if(format == DL_Group_Format::ANSI_X9_57)
{
der.start_cons(SEQUENCE)
.encode(get_p())
@@ -605,7 +605,7 @@ std::vector<uint8_t> DL_Group::DER_encode(Format format) const
.encode(get_g())
.end_cons();
}
- else if(format == ANSI_X9_42)
+ else if(format == DL_Group_Format::ANSI_X9_42)
{
der.start_cons(SEQUENCE)
.encode(get_p())
@@ -613,7 +613,7 @@ std::vector<uint8_t> DL_Group::DER_encode(Format format) const
.encode(get_q())
.end_cons();
}
- else if(format == PKCS_3)
+ else if(format == DL_Group_Format::PKCS_3)
{
der.start_cons(SEQUENCE)
.encode(get_p())
@@ -621,7 +621,7 @@ std::vector<uint8_t> DL_Group::DER_encode(Format format) const
.end_cons();
}
else
- throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding");
return output;
}
@@ -629,26 +629,26 @@ std::vector<uint8_t> DL_Group::DER_encode(Format format) const
/*
* PEM encode the parameters
*/
-std::string DL_Group::PEM_encode(Format format) const
+std::string DL_Group::PEM_encode(DL_Group_Format format) const
{
const std::vector<uint8_t> encoding = DER_encode(format);
- if(format == PKCS_3)
+ if(format == DL_Group_Format::PKCS_3)
return PEM_Code::encode(encoding, "DH PARAMETERS");
- else if(format == ANSI_X9_57)
+ else if(format == DL_Group_Format::ANSI_X9_57)
return PEM_Code::encode(encoding, "DSA PARAMETERS");
- else if(format == ANSI_X9_42)
+ else if(format == DL_Group_Format::ANSI_X9_42)
return PEM_Code::encode(encoding, "X9.42 DH PARAMETERS");
else
- throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
+ throw Invalid_Argument("Unknown DL_Group encoding");
}
-DL_Group::DL_Group(const uint8_t ber[], size_t ber_len, Format format)
+DL_Group::DL_Group(const uint8_t ber[], size_t ber_len, DL_Group_Format format)
{
m_data = BER_decode_DL_group(ber, ber_len, format, DL_Group_Source::ExternalSource);
}
-void DL_Group::BER_decode(const std::vector<uint8_t>& ber, Format format)
+void DL_Group::BER_decode(const std::vector<uint8_t>& ber, DL_Group_Format format)
{
m_data = BER_decode_DL_group(ber.data(), ber.size(), format, DL_Group_Source::ExternalSource);
}
@@ -658,7 +658,7 @@ DL_Group DL_Group::DL_Group_from_PEM(const std::string& pem)
{
std::string label;
const std::vector<uint8_t> ber = unlock(PEM_Code::decode(pem, label));
- Format format = pem_label_to_dl_format(label);
+ DL_Group_Format format = pem_label_to_dl_format(label);
return DL_Group(ber, format);
}
diff --git a/src/lib/pubkey/dl_group/dl_group.h b/src/lib/pubkey/dl_group/dl_group.h
index c3b9443b7..b9355da6f 100644
--- a/src/lib/pubkey/dl_group/dl_group.h
+++ b/src/lib/pubkey/dl_group/dl_group.h
@@ -22,6 +22,20 @@ enum class DL_Group_Source {
};
/**
+* The DL group encoding format variants.
+*/
+enum class DL_Group_Format {
+ ANSI_X9_42,
+ ANSI_X9_57,
+ PKCS_3,
+
+ DSA_PARAMETERS = ANSI_X9_57,
+ DH_PARAMETERS = ANSI_X9_42,
+ ANSI_X9_42_DH_PARAMETERS = ANSI_X9_42,
+ PKCS3_DH_PARAMETERS = PKCS_3
+};
+
+/**
* This class represents discrete logarithm groups. It holds a prime
* modulus p, a generator g, and (optionally) a prime q which is a
* factor of (p-1). In most cases g generates the order-q subgroup.
@@ -34,19 +48,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
*/
enum PrimeType { Strong, Prime_Subgroup, DSA_Kosherizer };
- /**
- * The DL group encoding format variants.
- */
- enum Format {
- ANSI_X9_42,
- ANSI_X9_57,
- PKCS_3,
-
- DSA_PARAMETERS = ANSI_X9_57,
- DH_PARAMETERS = ANSI_X9_42,
- ANSI_X9_42_DH_PARAMETERS = ANSI_X9_42,
- PKCS3_DH_PARAMETERS = PKCS_3
- };
+ using Format = DL_Group_Format;
/**
* Construct a DL group with uninitialized internal value.
@@ -115,13 +117,13 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
/**
* Decode a BER-encoded DL group param
*/
- DL_Group(const uint8_t ber[], size_t ber_len, Format format);
+ DL_Group(const uint8_t ber[], size_t ber_len, DL_Group_Format format);
/**
* Decode a BER-encoded DL group param
*/
template<typename Alloc>
- DL_Group(const std::vector<uint8_t, Alloc>& ber, Format format) :
+ DL_Group(const std::vector<uint8_t, Alloc>& ber, DL_Group_Format format) :
DL_Group(ber.data(), ber.size(), format) {}
/**
@@ -170,14 +172,14 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
* @param format the encoding format
* @return string holding the PEM encoded group
*/
- std::string PEM_encode(Format format) const;
+ std::string PEM_encode(DL_Group_Format format) const;
/**
* Encode this group into a string using DER encoding.
* @param format the encoding format
* @return string holding the DER encoded group
*/
- std::vector<uint8_t> DER_encode(Format format) const;
+ std::vector<uint8_t> DER_encode(DL_Group_Format format) const;
/**
* Reduce an integer modulo p
@@ -324,7 +326,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
*
* @warning avoid this. Instead use the DL_Group constructor
*/
- void BER_decode(const std::vector<uint8_t>& ber, Format format);
+ void BER_decode(const std::vector<uint8_t>& ber, DL_Group_Format format);
DL_Group_Source source() const;
@@ -343,7 +345,7 @@ class BOTAN_PUBLIC_API(2,0) DL_Group final
static std::shared_ptr<DL_Group_Data>
BER_decode_DL_group(const uint8_t data[], size_t data_len,
- DL_Group::Format format,
+ DL_Group_Format format,
DL_Group_Source source);
const DL_Group_Data& data() const;
diff --git a/src/lib/pubkey/dsa/dsa.cpp b/src/lib/pubkey/dsa/dsa.cpp
index c2c7e8194..103cb8115 100644
--- a/src/lib/pubkey/dsa/dsa.cpp
+++ b/src/lib/pubkey/dsa/dsa.cpp
@@ -48,7 +48,7 @@ DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng,
DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits) :
- DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
+ DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_57)
{
m_y = m_group.power_g_p(m_x, m_group.q_bits());
}
diff --git a/src/lib/pubkey/dsa/dsa.h b/src/lib/pubkey/dsa/dsa.h
index 1834737b5..75513a78d 100644
--- a/src/lib/pubkey/dsa/dsa.h
+++ b/src/lib/pubkey/dsa/dsa.h
@@ -20,7 +20,7 @@ class BOTAN_PUBLIC_API(2,0) DSA_PublicKey : public virtual DL_Scheme_PublicKey
public:
std::string algo_name() const override { return "DSA"; }
- DL_Group::Format group_format() const override { return DL_Group::ANSI_X9_57; }
+ DL_Group_Format group_format() const override { return DL_Group_Format::ANSI_X9_57; }
size_t message_parts() const override { return 2; }
size_t message_part_size() const override { return group_q().bytes(); }
@@ -31,7 +31,7 @@ class BOTAN_PUBLIC_API(2,0) DSA_PublicKey : public virtual DL_Scheme_PublicKey
*/
DSA_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits) :
- DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57)
+ DL_Scheme_PublicKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_57)
{
}
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index ab4a059fc..2e6739729 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -612,7 +612,7 @@ EC_Group::DER_encode(EC_Group_Encoding form) const
DER_Encoder der(output);
- if(form == EC_DOMPAR_ENC_EXPLICIT)
+ if(form == EC_Group_Encoding::Explicit)
{
const size_t ecpVers1 = 1;
const OID curve_type("1.2.840.10045.1.1"); // prime field
@@ -636,7 +636,7 @@ EC_Group::DER_encode(EC_Group_Encoding form) const
.encode(get_cofactor())
.end_cons();
}
- else if(form == EC_DOMPAR_ENC_OID)
+ else if(form == EC_Group_Encoding::NamedCurve)
{
const OID oid = get_curve_oid();
if(oid.empty())
@@ -645,7 +645,7 @@ EC_Group::DER_encode(EC_Group_Encoding form) const
}
der.encode(oid);
}
- else if(form == EC_DOMPAR_ENC_IMPLICITCA)
+ else if(form == EC_Group_Encoding::ImplicitCA)
{
der.encode_null();
}
@@ -659,7 +659,7 @@ EC_Group::DER_encode(EC_Group_Encoding form) const
std::string EC_Group::PEM_encode() const
{
- const std::vector<uint8_t> der = DER_encode(EC_DOMPAR_ENC_EXPLICIT);
+ const std::vector<uint8_t> der = DER_encode(EC_Group_Encoding::Explicit);
return PEM_Code::encode(der, "EC PARAMETERS");
}
diff --git a/src/lib/pubkey/ec_group/ec_group.h b/src/lib/pubkey/ec_group/ec_group.h
index 2a7876610..5f50edc9b 100644
--- a/src/lib/pubkey/ec_group/ec_group.h
+++ b/src/lib/pubkey/ec_group/ec_group.h
@@ -20,10 +20,14 @@ namespace Botan {
/**
* This class represents elliptic curce domain parameters
*/
-enum EC_Group_Encoding {
- EC_DOMPAR_ENC_EXPLICIT = 0,
- EC_DOMPAR_ENC_IMPLICITCA = 1,
- EC_DOMPAR_ENC_OID = 2
+enum class EC_Group_Encoding {
+ Explicit,
+ ImplicitCA,
+ NamedCurve,
+
+ EC_DOMPAR_ENC_EXPLICIT = Explicit,
+ EC_DOMPAR_ENC_IMPLICITCA = ImplicitCA,
+ EC_DOMPAR_ENC_OID = NamedCurve
};
enum class EC_Group_Source {
diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp
index 09748b847..90ffb260b 100644
--- a/src/lib/pubkey/ecc_key/ecc_key.cpp
+++ b/src/lib/pubkey/ecc_key/ecc_key.cpp
@@ -27,15 +27,24 @@ size_t EC_PublicKey::estimated_strength() const
return ecp_work_factor(key_length());
}
-EC_PublicKey::EC_PublicKey(const EC_Group& dom_par,
- const PointGFp& pub_point) :
- m_domain_params(dom_par), m_public_key(pub_point)
+namespace {
+
+EC_Group_Encoding default_encoding_for(EC_Group& group)
{
- if (!dom_par.get_curve_oid().empty())
- m_domain_encoding = EC_DOMPAR_ENC_OID;
+ if(group.get_curve_oid().empty())
+ return EC_Group_Encoding::Explicit;
else
- m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
+ return EC_Group_Encoding::NamedCurve;
+ }
+}
+
+EC_PublicKey::EC_PublicKey(const EC_Group& dom_par,
+ const PointGFp& pub_point) :
+ m_domain_params(dom_par),
+ m_public_key(pub_point),
+ m_domain_encoding(default_encoding_for(m_domain_params))
+ {
#if 0
if(domain().get_curve() != public_point().get_curve())
throw Invalid_Argument("EC_PublicKey: curve mismatch in constructor");
@@ -45,12 +54,9 @@ EC_PublicKey::EC_PublicKey(const EC_Group& dom_par,
EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits) :
m_domain_params{EC_Group(alg_id.get_parameters())},
- m_public_key{domain().OS2ECP(key_bits)}
+ m_public_key{domain().OS2ECP(key_bits)},
+ m_domain_encoding(default_encoding_for(m_domain_params))
{
- if (!domain().get_curve_oid().empty())
- m_domain_encoding = EC_DOMPAR_ENC_OID;
- else
- m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
}
bool EC_PublicKey::check_key(RandomNumberGenerator& rng,
@@ -83,15 +89,8 @@ void EC_PublicKey::set_point_encoding(PointGFp::Compression_Type enc)
void EC_PublicKey::set_parameter_encoding(EC_Group_Encoding form)
{
- if(form != EC_DOMPAR_ENC_EXPLICIT &&
- form != EC_DOMPAR_ENC_IMPLICITCA &&
- form != EC_DOMPAR_ENC_OID)
- throw Invalid_Argument("Invalid encoding form for EC-key object specified");
-
- if((form == EC_DOMPAR_ENC_OID) && (m_domain_params.get_curve_oid().empty()))
- throw Invalid_Argument("Invalid encoding form OID specified for "
- "EC-key object whose corresponding domain "
- "parameters are without oid");
+ if(form == EC_Group_Encoding::NamedCurve && m_domain_params.get_curve_oid().empty())
+ throw Invalid_Argument("Cannot used NamedCurve encoding for a curve without an OID");
m_domain_encoding = form;
}
@@ -113,10 +112,7 @@ EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng,
bool with_modular_inverse)
{
m_domain_params = ec_group;
- if (!ec_group.get_curve_oid().empty())
- m_domain_encoding = EC_DOMPAR_ENC_OID;
- else
- m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
+ m_domain_encoding = default_encoding_for(m_domain_params);
if(x == 0)
{
@@ -162,12 +158,7 @@ EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
bool with_modular_inverse)
{
m_domain_params = EC_Group(alg_id.get_parameters());
- m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
-
- if (!domain().get_curve_oid().empty())
- m_domain_encoding = EC_DOMPAR_ENC_OID;
- else
- m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
+ m_domain_encoding = default_encoding_for(m_domain_params);
OID key_parameters;
secure_vector<uint8_t> public_key_bits;
diff --git a/src/lib/pubkey/ecc_key/ecc_key.h b/src/lib/pubkey/ecc_key/ecc_key.h
index 629270890..9969700fb 100644
--- a/src/lib/pubkey/ecc_key/ecc_key.h
+++ b/src/lib/pubkey/ecc_key/ecc_key.h
@@ -108,7 +108,7 @@ class BOTAN_PUBLIC_API(2,0) EC_PublicKey : public virtual Public_Key
EC_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits);
- EC_PublicKey() : m_domain_params{}, m_public_key{}, m_domain_encoding(EC_DOMPAR_ENC_EXPLICIT)
+ EC_PublicKey() : m_domain_params{}, m_public_key{}, m_domain_encoding(EC_Group_Encoding::Explicit)
{}
EC_Group m_domain_params;
diff --git a/src/lib/pubkey/elgamal/elgamal.cpp b/src/lib/pubkey/elgamal/elgamal.cpp
index 73e091d0a..017f57073 100644
--- a/src/lib/pubkey/elgamal/elgamal.cpp
+++ b/src/lib/pubkey/elgamal/elgamal.cpp
@@ -45,7 +45,7 @@ ElGamal_PrivateKey::ElGamal_PrivateKey(RandomNumberGenerator& rng,
ElGamal_PrivateKey::ElGamal_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<uint8_t>& key_bits) :
- DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_42)
+ DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42)
{
m_y = m_group.power_g_p(m_x, m_group.p_bits());
}
diff --git a/src/lib/pubkey/elgamal/elgamal.h b/src/lib/pubkey/elgamal/elgamal.h
index 4147f5037..0c440df00 100644
--- a/src/lib/pubkey/elgamal/elgamal.h
+++ b/src/lib/pubkey/elgamal/elgamal.h
@@ -19,7 +19,7 @@ class BOTAN_PUBLIC_API(2,0) ElGamal_PublicKey : public virtual DL_Scheme_PublicK
{
public:
std::string algo_name() const override { return "ElGamal"; }
- DL_Group::Format group_format() const override { return DL_Group::ANSI_X9_42; }
+ DL_Group_Format group_format() const override { return DL_Group_Format::ANSI_X9_42; }
/**
* Load a public key.
@@ -28,7 +28,7 @@ class BOTAN_PUBLIC_API(2,0) ElGamal_PublicKey : public virtual DL_Scheme_PublicK
*/
ElGamal_PublicKey(const AlgorithmIdentifier& alg_id,
const std::vector<uint8_t>& key_bits) :
- DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42)
+ DL_Scheme_PublicKey(alg_id, key_bits, DL_Group_Format::ANSI_X9_42)
{}
/**