Counter Strike : Global Offensive Source Code
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.

34 lines
1.2 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. assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize()));
  12. if (representativeBitLength % 8 != 7)
  13. throw PK_SignatureScheme::InvalidKeyLength("EMSA2: EMSA2 requires a key length that is a multiple of 8");
  14. size_t digestSize = hash.DigestSize();
  15. size_t representativeByteLength = BitsToBytes(representativeBitLength);
  16. representative[0] = messageEmpty ? 0x4b : 0x6b;
  17. memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb
  18. byte *afterP2 = representative+representativeByteLength-digestSize-3;
  19. afterP2[0] = 0xba;
  20. hash.Final(afterP2+1);
  21. representative[representativeByteLength-2] = *hashIdentifier.first;
  22. representative[representativeByteLength-1] = 0xcc;
  23. }
  24. NAMESPACE_END
  25. #endif