/src/hpn-ssh/regress/misc/fuzz-harness/sig_fuzz.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // cc_fuzz_target test for public key parsing. |
2 | | |
3 | | #include <stddef.h> |
4 | | #include <stdio.h> |
5 | | #include <stdint.h> |
6 | | #include <stdlib.h> |
7 | | #include <string.h> |
8 | | |
9 | | extern "C" { |
10 | | |
11 | | #include "includes.h" |
12 | | #include "sshkey.h" |
13 | | #include "ssherr.h" |
14 | | |
15 | 5 | static struct sshkey *generate_or_die(int type, unsigned bits) { |
16 | 5 | int r; |
17 | 5 | struct sshkey *ret; |
18 | 5 | if ((r = sshkey_generate(type, bits, &ret)) != 0) { |
19 | 0 | fprintf(stderr, "generate(%d, %u): %s", type, bits, ssh_err(r)); |
20 | 0 | abort(); |
21 | 0 | } |
22 | 5 | return ret; |
23 | 5 | } |
24 | | |
25 | | int LLVMFuzzerTestOneInput(const uint8_t* sig, size_t slen) |
26 | 5.04k | { |
27 | 5.04k | #ifdef WITH_OPENSSL |
28 | 5.04k | static struct sshkey *rsa = generate_or_die(KEY_RSA, 2048); |
29 | 5.04k | static struct sshkey *ecdsa256 = generate_or_die(KEY_ECDSA, 256); |
30 | 5.04k | static struct sshkey *ecdsa384 = generate_or_die(KEY_ECDSA, 384); |
31 | 5.04k | static struct sshkey *ecdsa521 = generate_or_die(KEY_ECDSA, 521); |
32 | 5.04k | #endif |
33 | 5.04k | struct sshkey_sig_details *details = NULL; |
34 | 5.04k | static struct sshkey *ed25519 = generate_or_die(KEY_ED25519, 0); |
35 | 5.04k | static const char *data = "If everyone started announcing his nose had " |
36 | 5.04k | "run away, I don’t know how it would all end"; |
37 | 5.04k | static const size_t dlen = strlen(data); |
38 | | |
39 | 5.04k | #ifdef WITH_OPENSSL |
40 | 5.04k | sshkey_verify(rsa, sig, slen, (const u_char *)data, dlen, NULL, 0, &details); |
41 | 5.04k | sshkey_sig_details_free(details); |
42 | 5.04k | details = NULL; |
43 | | |
44 | 5.04k | sshkey_verify(ecdsa256, sig, slen, (const u_char *)data, dlen, NULL, 0, &details); |
45 | 5.04k | sshkey_sig_details_free(details); |
46 | 5.04k | details = NULL; |
47 | | |
48 | 5.04k | sshkey_verify(ecdsa384, sig, slen, (const u_char *)data, dlen, NULL, 0, &details); |
49 | 5.04k | sshkey_sig_details_free(details); |
50 | 5.04k | details = NULL; |
51 | | |
52 | 5.04k | sshkey_verify(ecdsa521, sig, slen, (const u_char *)data, dlen, NULL, 0, &details); |
53 | 5.04k | sshkey_sig_details_free(details); |
54 | 5.04k | details = NULL; |
55 | 5.04k | #endif |
56 | | |
57 | 5.04k | sshkey_verify(ed25519, sig, slen, (const u_char *)data, dlen, NULL, 0, &details); |
58 | 5.04k | sshkey_sig_details_free(details); |
59 | 5.04k | return 0; |
60 | 5.04k | } |
61 | | |
62 | | } // extern |