Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1332638 - fuzz PK11_Hashing, r=ttaubert
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
1 parent
4ac16dd
commit 993a402
Showing
6 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#ifndef shared_h__ | ||
#define shared_h__ | ||
|
||
#include "FuzzerRandom.h" | ||
#include "cert.h" | ||
#include "nss.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters