summaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authorMartin Thomson <martin.thomson@gmail.com>2017-08-24 10:16:13 +1000
committerMartin Thomson <martin.thomson@gmail.com>2017-08-24 10:16:13 +1000
commit0ec9a2703f77ec33765b318cc1ec519206faec26 (patch)
treebae90a4678ce056d51fcf594c67fa16976a7b5b5 /fuzz
parentdaa71317c427f1e96ba7819df1b5e8dfbf0d39bb (diff)
parentae7880aaf35321274152907955868ef50c0255d1 (diff)
downloadnss-hg-0ec9a2703f77ec33765b318cc1ec519206faec26.tar.gz
Merge NSS trunk to NSS_TLS13_DRAFT19_BRANCH, a=merge
Diffstat (limited to 'fuzz')
-rwxr-xr-xfuzz/config/git-copy.sh27
-rw-r--r--fuzz/mpi_expmod_target.cc6
-rw-r--r--fuzz/mpi_helper.cc6
-rw-r--r--fuzz/mpi_helper.h1
4 files changed, 27 insertions, 13 deletions
diff --git a/fuzz/config/git-copy.sh b/fuzz/config/git-copy.sh
index a5c7d371d..a9e817e2a 100755
--- a/fuzz/config/git-copy.sh
+++ b/fuzz/config/git-copy.sh
@@ -7,18 +7,18 @@ if [ $# -lt 3 ]; then
exit 2
fi
-REPO=$1
-COMMIT=$2
-DIR=$3
+REPO="$1"
+COMMIT="$2"
+DIR="$3"
echo "Copy '$COMMIT' from '$REPO' to '$DIR'"
-if [ -f $DIR/.git-copy ]; then
- CURRENT=$(cat $DIR/.git-copy)
- if [ $(echo -n $COMMIT | wc -c) != "40" ]; then
+if [ -f "$DIR"/.git-copy ]; then
+ CURRENT=$(cat "$DIR"/.git-copy)
+ if [ $(echo -n "$COMMIT" | wc -c) != "40" ]; then
# On the off chance that $COMMIT is a remote head.
- ACTUAL=$(git ls-remote $REPO $COMMIT | cut -c 1-40 -)
+ ACTUAL=$(git ls-remote "$REPO" "$COMMIT" | cut -c 1-40 -)
else
- ACTUAL=$COMMIT
+ ACTUAL="$COMMIT"
fi
if [ "$CURRENT" = "$ACTUAL" ]; then
echo "Up to date."
@@ -26,8 +26,9 @@ if [ -f $DIR/.git-copy ]; then
fi
fi
-git init -q $DIR
-git -C $DIR fetch -q --depth=1 $REPO $COMMIT:git-copy-tmp
-git -C $DIR reset --hard git-copy-tmp
-git -C $DIR rev-parse --verify HEAD > $DIR/.git-copy
-rm -rf $DIR/.git
+rm -rf "$DIR"
+git init -q "$DIR"
+git -C "$DIR" fetch -q --depth=1 "$REPO" "$COMMIT":git-copy-tmp
+git -C "$DIR" reset --hard git-copy-tmp
+git -C "$DIR" rev-parse --verify HEAD > "$DIR"/.git-copy
+rm -rf "$DIR"/.git
diff --git a/fuzz/mpi_expmod_target.cc b/fuzz/mpi_expmod_target.cc
index ed31da354..23826e935 100644
--- a/fuzz/mpi_expmod_target.cc
+++ b/fuzz/mpi_expmod_target.cc
@@ -19,6 +19,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
auto modulus = get_modulus(data, size, ctx);
// Compare with OpenSSL exp mod
m1 = &std::get<1>(modulus);
+ print_bn("A", A);
+ print_bn("B", B);
+ print_bn("m", std::get<0>(modulus));
+ check_equal(A, &a, max_size);
+ check_equal(B, &b, max_size);
+ check_equal(std::get<0>(modulus), m1, 3 * max_size);
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);
diff --git a/fuzz/mpi_helper.cc b/fuzz/mpi_helper.cc
index 65cf4b9cd..d092fdb11 100644
--- a/fuzz/mpi_helper.cc
+++ b/fuzz/mpi_helper.cc
@@ -12,6 +12,12 @@ char *to_char(const uint8_t *x) {
return reinterpret_cast<char *>(const_cast<unsigned char *>(x));
}
+void print_bn(std::string label, BIGNUM *x) {
+ char *xc = BN_bn2hex(x);
+ std::cout << label << ": " << std::hex << xc << std::endl;
+ OPENSSL_free(xc);
+}
+
// Check that the two numbers are equal.
void check_equal(BIGNUM *b, mp_int *m, size_t max_size) {
char *bnBc = BN_bn2hex(b);
diff --git a/fuzz/mpi_helper.h b/fuzz/mpi_helper.h
index 17383744b..ef7041b25 100644
--- a/fuzz/mpi_helper.h
+++ b/fuzz/mpi_helper.h
@@ -23,6 +23,7 @@ void parse_input(const uint8_t *data, size_t size, BIGNUM *A, BIGNUM *B,
void parse_input(const uint8_t *data, size_t size, BIGNUM *A, mp_int *a);
std::tuple<BIGNUM *, mp_int> get_modulus(const uint8_t *data, size_t size,
BN_CTX *ctx);
+void print_bn(std::string label, BIGNUM *x);
// Initialise MPI and BN variables
// XXX: Also silence unused variable warnings for R.