Skip to content

Commit

Permalink
Bug 1332638 - fuzz PK11_Hashing, r=ttaubert
Browse files Browse the repository at this point in the history
Differential Revision: https://nss-review.dev.mozaws.net/D158

--HG--
extra : rebase_source : 391fd7ea9cf419214eb699be6d4a34ec7f34f9c8
extra : amend_source : 0df17629e6e2de263ed292ce30b952385cf1fc8c
extra : histedit_source : c4ea8cd329bee586a2fad75951cb1a5f720b484a
  • Loading branch information
franziskuskiefer committed Jan 20, 2017
1 parent 4ac16dd commit 993a402
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 5 deletions.
1 change: 0 additions & 1 deletion fuzz/cert_target.cc
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "FuzzerInternal.h"
#include "FuzzerRandom.h"
#include "asn1_mutators.h"
#include "shared.h"

Expand Down
17 changes: 15 additions & 2 deletions fuzz/fuzz.gyp
Expand Up @@ -124,14 +124,27 @@
'fuzz_base',
],
},
{
'target_name': 'nssfuzz-hash',
'type': 'executable',
'sources': [
'hash_target.cc',
'initialize.cc',
],
'dependencies': [
'<(DEPTH)/exports.gyp:nss_exports',
'fuzz_base',
],
},
{
'target_name': 'nssfuzz',
'type': 'none',
'dependencies': [
'nssfuzz-cert',
'nssfuzz-spki',
'nssfuzz-hash',
'nssfuzz-pkcs8',
],
'nssfuzz-spki',
]
}
],
}
42 changes: 42 additions & 0 deletions fuzz/hash_target.cc
@@ -0,0 +1,42 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <memory>
#include <vector>

#include "FuzzerInternal.h"
#include "hasht.h"
#include "pk11pub.h"
#include "secoidt.h"
#include "shared.h"

extern const uint16_t DEFAULT_MAX_LENGTH = 4096U;

const std::vector<SECOidTag> algos = {SEC_OID_MD5, SEC_OID_SHA1, SEC_OID_SHA256,
SEC_OID_SHA384, SEC_OID_SHA512};

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint8_t hashOut[HASH_LENGTH_MAX];

static std::unique_ptr<NSSDatabase> db(new NSSDatabase());
assert(db != nullptr);

// simple hashing.
for (auto algo : algos) {
assert(PK11_HashBuf(algo, hashOut, data, size) == SECSuccess);
}

// hashing with context.
for (auto algo : algos) {
unsigned int len = 0;
PK11Context *context = PK11_CreateDigestContext(algo);
assert(context != nullptr);
assert(PK11_DigestBegin(context) == SECSuccess);
assert(PK11_DigestFinal(context, hashOut, &len, HASH_LENGTH_MAX) ==
SECSuccess);
PK11_DestroyContext(context, PR_TRUE);
}

return 0;
}
1 change: 0 additions & 1 deletion fuzz/pkcs8_target.cc
Expand Up @@ -9,7 +9,6 @@
#include "pk11pub.h"

#include "FuzzerInternal.h"
#include "FuzzerRandom.h"
#include "asn1_mutators.h"
#include "assert.h"
#include "shared.h"
Expand Down
1 change: 1 addition & 0 deletions fuzz/shared.h
Expand Up @@ -7,6 +7,7 @@
#ifndef shared_h__
#define shared_h__

#include "FuzzerRandom.h"
#include "cert.h"
#include "nss.h"

Expand Down
1 change: 0 additions & 1 deletion fuzz/spki_target.cc
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "FuzzerInternal.h"
#include "FuzzerRandom.h"
#include "asn1_mutators.h"
#include "shared.h"

Expand Down

0 comments on commit 993a402

Please sign in to comment.