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
class RIPEMD128;
00040
class SHA256;
00041
class SHA384;
00042
class SHA512;
00043
class Whirlpool;
00044
00045
00046
template <
class BASE>
00047
class EMSA2HashIdLookup :
public BASE
00048 {
00049
public:
00050
struct HashIdentifierLookup
00051 {
00052
template <
class H>
struct HashIdentifierLookup2
00053 {
00054
static HashIdentifier Lookup()
00055 {
00056
return HashIdentifier(&EMSA2HashId<H>::
id, 1);
00057 }
00058 };
00059 };
00060 };
00061
00062
template <
bool USE_HASH_ID>
class PSSR_MEM_BaseWithHashId;
00063
template<>
class PSSR_MEM_BaseWithHashId<true> :
public EMSA2HashIdLookup<PSSR_MEM_Base> {};
00064
template<>
class PSSR_MEM_BaseWithHashId<false> :
public PSSR_MEM_Base {};
00065
00066
template <
bool ALLOW_RECOVERY,
class MGF=
P1363_MGF1,
int SALT_LEN=-1,
int MIN_PAD_LEN=0,
bool USE_HASH_ID=
false>
00067
class PSSR_MEM :
public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
00068 {
00069
virtual bool AllowRecovery()
const {
return ALLOW_RECOVERY;}
00070
virtual unsigned int SaltLen(
unsigned int hashLen)
const {
return SALT_LEN < 0 ? hashLen : SALT_LEN;}
00071
virtual unsigned int MinPadLen(
unsigned int hashLen)
const {
return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
00072
virtual const MaskGeneratingFunction & GetMGF()
const {
static MGF mgf;
return mgf;}
00073
00074
public:
00075
static std::string StaticAlgorithmName() {
return std::string(ALLOW_RECOVERY ?
"PSSR-" :
"PSS-") + MGF::StaticAlgorithmName();}
00076 };
00077
00078
00079 struct PSSR :
public SignatureStandard
00080 {
00081
typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
00082 };
00083
00084
00085 struct PSS :
public SignatureStandard
00086 {
00087
typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
00088 };
00089
00090 NAMESPACE_END
00091
00092
#endif