From ccfcb3af8b8404f998aba895ddfc7f3d4405fdd5 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 14 Mar 2015 04:31:24 +0000 Subject: In PK encrypt/decrypt move pad calls to the operation. This allows an op to use a padding scheme outside of our knowledge or control, for instance an OpenSSL RSA op which uses OpenSSL's padding code. Similar change for key agreement and KDFs for the same reason. Add an EME_Raw type; previously this operation was implicit in the code in pubkey.cpp --- src/lib/pk_pad/eme_raw/eme_raw.cpp | 34 ++++++++++++++++++++++++++++++++++ src/lib/pk_pad/eme_raw/eme_raw.h | 31 +++++++++++++++++++++++++++++++ src/lib/pk_pad/eme_raw/info.txt | 1 + 3 files changed, 66 insertions(+) create mode 100644 src/lib/pk_pad/eme_raw/eme_raw.cpp create mode 100644 src/lib/pk_pad/eme_raw/eme_raw.h create mode 100644 src/lib/pk_pad/eme_raw/info.txt (limited to 'src/lib/pk_pad/eme_raw') diff --git a/src/lib/pk_pad/eme_raw/eme_raw.cpp b/src/lib/pk_pad/eme_raw/eme_raw.cpp new file mode 100644 index 000000000..9ae894c70 --- /dev/null +++ b/src/lib/pk_pad/eme_raw/eme_raw.cpp @@ -0,0 +1,34 @@ +/* +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include +#include +#include + +namespace Botan { + +BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw"); + +secure_vector EME_Raw::pad(const byte in[], size_t in_length, + size_t key_bits, + RandomNumberGenerator&) const + { + if(in_length > 0 && (8*(in_length - 1) + high_bit(in[0]) > key_bits)) + throw Invalid_Argument("EME_Raw: Input is too large"); + return secure_vector(in, in + in_length); + } + +secure_vector EME_Raw::unpad(const byte in[], size_t in_length, + size_t) const + { + return secure_vector(in, in + in_length); + } + +size_t EME_Raw::maximum_input_size(size_t keybits) const + { + return keybits / 8; + } +} diff --git a/src/lib/pk_pad/eme_raw/eme_raw.h b/src/lib/pk_pad/eme_raw/eme_raw.h new file mode 100644 index 000000000..903d9fc34 --- /dev/null +++ b/src/lib/pk_pad/eme_raw/eme_raw.h @@ -0,0 +1,31 @@ +/* +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_EME_RAW_H__ +#define BOTAN_EME_RAW_H__ + +#include +#include +#include + +namespace Botan { + +class BOTAN_DLL EME_Raw : public EME + { + public: + size_t maximum_input_size(size_t i) const; + + EME_Raw() {} + private: + secure_vector pad(const byte[], size_t, size_t, + RandomNumberGenerator&) const; + + secure_vector unpad(const byte[], size_t, size_t) const; + }; + +} + +#endif diff --git a/src/lib/pk_pad/eme_raw/info.txt b/src/lib/pk_pad/eme_raw/info.txt new file mode 100644 index 000000000..4c94824cf --- /dev/null +++ b/src/lib/pk_pad/eme_raw/info.txt @@ -0,0 +1 @@ +define EME_RAW 20150313 -- cgit v1.2.3