monotone

monotone Mtn Source Tree

Root/cryptopp/pssr.h

1#ifndef CRYPTOPP_PSSR_H
2#define CRYPTOPP_PSSR_H
3
4#include "pubkey.h"
5#include <functional>
6
7NAMESPACE_BEGIN(CryptoPP)
8
9class PSSR_MEM_Base : public PK_RecoverableSignatureMessageEncodingMethod
10{
11virtual bool AllowRecovery() const =0;
12virtual unsigned int SaltLen(unsigned int hashLen) const =0;
13virtual unsigned int MinPadLen(unsigned int hashLen) const =0;
14virtual const MaskGeneratingFunction & GetMGF() const =0;
15
16public:
17unsigned int MaxRecoverableLength(unsigned int representativeBitLength, unsigned int hashIdentifierLength, unsigned int digestLength) const;
18bool IsProbabilistic() const;
19bool AllowNonrecoverablePart() const;
20bool RecoverablePartFirst() const;
21void ComputeMessageRepresentative(RandomNumberGenerator &rng,
22const byte *recoverableMessage, unsigned int recoverableMessageLength,
23HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
24byte *representative, unsigned int representativeBitLength) const;
25DecodingResult RecoverMessageFromRepresentative(
26HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
27byte *representative, unsigned int representativeBitLength,
28byte *recoverableMessage) const;
29};
30
31template <class H> struct EMSA2HashId
32{
33static const byte id;
34};
35
36// EMSA2HashId can be instantiated with the following two classes.
37class SHA;
38class RIPEMD160;
39
40template <class BASE>
41class EMSA2HashIdLookup : public BASE
42{
43public:
44struct HashIdentifierLookup
45{
46template <class H> struct HashIdentifierLookup2
47{
48static HashIdentifier Lookup()
49{
50return HashIdentifier(&EMSA2HashId<H>::id, 1);
51}
52};
53};
54};
55
56template <bool USE_HASH_ID> class PSSR_MEM_BaseWithHashId;
57template<> class PSSR_MEM_BaseWithHashId<true> : public EMSA2HashIdLookup<PSSR_MEM_Base> {};
58template<> class PSSR_MEM_BaseWithHashId<false> : public PSSR_MEM_Base {};
59
60template <bool ALLOW_RECOVERY, class MGF=P1363_MGF1, int SALT_LEN=-1, int MIN_PAD_LEN=0, bool USE_HASH_ID=false>
61class PSSR_MEM : public PSSR_MEM_BaseWithHashId<USE_HASH_ID>
62{
63virtual bool AllowRecovery() const {return ALLOW_RECOVERY;}
64virtual unsigned int SaltLen(unsigned int hashLen) const {return SALT_LEN < 0 ? hashLen : SALT_LEN;}
65virtual unsigned int MinPadLen(unsigned int hashLen) const {return MIN_PAD_LEN < 0 ? hashLen : MIN_PAD_LEN;}
66virtual const MaskGeneratingFunction & GetMGF() const {static MGF mgf; return mgf;}
67
68public:
69static std::string StaticAlgorithmName() {return std::string(ALLOW_RECOVERY ? "PSSR-" : "PSS-") + MGF::StaticAlgorithmName();}
70};
71
72//! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSSR-MGF1">PSSR-MGF1</a>
73struct PSSR : public SignatureStandard
74{
75typedef PSSR_MEM<true> SignatureMessageEncodingMethod;
76};
77
78//! <a href="http://www.weidai.com/scan-mirror/sig.html#sem_PSS-MGF1">PSS-MGF1</a>
79struct PSS : public SignatureStandard
80{
81typedef PSSR_MEM<false> SignatureMessageEncodingMethod;
82};
83
84NAMESPACE_END
85
86#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status