aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/prov
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
parentfe242c20a01ae2e8a4589c353cdbc080ae629487 (diff)
Add PK_Signer::signature_length
Diffstat (limited to 'src/lib/prov')
-rw-r--r--src/lib/prov/bearssl/bearssl_ec.cpp8
-rw-r--r--src/lib/prov/openssl/openssl_ec.cpp14
-rw-r--r--src/lib/prov/openssl/openssl_rsa.cpp2
-rw-r--r--src/lib/prov/pkcs11/p11_ecdsa.cpp2
-rw-r--r--src/lib/prov/pkcs11/p11_rsa.cpp2
-rw-r--r--src/lib/prov/tpm/tpm.cpp5
-rw-r--r--src/lib/prov/tpm/tpm.h7
7 files changed, 29 insertions, 11 deletions
diff --git a/src/lib/prov/bearssl/bearssl_ec.cpp b/src/lib/prov/bearssl/bearssl_ec.cpp
index 23f566043..89f7773aa 100644
--- a/src/lib/prov/bearssl/bearssl_ec.cpp
+++ b/src/lib/prov/bearssl/bearssl_ec.cpp
@@ -77,7 +77,7 @@ class BearSSL_ECDSA_Verification_Operation final : public PK_Ops::Verification
{
public:
BearSSL_ECDSA_Verification_Operation(const ECDSA_PublicKey& ecdsa, const std::string& emsa) :
- m_order_bits(ecdsa.domain().get_order().bits())
+ m_order_bits(ecdsa.domain().get_order_bits())
{
const int curve = BearSSL_EC_curve_for(ecdsa.domain().get_oid());
if (curve < 0)
@@ -132,7 +132,8 @@ class BearSSL_ECDSA_Signing_Operation final : public PK_Ops::Signature
{
public:
BearSSL_ECDSA_Signing_Operation(const ECDSA_PrivateKey& ecdsa, const std::string& emsa) :
- m_order_bits(ecdsa.domain().get_order().bits())
+ m_order_bits(ecdsa.domain().get_order_bits()),
+ m_order_bytes(ecdsa.domain().get_order_bytes())
{
const int curve = BearSSL_EC_curve_for(ecdsa.domain().get_oid());
if(curve < 0)
@@ -175,12 +176,15 @@ class BearSSL_ECDSA_Signing_Operation final : public PK_Ops::Signature
size_t max_input_bits() const { return m_order_bits; }
+ size_t signature_length() const override { return 2*m_order_bytes; }
+
private:
br_ec_private_key m_key;
std::unique_ptr<HashFunction> m_hf;
secure_vector<uint8_t> m_x_buf;
const br_hash_class *m_hash;
size_t m_order_bits;
+ size_t m_order_bytes;
};
}
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
{
diff --git a/src/lib/prov/pkcs11/p11_ecdsa.cpp b/src/lib/prov/pkcs11/p11_ecdsa.cpp
index a93e761b1..bdea2c1fa 100644
--- a/src/lib/prov/pkcs11/p11_ecdsa.cpp
+++ b/src/lib/prov/pkcs11/p11_ecdsa.cpp
@@ -100,6 +100,8 @@ class PKCS11_ECDSA_Signature_Operation final : public PK_Ops::Signature
return signature;
}
+ size_t signature_length() const override { return 2*m_order.bytes(); }
+
private:
const PKCS11_EC_PrivateKey& m_key;
const BigInt& m_order;
diff --git a/src/lib/prov/pkcs11/p11_rsa.cpp b/src/lib/prov/pkcs11/p11_rsa.cpp
index e62c038ec..65bcd2d22 100644
--- a/src/lib/prov/pkcs11/p11_rsa.cpp
+++ b/src/lib/prov/pkcs11/p11_rsa.cpp
@@ -206,6 +206,8 @@ class PKCS11_RSA_Signature_Operation final : public PK_Ops::Signature
: m_key(key), m_mechanism(MechanismWrapper::create_rsa_sign_mechanism(padding))
{}
+ size_t signature_length() const override { return m_key.get_n().bytes(); }
+
void update(const uint8_t msg[], size_t msg_len) override
{
if(!m_initialized)
diff --git a/src/lib/prov/tpm/tpm.cpp b/src/lib/prov/tpm/tpm.cpp
index ccc6e9958..4847b0df6 100644
--- a/src/lib/prov/tpm/tpm.cpp
+++ b/src/lib/prov/tpm/tpm.cpp
@@ -394,6 +394,11 @@ class TPM_Signing_Operation final : public PK_Ops::Signature
{
}
+ size_t signature_length() const override
+ {
+ return m_key.get_n().bytes();
+ }
+
void update(const uint8_t msg[], size_t msg_len) override
{
m_hash->update(msg, msg_len);
diff --git a/src/lib/prov/tpm/tpm.h b/src/lib/prov/tpm/tpm.h
index bb215a476..b6e220935 100644
--- a/src/lib/prov/tpm/tpm.h
+++ b/src/lib/prov/tpm/tpm.h
@@ -159,6 +159,10 @@ class BOTAN_PUBLIC_API(2,0) TPM_PrivateKey final : public Private_Key
bool check_key(RandomNumberGenerator& rng, bool) const override;
+ BigInt get_n() const;
+
+ BigInt get_e() const;
+
std::string algo_name() const override { return "RSA"; } // ???
std::unique_ptr<PK_Ops::Signature>
@@ -167,9 +171,6 @@ class BOTAN_PUBLIC_API(2,0) TPM_PrivateKey final : public Private_Key
const std::string& provider) const override;
private:
- BigInt get_n() const;
- BigInt get_e() const;
-
TPM_Context& m_ctx;
TSS_HKEY m_key;