diff options
author | lloyd <[email protected]> | 2015-03-14 04:31:24 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-03-14 04:31:24 +0000 |
commit | ccfcb3af8b8404f998aba895ddfc7f3d4405fdd5 (patch) | |
tree | 9b4d1ba62249681622051a92758a3dc3c82bfd6d /src/lib/pk_pad | |
parent | d8ab5899e9f8c8d9987cec78fed34365b5ad0ee9 (diff) |
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
Diffstat (limited to 'src/lib/pk_pad')
-rw-r--r-- | src/lib/pk_pad/eme_raw/eme_raw.cpp | 34 | ||||
-rw-r--r-- | src/lib/pk_pad/eme_raw/eme_raw.h | 31 | ||||
-rw-r--r-- | src/lib/pk_pad/eme_raw/info.txt | 1 |
3 files changed, 66 insertions, 0 deletions
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 <botan/internal/pad_utils.h> +#include <botan/internal/bit_ops.h> +#include <botan/eme_raw.h> + +namespace Botan { + +BOTAN_REGISTER_EME_NAMED_NOARGS(EME_Raw, "Raw"); + +secure_vector<byte> 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<byte>(in, in + in_length); + } + +secure_vector<byte> EME_Raw::unpad(const byte in[], size_t in_length, + size_t) const + { + return secure_vector<byte>(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 <botan/eme.h> +#include <botan/kdf.h> +#include <botan/hash.h> + +namespace Botan { + +class BOTAN_DLL EME_Raw : public EME + { + public: + size_t maximum_input_size(size_t i) const; + + EME_Raw() {} + private: + secure_vector<byte> pad(const byte[], size_t, size_t, + RandomNumberGenerator&) const; + + secure_vector<byte> 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 |