diff options
author | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-10 03:41:59 +0000 |
commit | 6894dca64c04936d07048c0e8cbf7e25858548c3 (patch) | |
tree | 5d572bfde9fe667dab14e3f04b5285a85d8acd95 /src/lib/pk_pad/eme_pkcs | |
parent | 9efa3be92442afb3d0b69890a36c7f122df18eda (diff) |
Move lib into src
Diffstat (limited to 'src/lib/pk_pad/eme_pkcs')
-rw-r--r-- | src/lib/pk_pad/eme_pkcs/eme_pkcs.cpp | 70 | ||||
-rw-r--r-- | src/lib/pk_pad/eme_pkcs/eme_pkcs.h | 30 | ||||
-rw-r--r-- | src/lib/pk_pad/eme_pkcs/info.txt | 1 |
3 files changed, 101 insertions, 0 deletions
diff --git a/src/lib/pk_pad/eme_pkcs/eme_pkcs.cpp b/src/lib/pk_pad/eme_pkcs/eme_pkcs.cpp new file mode 100644 index 000000000..0e7d1fc30 --- /dev/null +++ b/src/lib/pk_pad/eme_pkcs/eme_pkcs.cpp @@ -0,0 +1,70 @@ +/* +* PKCS1 EME +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/eme_pkcs.h> + +namespace Botan { + +/* +* PKCS1 Pad Operation +*/ +secure_vector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen, + size_t olen, + RandomNumberGenerator& rng) const + { + olen /= 8; + + if(olen < 10) + throw Encoding_Error("PKCS1: Output space too small"); + if(inlen > olen - 10) + throw Encoding_Error("PKCS1: Input is too large"); + + secure_vector<byte> out(olen); + + out[0] = 0x02; + for(size_t j = 1; j != olen - inlen - 1; ++j) + while(out[j] == 0) + out[j] = rng.next_byte(); + buffer_insert(out, olen - inlen, in, inlen); + + return out; + } + +/* +* PKCS1 Unpad Operation +*/ +secure_vector<byte> EME_PKCS1v15::unpad(const byte in[], size_t inlen, + size_t key_len) const + { + if(inlen != key_len / 8 || inlen < 10 || in[0] != 0x02) + throw Decoding_Error("PKCS1::unpad"); + + size_t seperator = 0; + for(size_t j = 0; j != inlen; ++j) + if(in[j] == 0) + { + seperator = j; + break; + } + if(seperator < 9) + throw Decoding_Error("PKCS1::unpad"); + + return secure_vector<byte>(&in[seperator + 1], &in[inlen]); + } + +/* +* Return the max input size for a given key size +*/ +size_t EME_PKCS1v15::maximum_input_size(size_t keybits) const + { + if(keybits / 8 > 10) + return ((keybits / 8) - 10); + else + return 0; + } + +} diff --git a/src/lib/pk_pad/eme_pkcs/eme_pkcs.h b/src/lib/pk_pad/eme_pkcs/eme_pkcs.h new file mode 100644 index 000000000..2808e18d6 --- /dev/null +++ b/src/lib/pk_pad/eme_pkcs/eme_pkcs.h @@ -0,0 +1,30 @@ +/* +* EME PKCS#1 v1.5 +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_EME_PKCS1_H__ +#define BOTAN_EME_PKCS1_H__ + +#include <botan/eme.h> + +namespace Botan { + +/** +* EME from PKCS #1 v1.5 +*/ +class BOTAN_DLL EME_PKCS1v15 : public EME + { + public: + size_t maximum_input_size(size_t) const; + 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_pkcs/info.txt b/src/lib/pk_pad/eme_pkcs/info.txt new file mode 100644 index 000000000..432aaf8eb --- /dev/null +++ b/src/lib/pk_pad/eme_pkcs/info.txt @@ -0,0 +1 @@ +define EME_PKCS1v15 20131128 |