From afd97edf49c9381e434f5f786c59f743a246101b Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 8 Oct 2008 19:40:02 +0000 Subject: Add BSI variant of EMSA1, from InSiTo --- doc/log.txt | 1 + src/core/libstate/get_enc.cpp | 12 ++++++++++++ src/pk_pad/emsa1/emsa1.h | 2 ++ src/pk_pad/emsa1_bsi/emsa1_bsi.cpp | 27 +++++++++++++++++++++++++++ src/pk_pad/emsa1_bsi/emsa1_bsi.h | 30 ++++++++++++++++++++++++++++++ src/pk_pad/emsa1_bsi/info.txt | 14 ++++++++++++++ src/pubkey/ec_dompar/ec_dompar.cpp | 2 +- 7 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/pk_pad/emsa1_bsi/emsa1_bsi.cpp create mode 100644 src/pk_pad/emsa1_bsi/emsa1_bsi.h create mode 100644 src/pk_pad/emsa1_bsi/info.txt diff --git a/doc/log.txt b/doc/log.txt index 235fa429e..d76b75b80 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -2,6 +2,7 @@ * 1.7.16, ????-??-?? - Add several missing pieces needed for ECDSA and ECKAEG - Add SHA-224 from InSiTo + - Add BSI variant of EMSA1 from InSiTo - Split ECDSA and ECKAEG into distinct modules - Allow OpenSSL and GNU MP engines to be built with some PK algos disabled - Add GF(p) and ECDSA tests from InSiTo diff --git a/src/core/libstate/get_enc.cpp b/src/core/libstate/get_enc.cpp index 2459ef0a6..e42ab784e 100644 --- a/src/core/libstate/get_enc.cpp +++ b/src/core/libstate/get_enc.cpp @@ -16,6 +16,10 @@ #include #endif +#if defined(BOTAN_HAS_EMSA1_BSI) + #include +#endif + #if defined(BOTAN_HAS_EMSA2) #include #endif @@ -86,6 +90,14 @@ EMSA* get_emsa(const std::string& algo_spec) } #endif +#if defined(BOTAN_HAS_EMSA1_BSI) + if(emsa_name == "EMSA1_BSI") + { + if(name.size() == 2) + return new EMSA1_BSI(get_hash(name[1])); + } +#endif + #if defined(BOTAN_HAS_EMSA2) if(emsa_name == "EMSA2") { diff --git a/src/pk_pad/emsa1/emsa1.h b/src/pk_pad/emsa1/emsa1.h index 2de2d325e..8a15e2bfe 100644 --- a/src/pk_pad/emsa1/emsa1.h +++ b/src/pk_pad/emsa1/emsa1.h @@ -18,6 +18,8 @@ class BOTAN_DLL EMSA1 : public EMSA public: EMSA1(HashFunction* h) : hash(h) {} ~EMSA1() { delete hash; } + protected: + const HashFunction* hash_ptr() const { return hash; } private: void update(const byte[], u32bit); SecureVector raw_data(); diff --git a/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp b/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp new file mode 100644 index 000000000..cc7868a1d --- /dev/null +++ b/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp @@ -0,0 +1,27 @@ +/************************************************* +* EMSA1 BSI Source File * +* (C) 1999-2008 Jack Lloyd * +* 2008 Falko Strenzke, FlexSecure GmbH * +*************************************************/ + +#include + +namespace Botan { + +/************************************************* +* EMSA1 BSI Encode Operation * +*************************************************/ +SecureVector EMSA1_BSI::encoding_of(const MemoryRegion& msg, + u32bit output_bits, + RandomNumberGenerator&) + { + if(msg.size() != hash_ptr()->OUTPUT_LENGTH) + throw Encoding_Error("EMSA1_BSI::encoding_of: Invalid size for input"); + + if(8*msg.size() <= output_bits) + return msg; + + throw Encoding_Error("EMSA1_BSI::encoding_of: max key input size exceeded"); + } + +} diff --git a/src/pk_pad/emsa1_bsi/emsa1_bsi.h b/src/pk_pad/emsa1_bsi/emsa1_bsi.h new file mode 100644 index 000000000..0c0745bb0 --- /dev/null +++ b/src/pk_pad/emsa1_bsi/emsa1_bsi.h @@ -0,0 +1,30 @@ +/************************************************* +* EMSA1 BSI Variant Header File * +* (C) 1999-2008 Jack Lloyd * +* 2007 FlexSecure GmbH * +*************************************************/ + +#ifndef BOTAN_EMSA1_BSI_H__ +#define BOTAN_EMSA1_BSI_H__ + +#include + +namespace Botan { + +/** +EMSA1_BSI is a variant of EMSA1 specified by the BSI. It accepts only +hash values which are less or equal than the maximum key length. The +implementation comes from InSiTo +*/ +class BOTAN_DLL EMSA1_BSI : public EMSA1 + { + public: + EMSA1_BSI(HashFunction* hash) : EMSA1(hash) {} + private: + SecureVector encoding_of(const MemoryRegion&, u32bit, + RandomNumberGenerator& rng); + }; + +} + +#endif diff --git a/src/pk_pad/emsa1_bsi/info.txt b/src/pk_pad/emsa1_bsi/info.txt new file mode 100644 index 000000000..8a8c46abb --- /dev/null +++ b/src/pk_pad/emsa1_bsi/info.txt @@ -0,0 +1,14 @@ +realname "EMSA1 (BSI variant)" + +define EMSA1_BSI + +load_on auto + + +emsa1 + + + +emsa1_bsi.h +emsa1_bsi.cpp + diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp index 97f71a6b3..09be588ae 100644 --- a/src/pubkey/ec_dompar/ec_dompar.cpp +++ b/src/pubkey/ec_dompar/ec_dompar.cpp @@ -20,7 +20,7 @@ std::vector get_standard_domain_parameter(const std::string& oid) Version 0.3; section 2.1.2 */ - if(oid == "1.3.132.8") // InSiTo had '08' + if(oid == "1.3.132.0.8") { std::vector dom_par; dom_par.push_back("0xffffffffffffffffffffffffffffffff7fffffff"); //p -- cgit v1.2.3