00001
#ifndef CRYPTOPP_PSSR_H
00002
#define CRYPTOPP_PSSR_H
00003
00004
#include "pubkey.h"
00005
#include <functional>
00006
00007 NAMESPACE_BEGIN(CryptoPP)
00008
00009 class PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod
00010 {
00011
virtual bool AllowRecovery() const =0;
00012 virtual
unsigned int SaltLen(
unsigned int hashLen) const =0;
00013 virtual
unsigned int MinPadLen(
unsigned int hashLen) const =0;
00014 virtual const MaskGeneratingFunction & GetMGF() const =0;
00015
00016 public:
00017
unsigned int MaxRecoverableLength(
unsigned int representativeBitLength,
unsigned int hashIdentifierLength,
unsigned int digestLength) const;
00018
bool IsProbabilistic() const;
00019
bool AllowNonrecoverablePart() const;
00020
bool RecoverablePartFirst() const;
00021
void ComputeMessageRepresentative(
RandomNumberGenerator &rng,
00022 const byte *recoverableMessage,
unsigned int recoverableMessageLength,
00023
HashTransformation &hash, HashIdentifier hashIdentifier,
bool messageEmpty,
00024 byte *representative,
unsigned int representativeBitLength) const;
00025
DecodingResult RecoverMessageFromRepresentative(
00026
HashTransformation &hash, HashIdentifier hashIdentifier,
bool messageEmpty,
00027 byte *representative,
unsigned int representativeBitLength,
00028 byte *recoverableMessage) const;
00029 };
00030
00031 template <class H> struct EMSA2HashId
00032 {
00033
static const byte
id;
00034 };
00035
00036
00037
class SHA;
00038
class RIPEMD160;
00039
00040
template <
class BASE>
00041
class EMSA2HashIdLookup :
public BASE
00042 {
00043
public:
00044
struct HashIdentifierLookup
00045 {
00046
template <
class H>
struct HashIdentifierLookup2
00047 {
00048
static HashIdentifier Lookup()
00049 {
00050
return HashIdentifier(&EMSA2HashId<H>::
id, 1);
00051 }
00052 };
00053 };
00054 };
00055
00056
template <
bool USE_HASH_ID>
class PSSR_MEM_BaseWithHashId;
00057
template<>
class PSSR_MEM_BaseWithHashId<true> :
public EMSA2HashIdLookup<PSSR_MEM_Base> {};
00058
template<>
class PSSR_MEM_BaseWithHashId<false> :
public PSSR_MEM_Base {};
00059
00060
template <
bool ALLOW_RECOVERY,
class MGF=
P1363_MGF1,
int SALT_LEN=-1,
int MIN_PAD_LEN=0,
bool USE_HASH_ID=
false>
00061
class PSSR_MEM :
public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
00062 {
00063
virtual bool AllowRecovery()
const {
return ALLOW_RECOVERY;}
00064
virtual unsigned int SaltLen(
unsigned int hashLen)
const {
return SALT_LEN < 0 ? hashLen : SALT_LEN;}
00065
virtual unsigned int MinPadLen(
unsigned int hashLen)
const {
return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
00066
virtual const MaskGeneratingFunction & GetMGF()
const {
static MGF mgf;
return mgf;}
00067
00068
public:
00069
static std::string StaticAlgorithmName() {
return std::string(ALLOW_RECOVERY ?
"PSSR-" :
"PSS-") + MGF::StaticAlgorithmName();}
00070 };
00071
00072
00073 struct PSSR :
public SignatureStandard
00074 {
00075
typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
00076 };
00077
00078
00079 struct PSS :
public SignatureStandard
00080 {
00081
typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
00082 };
00083
00084 NAMESPACE_END
00085
00086
#endif