annotate fuzzer-verify.c @ 1672:3a97f14c0235

Add Chacha20-Poly1305, AES128-GCM and AES256-GCM support (#93) * Add Chacha20-Poly1305 authenticated encryption * Add general AEAD approach. * Add [email protected] algo using LibTomCrypt chacha and poly1305 routines. Chacha20-Poly1305 is generally faster than AES256 on CPU w/o dedicated AES instructions, having the same key size. Compiling in will add ~5,5kB to binary size on x86-64. function old new delta chacha_crypt - 1397 +1397 _poly1305_block - 608 +608 poly1305_done - 595 +595 dropbear_chachapoly_crypt - 457 +457 .rodata 26976 27392 +416 poly1305_process - 290 +290 poly1305_init - 221 +221 chacha_setup - 218 +218 encrypt_packet 1068 1270 +202 dropbear_chachapoly_getlength - 147 +147 decrypt_packet 756 897 +141 chacha_ivctr64 - 137 +137 read_packet 543 637 +94 dropbear_chachapoly_start - 94 +94 read_kex_algos 792 880 +88 chacha_keystream - 69 +69 dropbear_mode_chachapoly - 48 +48 sshciphers 280 320 +40 dropbear_mode_none 24 48 +24 dropbear_mode_ctr 24 48 +24 dropbear_mode_cbc 24 48 +24 dropbear_chachapoly_mac - 24 +24 dropbear_chachapoly - 24 +24 gen_new_keys 848 854 +6 ------------------------------------------------------------------------------ (add/remove: 14/0 grow/shrink: 10/0 up/down: 5388/0) Total: 5388 bytes * Add AES128-GCM and AES256-GCM authenticated encryption * Add general AES-GCM mode. * Add [email protected] and [email protected] algo using LibTomCrypt gcm routines. AES-GCM is combination of AES CTR mode and GHASH, slower than AES-CTR on CPU w/o dedicated AES/GHASH instructions therefore disabled by default. Compiling in will add ~6kB to binary size on x86-64. function old new delta gcm_process - 1060 +1060 .rodata 26976 27808 +832 gcm_gf_mult - 820 +820 gcm_add_aad - 660 +660 gcm_shift_table - 512 +512 gcm_done - 471 +471 gcm_add_iv - 384 +384 gcm_init - 347 +347 dropbear_gcm_crypt - 309 +309 encrypt_packet 1068 1270 +202 decrypt_packet 756 897 +141 gcm_reset - 118 +118 read_packet 543 637 +94 read_kex_algos 792 880 +88 sshciphers 280 360 +80 gcm_mult_h - 80 +80 dropbear_gcm_start - 62 +62 dropbear_mode_gcm - 48 +48 dropbear_mode_none 24 48 +24 dropbear_mode_ctr 24 48 +24 dropbear_mode_cbc 24 48 +24 dropbear_ghash - 24 +24 dropbear_gcm_getlength - 24 +24 gen_new_keys 848 854 +6 ------------------------------------------------------------------------------ (add/remove: 14/0 grow/shrink: 10/0 up/down: 6434/0) Total: 6434 bytes
author Vladislav Grishenko <themiron@users.noreply.github.com>
date Mon, 25 May 2020 20:50:25 +0500
parents f52919ffd3b1
children ae41624c2198
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "fuzz.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "session.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 #include "fuzz-wrapfd.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #include "debug.h"
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 static void setup_fuzzer(void) {
1456
a90fdd2d2ed8 add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents: 1380
diff changeset
7 fuzz_common_setup();
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 static buffer *verifydata;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 /* Tests reading a public key and verifying a signature */
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 static int once = 0;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 if (!once) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 setup_fuzzer();
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 verifydata = buf_new(30);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 buf_putstring(verifydata, "x", 1);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 once = 1;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21
1456
a90fdd2d2ed8 add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents: 1380
diff changeset
22 if (fuzz_set_input(Data, Size) == DROPBEAR_FAILURE) {
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 return 0;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 m_malloc_set_epoch(1);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 if (setjmp(fuzz.jmp) == 0) {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 sign_key *key = new_sign_key();
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 enum signkey_type type = DROPBEAR_SIGNKEY_ANY;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 if (buf_get_pub_key(fuzz.input, key, &type) == DROPBEAR_SUCCESS) {
1529
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
32 if (buf_verify(fuzz.input, key, verifydata) == DROPBEAR_SUCCESS) {
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
33 /* The fuzzer is capable of generating keys with a signature to match.
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
34 We don't want false positives if the key is bogus, since a client/server
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
35 wouldn't be trusting a bogus key anyway */
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
36 int boguskey = 0;
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
37
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
38 if (type == DROPBEAR_SIGNKEY_DSS) {
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
39 /* So far have seen dss keys with bad p/q/g domain parameters */
1655
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
40 int pprime, qprime, trials;
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
41 trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->p));
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
42 assert(mp_prime_is_prime(key->dsskey->p, trials, &pprime) == MP_OKAY);
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
43 trials = mp_prime_rabin_miller_trials(mp_count_bits(key->dsskey->q));
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
44 assert(mp_prime_is_prime(key->dsskey->q, trials, &qprime) == MP_OKAY);
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
45 boguskey = !(pprime && qprime);
f52919ffd3b1 update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents: 1559
diff changeset
46 /* Could also check g**q mod p == 1 */
1529
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
47 }
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
48
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
49 if (!boguskey) {
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
50 printf("Random key/signature managed to verify!\n");
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
51 abort();
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
52 }
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
53
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
54
66a1a2547133 The fuzzer has managed to generated DSS key/signature pairs that
Matt Johnston <matt@ucc.asn.au>
parents: 1456
diff changeset
55 }
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 sign_key_free(key);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 m_malloc_free_epoch(1, 0);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 } else {
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 m_malloc_free_epoch(1, 1);
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 TRACE(("dropbear_exit longjmped"))
1559
92c93b4a3646 Fix to be able to compile normal(ish) binaries with --enable-fuzz
Matt Johnston <matt@ucc.asn.au>
parents: 1529
diff changeset
62 /* dropbear_exit jumped here */
1380
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 }
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 return 0;
d201105df2ed add fuzzer-verify
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 }