Fabcoin Core  0.16.2
P2P Digital Currency
emsa2.cpp
Go to the documentation of this file.
1 // emsa2.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 #include "emsa2.h"
5 
6 #ifndef CRYPTOPP_IMPORTS
7 
9 
10 void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator& /*rng*/,
11  const byte* recoverableMessage, size_t recoverableMessageLength,
12  HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
13  byte *representative, size_t representativeBitLength) const
14 {
15  CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength), CRYPTOPP_UNUSED(representativeBitLength);
16  CRYPTOPP_ASSERT(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
17 
18  if (representativeBitLength % 8 != 7)
19  throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");
20 
21  size_t digestSize = hash.DigestSize();
22  size_t representativeByteLength = BitsToBytes(representativeBitLength);
23 
24  representative[0] = messageEmpty ? 0x4b : 0x6b;
25  memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb
26  byte *afterP2 = representative+representativeByteLength-digestSize-3;
27  afterP2[0] = 0xba;
28  hash.Final(afterP2+1);
29  representative[representativeByteLength-2] = *hashIdentifier.first;
30  representative[representativeByteLength-1] = 0xcc;
31 }
32 
34 
35 #endif
uint8_t byte
Definition: Common.h:57
Classes and functions for various padding schemes used in public key algorithms.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
Definition: misc.h:749
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
Interface for random number generators.
Definition: cryptlib.h:1188
_
Definition: emsa2.h:61
Exception throw when the private or public key has a length that can't be used.
Definition: cryptlib.h:2438
#define CRYPTOPP_ASSERT(exp)
Definition: trap.h:92
#define CRYPTOPP_UNUSED(x)
Definition: config.h:741
Interface for hash functions and data processing part of MACs.
Definition: cryptlib.h:930
#define NAMESPACE_END
Definition: config.h:201
std::pair< const byte *, unsigned int > HashIdentifier
Definition: pubkey.h:314