Coverage Report

Created: 2024-10-02 06:58

/src/libcaes/ossfuzz/crypt_ccm_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libcaes AES-CCM crypt function
3
 *
4
 * Copyright (C) 2011-2024, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <stddef.h>
23
#include <stdint.h>
24
25
/* Note that some of the OSS-Fuzz engines use C++
26
 */
27
extern "C" {
28
29
#include "ossfuzz_libcaes.h"
30
31
int LLVMFuzzerTestOneInput(
32
     const uint8_t *data,
33
     size_t size )
34
625
{
35
625
  uint8_t encrypted_data[ 64 ];
36
625
  uint8_t key[ 16 ]  = {
37
625
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
38
625
  uint8_t nonce[ 8 ] = {
39
625
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
40
41
625
  libcaes_context_t *context = NULL;
42
43
625
  if( libcaes_context_initialize(
44
625
       &context,
45
625
       NULL ) != 1 )
46
0
  {
47
0
    return( 0 );
48
0
  }
49
625
  if( libcaes_context_set_key(
50
625
       context,
51
625
       LIBCAES_CRYPT_MODE_ENCRYPT,
52
625
       key,
53
625
       128,
54
625
       NULL ) != 1 )
55
0
  {
56
0
    goto on_error_libcaes;
57
0
  }
58
625
  libcaes_crypt_ccm(
59
625
   context,
60
625
   LIBCAES_CRYPT_MODE_ENCRYPT,
61
625
   nonce,
62
625
   8,
63
625
   data,
64
625
   size,
65
625
   encrypted_data,
66
625
   64,
67
625
   NULL );
68
69
625
on_error_libcaes:
70
625
  libcaes_context_free(
71
625
   &context,
72
625
   NULL );
73
74
625
  return( 0 );
75
625
}
76
77
} /* extern "C" */
78