Advertisement
AnthonyCagliano

Untitled

Oct 24th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /*
  2. void hashlib_HMACSha256Init(hmac_ctx *hmac, const uint8_t* key, size_t keylen){
  3. size_t i;
  4. uint8_t sum[64] = {0};
  5. if(keylen > 64){
  6. hashlib_Sha256Init(&hmac->sha256_ctx);
  7. hashlib_Sha256Update(&hmac->sha256_ctx, key, keylen);
  8. hashlib_Sha256Final(&hmac->sha256_ctx, sum);
  9. keylen = 32;
  10. }
  11. else memcpy(sum, key, keylen);
  12. memset( hmac->ipad, 0x36, 64 );
  13. memset( hmac->opad, 0x5C, 64 );
  14. for( i = 0; i < 64; i++ ){
  15. hmac->ipad[i] ^= sum[i];
  16. hmac->opad[i] ^= sum[i];
  17. }
  18. hashlib_Sha256Init(&hmac->sha256_ctx);
  19. hashlib_Sha256Update(&hmac->sha256_ctx, hmac->ipad, 64);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement