Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1334106 - split mpi target, r=ttaubert
Differential Revision: https://nss-review.dev.mozaws.net/D189 --HG-- extra : rebase_source : 30bd247a2eb5023e3ce5438b3f32d73ac3752065 extra : histedit_source : 3e3642f16fe9526943b563560468e4944bf37ff6
- Loading branch information
1 parent
4fc4896
commit 45ad819
Showing
14 changed files
with
667 additions
and
195 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
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/. */ | ||
|
||
/* | ||
* This target fuzzes NSS mpi against openssl bignum. | ||
* It therefore requires openssl to be installed. | ||
*/ | ||
|
||
#include "mpi_helper.h" | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
// We require at least size 3 to get two integers from Data. | ||
if (size < 3) { | ||
return 0; | ||
} | ||
INIT_NUMBERS | ||
|
||
// Compare with OpenSSL addition | ||
assert(mp_add(&a, &b, &c) == MP_OKAY); | ||
(void)BN_add(C, A, B); | ||
check_equal(C, &c, max_size); | ||
|
||
// Check a + b == a - -b | ||
mp_neg(&b, &b); | ||
assert(mp_sub(&a, &b, &r) == MP_OKAY); | ||
bool eq = mp_cmp(&r, &c) == 0; | ||
if (!eq) { | ||
char rC[max_size], cC[max_size], aC[max_size], bC[max_size]; | ||
mp_tohex(&r, rC); | ||
mp_tohex(&c, cC); | ||
mp_tohex(&a, aC); | ||
mp_tohex(&b, bC); | ||
std::cout << "a = " << std::hex << aC << std::endl; | ||
std::cout << "-b = " << std::hex << bC << std::endl; | ||
std::cout << "a + b = " << std::hex << cC << std::endl; | ||
std::cout << "a - -b = " << std::hex << rC << std::endl; | ||
} | ||
assert(eq); | ||
|
||
CLEANUP_AND_RETURN | ||
} |
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,27 @@ | ||
/* 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/. */ | ||
|
||
/* | ||
* This target fuzzes NSS mpi against openssl bignum. | ||
* It therefore requires openssl to be installed. | ||
*/ | ||
|
||
#include "mpi_helper.h" | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
// We require at least size 3 to get two integers from Data. | ||
if (size < 3) { | ||
return 0; | ||
} | ||
INIT_NUMBERS | ||
|
||
auto modulus = get_modulus(data, size, ctx); | ||
// Compare with OpenSSL add mod | ||
m1 = &std::get<1>(modulus); | ||
assert(mp_addmod(&a, &b, m1, &c) == MP_OKAY); | ||
(void)BN_mod_add(C, A, B, std::get<0>(modulus), ctx); | ||
check_equal(C, &c, max_size); | ||
|
||
CLEANUP_AND_RETURN | ||
} |
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,36 @@ | ||
/* 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/. */ | ||
|
||
/* | ||
* This target fuzzes NSS mpi against openssl bignum. | ||
* It therefore requires openssl to be installed. | ||
*/ | ||
|
||
#include "mpi_helper.h" | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
// We require at least size 3 to get two integers from Data. | ||
if (size < 3) { | ||
return 0; | ||
} | ||
INIT_NUMBERS | ||
|
||
// We can't divide by 0. | ||
if (mp_cmp_z(&b) == 0) { | ||
CLEANUP_AND_RETURN | ||
} | ||
|
||
// Compare with OpenSSL division | ||
assert(mp_div(&a, &b, &c, &r) == MP_OKAY); | ||
BN_div(C, R, A, B, ctx); | ||
check_equal(C, &c, max_size); | ||
check_equal(R, &r, max_size); | ||
|
||
// Check c * b + r == a | ||
assert(mp_mul(&c, &b, &c) == MP_OKAY); | ||
assert(mp_add(&c, &r, &c) == MP_OKAY); | ||
assert(mp_cmp(&c, &a) == 0); | ||
|
||
CLEANUP_AND_RETURN | ||
} |
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,27 @@ | ||
/* 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/. */ | ||
|
||
/* | ||
* This target fuzzes NSS mpi against openssl bignum. | ||
* It therefore requires openssl to be installed. | ||
*/ | ||
|
||
#include "mpi_helper.h" | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
// We require at least size 3 to get two integers from Data. | ||
if (size < 3) { | ||
return 0; | ||
} | ||
INIT_NUMBERS | ||
|
||
auto modulus = get_modulus(data, size, ctx); | ||
// Compare with OpenSSL exp mod | ||
m1 = &std::get<1>(modulus); | ||
assert(mp_exptmod(&a, &b, m1, &c) == MP_OKAY); | ||
(void)BN_mod_exp(C, A, B, std::get<0>(modulus), ctx); | ||
check_equal(C, &c, 2 * max_size); | ||
|
||
CLEANUP_AND_RETURN | ||
} |
Oops, something went wrong.