Coverage Report

Created: 2026-08-18 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/nss/fuzz/targets/pkcs8.cc
Line
Count
Source
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include <cassert>
6
#include <cstddef>
7
#include <cstdint>
8
9
#include "keyhi.h"
10
#include "nss_scoped_ptrs.h"
11
#include "pk11pub.h"
12
#include "seccomon.h"
13
#include "utilrename.h"
14
15
#include "asn1/mutators.h"
16
#include "base/database.h"
17
18
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
19
  static NSSDatabase db = NSSDatabase();
20
21
  SECItem derPki = {siBuffer, (unsigned char*)data, (unsigned int)size};
22
23
  ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
24
  assert(slot);
25
26
  SECKEYPrivateKey* privKey = nullptr;
27
  if (PK11_ImportDERPrivateKeyInfoAndReturnKey(
28
          slot.get(), &derPki, nullptr, nullptr, false, false, KU_ALL, &privKey,
29
          nullptr) != SECSuccess) {
30
    return 0;
31
  }
32
33
  // Basic properties.
34
  (void)SECKEY_GetPrivateKeyType(privKey);
35
  (void)SECKEY_PrivateKeyStrengthInBits(privKey);
36
  (void)PK11_SignatureLen(privKey);
37
  (void)PK11_GetPrivateModulusLen(privKey);
38
39
  ScopedSECItem keyID(PK11_GetLowLevelKeyIDForPrivateKey(privKey));
40
41
  SECKEYPQGParams* params = PK11_GetPQGParamsFromPrivateKey(privKey);
42
  if (params && params->arena) {
43
    PORT_FreeArena(params->arena, PR_FALSE);
44
  }
45
46
  // Key and nickname.
47
  ScopedSECKEYPublicKey pubKey(SECKEY_ConvertToPublicKey(privKey));
48
  ScopedCERTCertificate cert(PK11_GetCertFromPrivateKey(privKey));
49
50
  char* nickname = PK11_GetPrivateKeyNickname(privKey);
51
  PORT_Free(nickname);
52
53
  // Export.
54
  ScopedSECItem derExport(PK11_ExportDERPrivateKeyInfo(privKey, nullptr));
55
56
  SECKEY_DestroyPrivateKey(privKey);
57
58
  return 0;
59
}
60
61
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size,
62
0
                                          size_t maxSize, unsigned int seed) {
63
0
  return ASN1Mutators::CustomMutator(data, size, maxSize, seed);
64
0
}
65
66
extern "C" size_t LLVMFuzzerCustomCrossOver(const uint8_t* data1, size_t size1,
67
                                            const uint8_t* data2, size_t size2,
68
                                            uint8_t* out, size_t maxOutSize,
69
0
                                            unsigned int seed) {
70
0
  return ASN1Mutators::CustomCrossOver(data1, size1, data2, size2, out,
71
0
                                       maxOutSize, seed);
72
0
}