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.

59 lines
1.5 KiB

  1. // eax.cpp - written and placed in the public domain by Wei Dai
  2. #include "pch.h"
  3. #include "eax.h"
  4. NAMESPACE_BEGIN(CryptoPP)
  5. void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params)
  6. {
  7. AccessMAC().SetKey(userKey, keylength, params);
  8. m_buffer.New(2*AccessMAC().TagSize());
  9. }
  10. void EAX_Base::Resync(const byte *iv, size_t len)
  11. {
  12. MessageAuthenticationCode &mac = AccessMAC();
  13. unsigned int blockSize = mac.TagSize();
  14. memset(m_buffer, 0, blockSize);
  15. mac.Update(m_buffer, blockSize);
  16. mac.CalculateDigest(m_buffer+blockSize, iv, len);
  17. m_buffer[blockSize-1] = 1;
  18. mac.Update(m_buffer, blockSize);
  19. m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
  20. }
  21. size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
  22. {
  23. AccessMAC().Update(data, len);
  24. return 0;
  25. }
  26. void EAX_Base::AuthenticateLastHeaderBlock()
  27. {
  28. assert(m_bufferedDataLength == 0);
  29. MessageAuthenticationCode &mac = AccessMAC();
  30. unsigned int blockSize = mac.TagSize();
  31. mac.Final(m_buffer);
  32. xorbuf(m_buffer+blockSize, m_buffer, blockSize);
  33. memset(m_buffer, 0, blockSize);
  34. m_buffer[blockSize-1] = 2;
  35. mac.Update(m_buffer, blockSize);
  36. }
  37. void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
  38. {
  39. assert(m_bufferedDataLength == 0);
  40. MessageAuthenticationCode &mac = AccessMAC();
  41. unsigned int blockSize = mac.TagSize();
  42. mac.TruncatedFinal(m_buffer, macSize);
  43. xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
  44. }
  45. NAMESPACE_END