Skip to content

Commit bfeb8f3

Browse files
loganadenmkj
authored andcommitted
Add fuzzers for mlkem hybrid.
Signed-off-by: Loganaden Velvindron <logan@cyberstorm.mu> Signed-off-by: Jaykishan Mutkawoa <jay@cyberstorm.mu> Signed-off-by: Kavish Nadan <kn@cyberstorm.mu>
1 parent 1748cca commit bfeb8f3

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ check: lint
298298
FUZZ_TARGETS=fuzzer-preauth fuzzer-pubkey fuzzer-verify fuzzer-preauth_nomaths \
299299
fuzzer-kexdh fuzzer-kexecdh fuzzer-kexcurve25519 fuzzer-client fuzzer-client_nomaths \
300300
fuzzer-postauth_nomaths fuzzer-cliconf \
301-
fuzzer-kexsntrup-srv fuzzer-kexsntrup-cli
301+
fuzzer-kexsntrup-srv fuzzer-kexsntrup-cli \
302+
fuzzer-kexmlkem-srv fuzzer-kexmlkem-cli
302303

303304
FUZZER_OPTIONS = $(addsuffix .options, $(FUZZ_TARGETS))
304305
FUZZ_OBJS = $(addprefix fuzz/,$(addsuffix .o,$(FUZZ_TARGETS))) \

fuzz/fuzzer-kexmlkem-cli.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "fuzz.h"
2+
#include "session.h"
3+
#include "fuzz-wrapfd.h"
4+
#include "debug.h"
5+
#include "runopts.h"
6+
#include "algo.h"
7+
8+
static struct key_context* keep_newkeys = NULL;
9+
10+
static void setup() __attribute__((constructor));
11+
static void setup() {
12+
fuzz_common_setup();
13+
fuzz_cli_setup();
14+
15+
keep_newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
16+
keep_newkeys->algo_kex = fuzz_get_algo(sshkex, "mlkem768x25519-sha256");
17+
}
18+
19+
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
20+
if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
21+
return 0;
22+
}
23+
24+
m_malloc_set_epoch(1);
25+
26+
if (setjmp(fuzz.jmp) == 0) {
27+
/* Arbitrary key to write into a buffer */
28+
sign_key *hostkey = cli_opts.privkeys->first->item;
29+
ses.newkeys = keep_newkeys;
30+
31+
struct kex_pqhybrid_param *param = gen_kexpqhybrid_param();
32+
33+
buffer * q_s = buf_getstringbuf(fuzz.input);
34+
35+
ses.kexhashbuf = buf_new(KEXHASHBUF_MAX_INTS);
36+
kexpqhybrid_comb_key(param, q_s, hostkey);
37+
38+
free_kexpqhybrid_param(param);
39+
40+
buf_free(ses.dh_K_bytes);
41+
buf_free(q_s);
42+
43+
buf_free(ses.hash);
44+
buf_free(ses.session_id);
45+
/* kexhashbuf is freed in kexpqhybrid_comb_key */
46+
47+
m_malloc_free_epoch(1, 0);
48+
} else {
49+
m_malloc_free_epoch(1, 1);
50+
TRACE(("dropbear_exit longjmped"))
51+
/* dropbear_exit jumped here */
52+
}
53+
54+
return 0;
55+
}

fuzz/fuzzer-kexmlkem-srv.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "fuzz.h"
2+
#include "session.h"
3+
#include "fuzz-wrapfd.h"
4+
#include "debug.h"
5+
#include "runopts.h"
6+
#include "algo.h"
7+
8+
static struct key_context* keep_newkeys = NULL;
9+
10+
static void setup() __attribute__((constructor));
11+
static void setup() {
12+
fuzz_common_setup();
13+
fuzz_svr_setup();
14+
15+
keep_newkeys = (struct key_context*)m_malloc(sizeof(struct key_context));
16+
keep_newkeys->algo_kex = fuzz_get_algo(sshkex, "mlkem768x25519-sha256");
17+
keep_newkeys->algo_hostkey = DROPBEAR_SIGNKEY_ED25519;
18+
}
19+
20+
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
21+
if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
22+
return 0;
23+
}
24+
25+
m_malloc_set_epoch(1);
26+
27+
if (setjmp(fuzz.jmp) == 0) {
28+
ses.newkeys = keep_newkeys;
29+
30+
struct kex_pqhybrid_param *param = gen_kexpqhybrid_param();
31+
32+
buffer * q_c = buf_getstringbuf(fuzz.input);
33+
34+
ses.kexhashbuf = buf_new(KEXHASHBUF_MAX_INTS);
35+
kexpqhybrid_comb_key(param, q_c, svr_opts.hostkey);
36+
37+
free_kexpqhybrid_param(param);
38+
39+
buf_free(ses.dh_K_bytes);
40+
buf_free(q_c);
41+
42+
buf_free(ses.hash);
43+
buf_free(ses.session_id);
44+
/* kexhashbuf is freed in kexpqhybrid_comb_key */
45+
46+
m_malloc_free_epoch(1, 0);
47+
} else {
48+
m_malloc_free_epoch(1, 1);
49+
TRACE(("dropbear_exit longjmped"))
50+
/* dropbear_exit jumped here */
51+
}
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)