Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

  1. // emsa2.cpp - written and placed in the public domain by Wei Dai
  2. #include "pch.h"
  3. #include "emsa2.h"
  4. #ifndef CRYPTOPP_IMPORTS
  5. NAMESPACE_BEGIN(CryptoPP)
  6. void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator& /*rng*/,
  7. const byte* recoverableMessage, size_t recoverableMessageLength,
  8. HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty,
  9. byte *representative, size_t representativeBitLength) const
  10. {
  11. CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength), CRYPTOPP_UNUSED(representativeBitLength);
  12. assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
  13. if (representativeBitLength % 8 != 7)
  14. throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");
  15. size_t digestSize = hash.DigestSize();
  16. size_t representativeByteLength = BitsToBytes(representativeBitLength);
  17. representative[0] = messageEmpty ? 0x4b : 0x6b;
  18. memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb
  19. byte *afterP2 = representative+representativeByteLength-digestSize-3;
  20. afterP2[0] = 0xba;
  21. hash.Final(afterP2+1);
  22. representative[representativeByteLength-2] = *hashIdentifier.first;
  23. representative[representativeByteLength-1] = 0xcc;
  24. }
  25. NAMESPACE_END
  26. #endif