Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:05

0001 // oaep.h - originally written and placed in the public domain by Wei Dai

0002 
0003 /// \file oaep.h

0004 /// \brief Classes for optimal asymmetric encryption padding

0005 /// \since Crypto++ 2.1

0006 
0007 #ifndef CRYPTOPP_OAEP_H
0008 #define CRYPTOPP_OAEP_H
0009 
0010 #include "cryptlib.h"
0011 #include "pubkey.h"
0012 #include "sha.h"
0013 
0014 NAMESPACE_BEGIN(CryptoPP)
0015 
0016 /// \brief OAEP padding base class

0017 /// \since Crypto++ 2.1

0018 class CRYPTOPP_DLL OAEP_Base : public PK_EncryptionMessageEncodingMethod
0019 {
0020 public:
0021     bool ParameterSupported(const char *name) const {return strcmp(name, Name::EncodingParameters()) == 0;}
0022     size_t MaxUnpaddedLength(size_t paddedLength) const;
0023     void Pad(RandomNumberGenerator &rng, const byte *raw, size_t inputLength, byte *padded, size_t paddedLength, const NameValuePairs &parameters) const;
0024     DecodingResult Unpad(const byte *padded, size_t paddedLength, byte *raw, const NameValuePairs &parameters) const;
0025 
0026 protected:
0027     virtual unsigned int DigestSize() const =0;
0028     virtual HashTransformation * NewHash() const =0;
0029     virtual MaskGeneratingFunction * NewMGF() const =0;
0030 };
0031 
0032 /// \brief OAEP padding

0033 /// \tparam H HashTransformation derived class

0034 /// \tparam MGF MaskGeneratingFunction derived class

0035 /// \sa <a href="http://www.weidai.com/scan-mirror/ca.html#cem_OAEP-MGF1">EME-OAEP</a>, for use with classes derived from TF_ES

0036 /// \since Crypto++ 2.1

0037 template <class H, class MGF=P1363_MGF1>
0038 class OAEP : public OAEP_Base, public EncryptionStandard
0039 {
0040 public:
0041     static std::string CRYPTOPP_API StaticAlgorithmName() {return std::string("OAEP-") + MGF::StaticAlgorithmName() + "(" + H::StaticAlgorithmName() + ")";}
0042     typedef OAEP<H, MGF> EncryptionMessageEncodingMethod;
0043 
0044 protected:
0045     unsigned int DigestSize() const {return H::DIGESTSIZE;}
0046     HashTransformation * NewHash() const {return new H;}
0047     MaskGeneratingFunction * NewMGF() const {return new MGF;}
0048 };
0049 
0050 CRYPTOPP_DLL_TEMPLATE_CLASS OAEP<SHA1>;
0051 
0052 NAMESPACE_END
0053 
0054 #endif