Coverage Report

Created: 2024-06-12 07:07

/src/libcaes/ossfuzz/crypt_xts_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * OSS-Fuzz target for libcaes AES-ECB 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
626
{
35
626
  uint8_t encrypted_data[ 64 ];
36
626
  uint8_t key[ 16 ]         = {
37
626
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
38
626
  uint8_t tweak_key[ 16 ]   = {
39
626
    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f };
40
626
  uint8_t tweak_value[ 16 ] = {
41
626
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
42
43
626
  libcaes_tweaked_context_t *tweaked_context = NULL;
44
45
626
  if( libcaes_tweaked_context_initialize(
46
626
       &tweaked_context,
47
626
       NULL ) != 1 )
48
0
  {
49
0
    return( 0 );
50
0
  }
51
626
  if( libcaes_tweaked_context_set_keys(
52
626
       tweaked_context,
53
626
       LIBCAES_CRYPT_MODE_ENCRYPT,
54
626
       key,
55
626
       128,
56
626
       tweak_key,
57
626
       128,
58
626
       NULL ) != 1 )
59
0
  {
60
0
    goto on_error_libcaes;
61
0
  }
62
626
  libcaes_crypt_xts(
63
626
   tweaked_context,
64
626
   LIBCAES_CRYPT_MODE_ENCRYPT,
65
626
   tweak_value,
66
626
   16,
67
626
   data,
68
626
   size,
69
626
   encrypted_data,
70
626
   64,
71
626
   NULL );
72
73
626
on_error_libcaes:
74
626
  libcaes_tweaked_context_free(
75
626
   &tweaked_context,
76
626
   NULL );
77
78
626
  return( 0 );
79
626
}
80
81
} /* extern "C" */
82