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.

62 lines
1.2 KiB

  1. #include "pch.h"
  2. #ifndef CRYPTOPP_IMPORTS
  3. #include "cbcmac.h"
  4. NAMESPACE_BEGIN(CryptoPP)
  5. void CBC_MAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params)
  6. {
  7. AccessCipher().SetKey(key, length, params);
  8. m_reg.CleanNew(AccessCipher().BlockSize());
  9. m_counter = 0;
  10. }
  11. void CBC_MAC_Base::Update(const byte *input, size_t length)
  12. {
  13. unsigned int blockSize = AccessCipher().BlockSize();
  14. while (m_counter && length)
  15. {
  16. m_reg[m_counter++] ^= *input++;
  17. if (m_counter == blockSize)
  18. ProcessBuf();
  19. length--;
  20. }
  21. if (length >= blockSize)
  22. {
  23. size_t leftOver = AccessCipher().AdvancedProcessBlocks(m_reg, input, m_reg, length, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
  24. input += (length - leftOver);
  25. length = leftOver;
  26. }
  27. while (length--)
  28. {
  29. m_reg[m_counter++] ^= *input++;
  30. if (m_counter == blockSize)
  31. ProcessBuf();
  32. }
  33. }
  34. void CBC_MAC_Base::TruncatedFinal(byte *mac, size_t size)
  35. {
  36. ThrowIfInvalidTruncatedSize(size);
  37. if (m_counter)
  38. ProcessBuf();
  39. memcpy(mac, m_reg, size);
  40. memset(m_reg, 0, AccessCipher().BlockSize());
  41. }
  42. void CBC_MAC_Base::ProcessBuf()
  43. {
  44. AccessCipher().ProcessBlock(m_reg);
  45. m_counter = 0;
  46. }
  47. NAMESPACE_END
  48. #endif