LCOV - code coverage report
Current view: top level - src/crypto - hmac_sha512.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 21 21
Test Date: 2026-06-13 07:23:11 Functions: 100.0 % 2 2
Branches: 100.0 % 6 6

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2014-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <crypto/hmac_sha512.h>
       6                 :             : 
       7                 :             : #include <crypto/sha512.h>
       8                 :             : #include <support/cleanse.h>
       9                 :             : 
      10                 :             : #include <cstring>
      11                 :             : 
      12                 :      804502 : CHMAC_SHA512::CHMAC_SHA512(const unsigned char* key, size_t keylen)
      13                 :             : {
      14                 :      804502 :     unsigned char rkey[128];
      15         [ +  + ]:      804502 :     if (keylen <= 128) {
      16                 :      804499 :         memcpy(rkey, key, keylen);
      17                 :      804499 :         memset(rkey + keylen, 0, 128 - keylen);
      18                 :             :     } else {
      19                 :           3 :         CSHA512().Write(key, keylen).Finalize(rkey);
      20                 :           3 :         memset(rkey + 64, 0, 64);
      21                 :             :     }
      22                 :             : 
      23         [ +  + ]:   103780758 :     for (int n = 0; n < 128; n++)
      24                 :   102976256 :         rkey[n] ^= 0x5c;
      25                 :      804502 :     outer.Write(rkey, 128);
      26                 :             : 
      27         [ +  + ]:   103780758 :     for (int n = 0; n < 128; n++)
      28                 :   102976256 :         rkey[n] ^= 0x5c ^ 0x36;
      29                 :      804502 :     inner.Write(rkey, 128);
      30                 :             : 
      31                 :      804502 :     memory_cleanse(rkey, sizeof(rkey));
      32                 :      804502 : }
      33                 :             : 
      34                 :      807966 : void CHMAC_SHA512::Finalize(unsigned char hash[OUTPUT_SIZE])
      35                 :             : {
      36                 :      807966 :     unsigned char temp[64];
      37                 :      807966 :     inner.Finalize(temp);
      38                 :      807966 :     outer.Write(temp, 64).Finalize(hash);
      39                 :      807966 :     memory_cleanse(temp, sizeof(temp));
      40                 :      807966 : }
        

Generated by: LCOV version 2.0-1