Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhmac/ossfuzz/sha224_calculate_hmac_fuzzer.cc
Line
Count
Source
1
/*
2
 * OSS-Fuzz target for libhmac SHA-224 calculate HMAC
3
 *
4
 * The fuzzer input consists of:
5
 * [ 0, 3 ]  32-bit little-endian key size, clamped to the amount of remaining data
6
 * [ 4, 4 + key_size - 1 ]  optional key
7
 * [ 4 + key_size, ... ]  message
8
 * If the input is smaller than 4 bytes the key size is 0
9
 *
10
 * Copyright (C) 2011-2026, Joachim Metz <joachim.metz@gmail.com>
11
 *
12
 * Refer to AUTHORS for acknowledgements.
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Lesser General Public License as published by
16
 * the Free Software Foundation, either version 3 of the License, or
17
 * (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public License
25
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
26
 */
27
28
#include <stddef.h>
29
#include <stdint.h>
30
31
/* Note that some of the OSS-Fuzz engines use C++
32
 */
33
extern "C" {
34
35
#include "ossfuzz_libhmac.h"
36
37
int LLVMFuzzerTestOneInput(
38
     const uint8_t *data,
39
     size_t size )
40
767
{
41
767
  uint8_t sha224_hmac[ LIBHMAC_SHA224_HASH_SIZE ];
42
767
  const uint8_t *key                 = NULL;
43
767
  size_t key_size                    = 0;
44
767
  const uint8_t *message             = data;
45
767
  size_t message_size                = size;
46
47
767
  if( size >= 4 )
48
752
  {
49
752
    key_size          = (size_t) data[ 0 ] | ( (size_t) data[ 1 ] << 8 ) | ( (size_t) data[ 2 ] << 16 ) | ( (size_t) data[ 3 ] << 24 );
50
51
752
    if( key_size > size - 4 )
52
611
    {
53
611
      key_size = size - 4;
54
611
    }
55
752
    key             = &( data[ 4 ] );
56
752
    message         = &( data[ 4 + key_size ] );
57
752
    message_size    = size - 4 - key_size;
58
752
  }
59
767
  libhmac_sha224_calculate_hmac(
60
767
   key,
61
767
   key_size,
62
767
   message,
63
767
   message_size,
64
767
   sha224_hmac,
65
767
   LIBHMAC_SHA224_HASH_SIZE,
66
767
   NULL );
67
68
  /* Exercise invalid argument handling
69
   */
70
767
  libhmac_sha224_calculate_hmac(
71
767
   NULL,
72
767
   0,
73
767
   message,
74
767
   message_size,
75
767
   sha224_hmac,
76
767
   LIBHMAC_SHA224_HASH_SIZE,
77
767
   NULL );
78
79
767
  libhmac_sha224_calculate_hmac(
80
767
   key,
81
767
   key_size,
82
767
   message,
83
767
   message_size,
84
767
   sha224_hmac,
85
767
   sizeof( uint8_t ),
86
767
   NULL );
87
88
767
  return( 0 );
89
767
}
90
91
} /* extern "C" */