[tools] master update

Dr. Paul Dale pauli at openssl.org
Thu May 9 10:03:17 UTC 2019


The branch master has been updated
       via  f35dfdd6bba36d9b7568ee235177726ee6fe0f33 (commit)
      from  191d279c0e11953cd1a3d02e3fe422391cf9674f (commit)


- Log -----------------------------------------------------------------
commit f35dfdd6bba36d9b7568ee235177726ee6fe0f33
Author: Pauli <paul.dale at oracle.com>
Date:   Thu May 9 20:02:46 2019 +1000

    BN random range testing.
    
    Add a script to generate critical value tables for the bn_rand_range stochastic
    test.
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/38)

-----------------------------------------------------------------------

Summary of changes:
 statistics/README           |  6 +++++
 statistics/bn_rand_range.py | 61 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 statistics/README
 create mode 100755 statistics/bn_rand_range.py

diff --git a/statistics/README b/statistics/README
new file mode 100644
index 0000000..d564104
--- /dev/null
+++ b/statistics/README
@@ -0,0 +1,6 @@
+
+This collection of scripts contains statistical scripts.
+
+
+bn_rand_range.py    Generate the critical values tables for test/bn_rand_range.c
+                    There is a dependency on the scipi package.
diff --git a/statistics/bn_rand_range.py b/statistics/bn_rand_range.py
new file mode 100755
index 0000000..57a579b
--- /dev/null
+++ b/statistics/bn_rand_range.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+
+# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+# Run this using:
+#   bn_rand_range.py > $(OPENSSL)/test/bn_rand_range.h
+#
+# There is a dependency of scipi, include the package python3-scipy to resolve
+# this.
+
+from datetime import datetime
+from scipy.stats import chi2, binom
+
+alpha_chi2 = 0.95
+alpha_binomial = 0.9999
+test_cases = list(range(2, 20)) \
+             + [x * 10 + 10 for x in range(1, 10)] \
+             + [x * 1000 for x in range(1, 11)]
+
+# The rest of this file produces the C include file
+
+def do_case(n):
+    "Output a single formatted row in the table"
+    ns = "%d," % n
+    iterations = "%d," % (n * (100 if n < 1000 else 10))
+    critical = "%f" % (chi2.ppf(alpha_chi2, n - 1))
+    print("    { %6s %8s %12s }," % ( ns, iterations, critical ))
+
+# Work out the copyright year range
+year = datetime.today().year
+if year != 2019:
+    year = "2019-%d" % year
+
+print("""/*
+ * WARNING: do not edit!
+ * Generated by statistics/bn_rand_range.py in the OpenSSL tool repository.
+ *
+ * Copyright %s The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+static const struct {
+    unsigned int range;
+    unsigned int iterations;
+    double critical;
+} rand_range_cases[] = {""" % year)
+num_cases = len(list(map(do_case, test_cases)))
+print("};\n")
+
+# Finally, calculate and output the lower tail binomial threshold.
+b_thresh = binom.isf(alpha_binomial, num_cases, alpha_chi2)
+print("static const int binomial_critical = %d;\n" % b_thresh)


More information about the openssl-commits mailing list