aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/prov/openssl
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-08-09 14:05:29 -0400
committerJack Lloyd <[email protected]>2018-08-10 10:12:49 -0400
commit1e18edf2673519c8f8c01dbbaacc5a189f0c0a92 (patch)
tree40a7c64752842ce9298de220860af38fe80bb882 /src/lib/prov/openssl
parentfe242c20a01ae2e8a4589c353cdbc080ae629487 (diff)
Add PK_Signer::signature_length
Diffstat (limited to 'src/lib/prov/openssl')
-rw-r--r--src/lib/prov/openssl/openssl_ec.cpp14
-rw-r--r--src/lib/prov/openssl/openssl_rsa.cpp2
2 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/prov/openssl/openssl_ec.cpp b/src/lib/prov/openssl/openssl_ec.cpp
index b9e53b6fd..33f277d5a 100644
--- a/src/lib/prov/openssl/openssl_ec.cpp
+++ b/src/lib/prov/openssl/openssl_ec.cpp
@@ -229,8 +229,11 @@ class OpenSSL_ECDSA_Signing_Operation final : public PK_Ops::Signature_with_EMSA
const EC_GROUP* group = ::EC_KEY_get0_group(m_ossl_ec.get());
m_order_bits = ::EC_GROUP_get_degree(group);
+ m_order_bytes = (m_order_bits + 7) / 8;
}
+ size_t signature_length() const { return 2*m_order_bytes; }
+
secure_vector<uint8_t> raw_sign(const uint8_t msg[], size_t msg_len,
RandomNumberGenerator&) override
{
@@ -240,8 +243,6 @@ class OpenSSL_ECDSA_Signing_Operation final : public PK_Ops::Signature_with_EMSA
if(!sig)
throw OpenSSL_Error("ECDSA_do_sign");
- const size_t order_bytes = (m_order_bits + 7) / 8;
-
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
const BIGNUM* r = sig->r;
const BIGNUM* s = sig->s;
@@ -253,9 +254,9 @@ class OpenSSL_ECDSA_Signing_Operation final : public PK_Ops::Signature_with_EMSA
const size_t r_bytes = BN_num_bytes(r);
const size_t s_bytes = BN_num_bytes(s);
- secure_vector<uint8_t> sigval(2*order_bytes);
- BN_bn2bin(r, &sigval[order_bytes - r_bytes]);
- BN_bn2bin(s, &sigval[2*order_bytes - s_bytes]);
+ secure_vector<uint8_t> sigval(2*m_order_bytes);
+ BN_bn2bin(r, &sigval[m_order_bytes - r_bytes]);
+ BN_bn2bin(s, &sigval[2*m_order_bytes - s_bytes]);
return sigval;
}
@@ -263,7 +264,8 @@ class OpenSSL_ECDSA_Signing_Operation final : public PK_Ops::Signature_with_EMSA
private:
std::unique_ptr<EC_KEY, std::function<void (EC_KEY*)>> m_ossl_ec;
- size_t m_order_bits = 0;
+ size_t m_order_bits;
+ size_t m_order_bytes;
};
}
diff --git a/src/lib/prov/openssl/openssl_rsa.cpp b/src/lib/prov/openssl/openssl_rsa.cpp
index 6385bcbb3..cf9c2b52b 100644
--- a/src/lib/prov/openssl/openssl_rsa.cpp
+++ b/src/lib/prov/openssl/openssl_rsa.cpp
@@ -205,6 +205,8 @@ class OpenSSL_RSA_Signing_Operation final : public PK_Ops::Signature_with_EMSA
throw OpenSSL_Error("d2i_RSAPrivateKey");
}
+ size_t signature_length() const override { return ::RSA_size(m_openssl_rsa.get()); }
+
secure_vector<uint8_t> raw_sign(const uint8_t msg[], size_t msg_len,
RandomNumberGenerator&) override
{