您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hmac_sha256.cpp 893B

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_sha256.h"
  5. #include <string.h>
  6. CHMAC_SHA256::CHMAC_SHA256(const unsigned char* key, size_t keylen)
  7. {
  8. unsigned char rkey[64];
  9. if (keylen <= 64) {
  10. memcpy(rkey, key, keylen);
  11. memset(rkey + keylen, 0, 64 - keylen);
  12. } else {
  13. CSHA256().Write(key, keylen).Finalize(rkey);
  14. memset(rkey + 32, 0, 32);
  15. }
  16. for (int n = 0; n < 64; n++)
  17. rkey[n] ^= 0x5c;
  18. outer.Write(rkey, 64);
  19. for (int n = 0; n < 64; n++)
  20. rkey[n] ^= 0x5c ^ 0x36;
  21. inner.Write(rkey, 64);
  22. }
  23. void CHMAC_SHA256::Finalize(unsigned char hash[OUTPUT_SIZE])
  24. {
  25. unsigned char temp[32];
  26. inner.Finalize(temp);
  27. outer.Write(temp, 32).Finalize(hash);
  28. }