Coverage Report

Created: 2025-08-26 06:53

/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
4.31k
{
27
4.31k
#ifdef WITH_OPENSSL
28
4.31k
  static struct sshkey *rsa = generate_or_die(KEY_RSA, 2048);
29
4.31k
  static struct sshkey *ecdsa256 = generate_or_die(KEY_ECDSA, 256);
30
4.31k
  static struct sshkey *ecdsa384 = generate_or_die(KEY_ECDSA, 384);
31
4.31k
  static struct sshkey *ecdsa521 = generate_or_die(KEY_ECDSA, 521);
32
4.31k
#endif
33
4.31k
  struct sshkey_sig_details *details = NULL;
34
4.31k
  static struct sshkey *ed25519 = generate_or_die(KEY_ED25519, 0);
35
4.31k
  static const char *data = "If everyone started announcing his nose had "
36
4.31k
      "run away, I don’t know how it would all end";
37
4.31k
  static const size_t dlen = strlen(data);
38
39
4.31k
#ifdef WITH_OPENSSL
40
4.31k
  sshkey_verify(rsa, sig, slen, (const u_char *)data, dlen, NULL, 0, &details);
41
4.31k
  sshkey_sig_details_free(details);
42
4.31k
  details = NULL;
43
44
4.31k
  sshkey_verify(ecdsa256, sig, slen, (const u_char *)data, dlen, NULL, 0, &details);
45
4.31k
  sshkey_sig_details_free(details);
46
4.31k
  details = NULL;
47
48
4.31k
  sshkey_verify(ecdsa384, sig, slen, (const u_char *)data, dlen, NULL, 0, &details);
49
4.31k
  sshkey_sig_details_free(details);
50
4.31k
  details = NULL;
51
52
4.31k
  sshkey_verify(ecdsa521, sig, slen, (const u_char *)data, dlen, NULL, 0, &details);
53
4.31k
  sshkey_sig_details_free(details);
54
4.31k
  details = NULL;
55
4.31k
#endif
56
57
4.31k
  sshkey_verify(ed25519, sig, slen, (const u_char *)data, dlen, NULL, 0, &details);
58
4.31k
  sshkey_sig_details_free(details);
59
4.31k
  return 0;
60
4.31k
}
61
62
} // extern