|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import argparse |
| 4 | +import json |
| 5 | +import time |
| 6 | + |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +import subprocess as sp |
| 10 | + |
| 11 | + |
| 12 | +def base_options(library): |
| 13 | + match library: |
| 14 | + case "openssl" | "botan" | "boringssl" | "ippcp" | "libressl" | "gcrypt" | "nettle": |
| 15 | + return ["-ps", "123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234"] |
| 16 | + case "cryptopp" | "mbedtls": |
| 17 | + return ["-ps", "12345678"] |
| 18 | + case _: |
| 19 | + return [] |
| 20 | + |
| 21 | +def default_options(library): |
| 22 | + match library: |
| 23 | + case "botan" | "cryptopp": |
| 24 | + return ["-gt", "ECDH"] |
| 25 | + case _: |
| 26 | + return [] |
| 27 | + |
| 28 | +def test_vectors_options(library): |
| 29 | + return default_options(library) |
| 30 | + |
| 31 | +def performance_options(library): |
| 32 | + return default_options(library) |
| 33 | + |
| 34 | +def signature_options(library): |
| 35 | + match library: |
| 36 | + case "nettle" | "gcrypt" | "boringssl" | "openssl" | "tomcrypt" | "libressl" | "ippcp" | "mbedtls": |
| 37 | + return ["-st", "NONEwithECDSA"] |
| 38 | + case _: |
| 39 | + return [] |
| 40 | + |
| 41 | +def miscellaneous_options(library): |
| 42 | + return default_options(library) |
| 43 | + |
| 44 | +def twist_options(library): |
| 45 | + return default_options(library) |
| 46 | + |
| 47 | +def invalid_options(library): |
| 48 | + return default_options(library) |
| 49 | + |
| 50 | +def degenerate_options(library): |
| 51 | + return default_options(library) |
| 52 | + |
| 53 | +def cofactor_options(library): |
| 54 | + return default_options(library) |
| 55 | + |
| 56 | +def composite_options(library): |
| 57 | + return default_options(library) |
| 58 | + |
| 59 | +def edge_cases_options(library): |
| 60 | + return default_options(library) |
| 61 | + |
| 62 | +def wrong_options(library): |
| 63 | + return default_options(library) |
| 64 | + |
| 65 | +def test_library(library, test_suite, version): |
| 66 | + opts = base_options(library) |
| 67 | + opts.extend(globals()[f"{test_suite.replace('-', '_')}_options"](library)) |
| 68 | + command = ["nix", "run", f"?submodules=1#{library}.{version}", "--", "test", f"-oyml:results/{library}_{test_suite}_{version}.yml", *opts, test_suite, library] |
| 69 | + print(command) |
| 70 | + process = sp.run(command) |
| 71 | + |
| 72 | + |
| 73 | +def main(): |
| 74 | + parser = argparse.ArgumentParser() |
| 75 | + parser.add_argument("-l", "--library") |
| 76 | + parser.add_argument("-s", "--suite") |
| 77 | + args = parser.parse_args() |
| 78 | + library = args.library |
| 79 | + suite = args.suite |
| 80 | + |
| 81 | + libraries = [ |
| 82 | + "botan", |
| 83 | + "cryptopp", |
| 84 | + "openssl", |
| 85 | + "boringssl", |
| 86 | + "gcrypt", |
| 87 | + "mbedtls", |
| 88 | + "ippcp", |
| 89 | + "nettle", |
| 90 | + "libressl", |
| 91 | + ] |
| 92 | + |
| 93 | + suites = [ |
| 94 | + "default", |
| 95 | + "test-vectors", |
| 96 | + "performance", |
| 97 | + "signature", |
| 98 | + "miscellaneous", |
| 99 | + "invalid", |
| 100 | + "twist", |
| 101 | + "degenerate", |
| 102 | + "edge-cases", |
| 103 | + "cofactor", |
| 104 | + "composite", |
| 105 | + "wrong" |
| 106 | + ] |
| 107 | + |
| 108 | + |
| 109 | + if library is None: |
| 110 | + libraries2test = libraries |
| 111 | + else: |
| 112 | + libraries2test = [library] |
| 113 | + |
| 114 | + if suite is None: |
| 115 | + suites2test = suites |
| 116 | + else: |
| 117 | + suites2test = [suite] |
| 118 | + |
| 119 | + for library in libraries2test: |
| 120 | + with open(f"./nix/{library}_pkg_versions.json", "r") as f: |
| 121 | + versions = list(json.load(f).keys()) |
| 122 | + for version in versions: |
| 123 | + for suite in suites2test: |
| 124 | + test_library(library, suite, version) |
| 125 | + |
| 126 | + |
| 127 | +if __name__ == '__main__': |
| 128 | + main() |
0 commit comments