comparison fuzz/fuzzer-kexcurve25519.c @ 1772:0cc85b4a4abb

Move fuzzer-kex initialisation into a constructor function Hopefully this can avoid hitting AFL timeouts https://github.com/google/oss-fuzz/pull/2474
author Matt Johnston <matt@ucc.asn.au>
date Thu, 29 Oct 2020 23:00:52 +0800
parents d5680e12ac33
children
comparison
equal deleted inserted replaced
1771:af9ed0815818 1772:0cc85b4a4abb
4 #include "debug.h" 4 #include "debug.h"
5 #include "runopts.h" 5 #include "runopts.h"
6 #include "algo.h" 6 #include "algo.h"
7 #include "bignum.h" 7 #include "bignum.h"
8 8
9 static struct key_context* keep_newkeys = NULL;
10 /* An arbitrary limit */
11 #define NUM_PARAMS 80
12 static struct kex_curve25519_param *curve25519_params[NUM_PARAMS];
13
14 static void setup() __attribute__((constructor));
15 // Perform initial setup here to avoid hitting timeouts on first run
16 static void setup() {
17 fuzz_common_setup();
18 fuzz_svr_setup();
19
20 keep_newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
21 keep_newkeys->algo_kex = fuzz_get_algo(sshkex, "curve25519-sha256");
22 keep_newkeys->algo_hostkey = DROPBEAR_SIGNKEY_ED25519;
23 ses.newkeys = keep_newkeys;
24
25 /* Pre-generate parameters */
26 int i;
27 for (i = 0; i < NUM_PARAMS; i++) {
28 curve25519_params[i] = gen_kexcurve25519_param();
29 }
30 }
31
9 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 32 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
10 static int once = 0;
11 static struct key_context* keep_newkeys = NULL;
12 /* number of generated parameters is limited by the timeout for the first run.
13 TODO move this to the libfuzzer initialiser function instead if the timeout
14 doesn't apply there */
15 #define NUM_PARAMS 20
16 static struct kex_curve25519_param *curve25519_params[NUM_PARAMS];
17
18 if (!once) {
19 fuzz_common_setup();
20 fuzz_svr_setup();
21
22 keep_newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
23 keep_newkeys->algo_kex = fuzz_get_algo(sshkex, "curve25519-sha256");
24 keep_newkeys->algo_hostkey = DROPBEAR_SIGNKEY_ED25519;
25 ses.newkeys = keep_newkeys;
26
27 /* Pre-generate parameters */
28 int i;
29 for (i = 0; i < NUM_PARAMS; i++) {
30 curve25519_params[i] = gen_kexcurve25519_param();
31 }
32
33 once = 1;
34 }
35
36 if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) { 33 if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
37 return 0; 34 return 0;
38 } 35 }
39 36
40 m_malloc_set_epoch(1); 37 m_malloc_set_epoch(1);