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.

hmac_sha512.cpp 900B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) 2014 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "crypto/hmac_sha512.h"
  5. #include <string.h>
  6. CHMAC_SHA512::CHMAC_SHA512(const unsigned char* key, size_t keylen)
  7. {
  8. unsigned char rkey[128];
  9. if (keylen <= 128) {
  10. memcpy(rkey, key, keylen);
  11. memset(rkey + keylen, 0, 128 - keylen);
  12. } else {
  13. CSHA512().Write(key, keylen).Finalize(rkey);
  14. memset(rkey + 64, 0, 64);
  15. }
  16. for (int n = 0; n < 128; n++)
  17. rkey[n] ^= 0x5c;
  18. outer.Write(rkey, 128);
  19. for (int n = 0; n < 128; n++)
  20. rkey[n] ^= 0x5c ^ 0x36;
  21. inner.Write(rkey, 128);
  22. }
  23. void CHMAC_SHA512::Finalize(unsigned char hash[OUTPUT_SIZE])
  24. {
  25. unsigned char temp[64];
  26. inner.Finalize(temp);
  27. outer.Write(temp, 64).Finalize(hash);
  28. }