From e89b6a365e56283a945aeda8ed2b427937fe5d91 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 29 Nov 2014 14:16:26 +0000 Subject: Move all PK workfactor esstimators to workfactors.* --- src/lib/pubkey/ecc_key/ecc_key.cpp | 3 ++- src/lib/pubkey/mce/mceliece_key.cpp | 9 +++++++-- src/lib/pubkey/mce/mceliece_key.h | 3 +-- src/lib/pubkey/workfactor.cpp | 10 ++++++++++ src/lib/pubkey/workfactor.h | 13 +++++++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index c9d4d62fe..7f82af4f5 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -14,12 +14,13 @@ #include #include #include +#include namespace Botan { size_t EC_PublicKey::estimated_strength() const { - return domain().get_curve().get_p().bits() / 2; + return ecp_work_factor(domain().get_curve().get_p().bits()); } EC_PublicKey::EC_PublicKey(const EC_Group& dom_par, diff --git a/src/lib/pubkey/mce/mceliece_key.cpp b/src/lib/pubkey/mce/mceliece_key.cpp index 71e0ec4e8..7da5aefed 100644 --- a/src/lib/pubkey/mce/mceliece_key.cpp +++ b/src/lib/pubkey/mce/mceliece_key.cpp @@ -14,10 +14,10 @@ #include #include #include -#include +#include #include #include -#include +#include namespace Botan { @@ -74,6 +74,11 @@ McEliece_PublicKey::McEliece_PublicKey(const McEliece_PublicKey & other) : { } +size_t McEliece_PublicKey::estimated_strength() const + { + return mceliece_work_factor(m_t, m_code_length); + } + McEliece_PublicKey::McEliece_PublicKey(const std::vector& key_bits) { BER_Decoder dec(key_bits); diff --git a/src/lib/pubkey/mce/mceliece_key.h b/src/lib/pubkey/mce/mceliece_key.h index c51745bba..1a9a699f4 100644 --- a/src/lib/pubkey/mce/mceliece_key.h +++ b/src/lib/pubkey/mce/mceliece_key.h @@ -15,7 +15,6 @@ #include #include #include -#include namespace Botan { @@ -47,7 +46,7 @@ class BOTAN_DLL McEliece_PublicKey : public virtual Public_Key AlgorithmIdentifier algorithm_identifier() const; - size_t estimated_strength() const { return 0; } + size_t estimated_strength() const; std::vector x509_subject_public_key() const; diff --git a/src/lib/pubkey/workfactor.cpp b/src/lib/pubkey/workfactor.cpp index b917ce52d..972d03af9 100644 --- a/src/lib/pubkey/workfactor.cpp +++ b/src/lib/pubkey/workfactor.cpp @@ -11,6 +11,16 @@ namespace Botan { +size_t mceliece_work_factor(size_t code_size, size_t t) + { + return 0; + } + +size_t ecp_work_factor(size_t bits) + { + return bits / 2; + } + size_t dl_work_factor(size_t bits) { /* diff --git a/src/lib/pubkey/workfactor.h b/src/lib/pubkey/workfactor.h index 179b580e7..37f487234 100644 --- a/src/lib/pubkey/workfactor.h +++ b/src/lib/pubkey/workfactor.h @@ -19,6 +19,19 @@ namespace Botan { */ size_t dl_work_factor(size_t prime_group_size); +/** +* Estimate work factor for EC discrete logarithm +* @param prime_group_size size of the group in bits +* @return estimated security level for this group +*/ +size_t ecp_work_factor(size_t prime_group_size); + +/** +* Estimate work factor for McEliece +* @return estimated security level for this group +*/ +size_t mceliece_work_factor(size_t code_size, size_t t); + } #endif -- cgit v1.2.3