Merge remote-tracking branch 'origin/development' into sha3-updated
This commit is contained in:
commit
05d71ffe5b
359 changed files with 10157 additions and 3037 deletions
|
@ -10,3 +10,9 @@ pylint == 2.4.4
|
|||
# Use the earliest version of mypy that works with our code base.
|
||||
# See https://github.com/Mbed-TLS/mbedtls/pull/3953 .
|
||||
mypy >= 0.780
|
||||
|
||||
# Install cryptography to avoid import-error reported by pylint.
|
||||
# What we really need is cryptography >= 35.0.0, which is only
|
||||
# available for Python >= 3.6.
|
||||
cryptography >= 35.0.0; sys_platform == 'linux' and python_version >= '3.6'
|
||||
cryptography; sys_platform == 'linux' and python_version < '3.6'
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Purpose
|
||||
|
||||
This script is for comparing the size of the library files from two
|
||||
different Git revisions within an Mbed TLS repository.
|
||||
The results of the comparison is formatted as csv and stored at a
|
||||
|
@ -29,18 +27,103 @@ import argparse
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from enum import Enum
|
||||
|
||||
from mbedtls_dev import build_tree
|
||||
|
||||
class SupportedArch(Enum):
|
||||
"""Supported architecture for code size measurement."""
|
||||
AARCH64 = 'aarch64'
|
||||
AARCH32 = 'aarch32'
|
||||
ARMV8_M = 'armv8-m'
|
||||
X86_64 = 'x86_64'
|
||||
X86 = 'x86'
|
||||
|
||||
CONFIG_TFM_MEDIUM_MBEDCRYPTO_H = "../configs/tfm_mbedcrypto_config_profile_medium.h"
|
||||
CONFIG_TFM_MEDIUM_PSA_CRYPTO_H = "../configs/crypto_config_profile_medium.h"
|
||||
class SupportedConfig(Enum):
|
||||
"""Supported configuration for code size measurement."""
|
||||
DEFAULT = 'default'
|
||||
TFM_MEDIUM = 'tfm-medium'
|
||||
|
||||
DETECT_ARCH_CMD = "cc -dM -E - < /dev/null"
|
||||
def detect_arch() -> str:
|
||||
"""Auto-detect host architecture."""
|
||||
cc_output = subprocess.check_output(DETECT_ARCH_CMD, shell=True).decode()
|
||||
if "__aarch64__" in cc_output:
|
||||
return SupportedArch.AARCH64.value
|
||||
if "__arm__" in cc_output:
|
||||
return SupportedArch.AARCH32.value
|
||||
if "__x86_64__" in cc_output:
|
||||
return SupportedArch.X86_64.value
|
||||
if "__x86__" in cc_output:
|
||||
return SupportedArch.X86.value
|
||||
else:
|
||||
print("Unknown host architecture, cannot auto-detect arch.")
|
||||
sys.exit(1)
|
||||
|
||||
class CodeSizeInfo: # pylint: disable=too-few-public-methods
|
||||
"""Gather information used to measure code size.
|
||||
|
||||
It collects information about architecture, configuration in order to
|
||||
infer build command for code size measurement.
|
||||
"""
|
||||
|
||||
SupportedArchConfig = [
|
||||
"-a " + SupportedArch.AARCH64.value + " -c " + SupportedConfig.DEFAULT.value,
|
||||
"-a " + SupportedArch.AARCH32.value + " -c " + SupportedConfig.DEFAULT.value,
|
||||
"-a " + SupportedArch.X86_64.value + " -c " + SupportedConfig.DEFAULT.value,
|
||||
"-a " + SupportedArch.X86.value + " -c " + SupportedConfig.DEFAULT.value,
|
||||
"-a " + SupportedArch.ARMV8_M.value + " -c " + SupportedConfig.TFM_MEDIUM.value,
|
||||
]
|
||||
|
||||
def __init__(self, arch: str, config: str, sys_arch: str) -> None:
|
||||
"""
|
||||
arch: architecture to measure code size on.
|
||||
config: configuration type to measure code size with.
|
||||
make_command: command to build library (Inferred from arch and config).
|
||||
"""
|
||||
self.arch = arch
|
||||
self.config = config
|
||||
self.sys_arch = sys_arch
|
||||
self.make_command = self.set_make_command()
|
||||
|
||||
def set_make_command(self) -> str:
|
||||
"""Infer build command based on architecture and configuration."""
|
||||
|
||||
if self.config == SupportedConfig.DEFAULT.value and \
|
||||
self.arch == self.sys_arch:
|
||||
return 'make -j lib CFLAGS=\'-Os \' '
|
||||
elif self.arch == SupportedArch.ARMV8_M.value and \
|
||||
self.config == SupportedConfig.TFM_MEDIUM.value:
|
||||
return \
|
||||
'make -j lib CC=armclang \
|
||||
CFLAGS=\'--target=arm-arm-none-eabi -mcpu=cortex-m33 -Os \
|
||||
-DMBEDTLS_CONFIG_FILE=\\\"' + CONFIG_TFM_MEDIUM_MBEDCRYPTO_H + '\\\" \
|
||||
-DMBEDTLS_PSA_CRYPTO_CONFIG_FILE=\\\"' + CONFIG_TFM_MEDIUM_PSA_CRYPTO_H + '\\\" \''
|
||||
else:
|
||||
print("Unsupported combination of architecture: {} and configuration: {}"
|
||||
.format(self.arch, self.config))
|
||||
print("\nPlease use supported combination of architecture and configuration:")
|
||||
for comb in CodeSizeInfo.SupportedArchConfig:
|
||||
print(comb)
|
||||
print("\nFor your system, please use:")
|
||||
for comb in CodeSizeInfo.SupportedArchConfig:
|
||||
if "default" in comb and self.sys_arch not in comb:
|
||||
continue
|
||||
print(comb)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class CodeSizeComparison:
|
||||
"""Compare code size between two Git revisions."""
|
||||
|
||||
def __init__(self, old_revision, new_revision, result_dir):
|
||||
def __init__(self, old_revision, new_revision, result_dir, code_size_info):
|
||||
"""
|
||||
old_revision: revision to compare against
|
||||
old_revision: revision to compare against.
|
||||
new_revision:
|
||||
result_dir: directory for comparison result
|
||||
result_dir: directory for comparison result.
|
||||
code_size_info: an object containing information to build library.
|
||||
"""
|
||||
self.repo_path = "."
|
||||
self.result_dir = os.path.abspath(result_dir)
|
||||
|
@ -52,7 +135,9 @@ class CodeSizeComparison:
|
|||
self.old_rev = old_revision
|
||||
self.new_rev = new_revision
|
||||
self.git_command = "git"
|
||||
self.make_command = "make"
|
||||
self.make_command = code_size_info.make_command
|
||||
self.fname_suffix = "-" + code_size_info.arch + "-" +\
|
||||
code_size_info.config
|
||||
|
||||
@staticmethod
|
||||
def validate_revision(revision):
|
||||
|
@ -75,21 +160,25 @@ class CodeSizeComparison:
|
|||
git_worktree_path, revision], cwd=self.repo_path,
|
||||
stderr=subprocess.STDOUT
|
||||
)
|
||||
|
||||
return git_worktree_path
|
||||
|
||||
def _build_libraries(self, git_worktree_path):
|
||||
"""Build libraries in the specified worktree."""
|
||||
|
||||
my_environment = os.environ.copy()
|
||||
subprocess.check_output(
|
||||
[self.make_command, "-j", "lib"], env=my_environment,
|
||||
cwd=git_worktree_path, stderr=subprocess.STDOUT,
|
||||
)
|
||||
try:
|
||||
subprocess.check_output(
|
||||
self.make_command, env=my_environment, shell=True,
|
||||
cwd=git_worktree_path, stderr=subprocess.STDOUT,
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
self._handle_called_process_error(e, git_worktree_path)
|
||||
|
||||
def _gen_code_size_csv(self, revision, git_worktree_path):
|
||||
"""Generate code size csv file."""
|
||||
|
||||
csv_fname = revision + ".csv"
|
||||
csv_fname = revision + self.fname_suffix + ".csv"
|
||||
if revision == "current":
|
||||
print("Measuring code size in current work directory.")
|
||||
else:
|
||||
|
@ -117,7 +206,7 @@ class CodeSizeComparison:
|
|||
"""Generate code size csv file for the specified git revision."""
|
||||
|
||||
# Check if the corresponding record exists
|
||||
csv_fname = revision + ".csv"
|
||||
csv_fname = revision + self.fname_suffix + ".csv"
|
||||
if (revision != "current") and \
|
||||
os.path.exists(os.path.join(self.csv_dir, csv_fname)):
|
||||
print("Code size csv file for", revision, "already exists.")
|
||||
|
@ -132,16 +221,20 @@ class CodeSizeComparison:
|
|||
old and new. Measured code size results of these two revisions
|
||||
must be available."""
|
||||
|
||||
old_file = open(os.path.join(self.csv_dir, self.old_rev + ".csv"), "r")
|
||||
new_file = open(os.path.join(self.csv_dir, self.new_rev + ".csv"), "r")
|
||||
res_file = open(os.path.join(self.result_dir, "compare-" + self.old_rev
|
||||
+ "-" + self.new_rev + ".csv"), "w")
|
||||
old_file = open(os.path.join(self.csv_dir, self.old_rev +
|
||||
self.fname_suffix + ".csv"), "r")
|
||||
new_file = open(os.path.join(self.csv_dir, self.new_rev +
|
||||
self.fname_suffix + ".csv"), "r")
|
||||
res_file = open(os.path.join(self.result_dir, "compare-" +
|
||||
self.old_rev + "-" + self.new_rev +
|
||||
self.fname_suffix +
|
||||
".csv"), "w")
|
||||
|
||||
res_file.write("file_name, this_size, old_size, change, change %\n")
|
||||
print("Generating comparison results.")
|
||||
|
||||
old_ds = {}
|
||||
for line in old_file.readlines()[1:]:
|
||||
for line in old_file.readlines():
|
||||
cols = line.split(", ")
|
||||
fname = cols[0]
|
||||
size = int(cols[1])
|
||||
|
@ -149,7 +242,7 @@ class CodeSizeComparison:
|
|||
old_ds[fname] = size
|
||||
|
||||
new_ds = {}
|
||||
for line in new_file.readlines()[1:]:
|
||||
for line in new_file.readlines():
|
||||
cols = line.split(", ")
|
||||
fname = cols[0]
|
||||
size = int(cols[1])
|
||||
|
@ -175,30 +268,50 @@ class CodeSizeComparison:
|
|||
self._get_code_size_for_rev(self.new_rev)
|
||||
return self.compare_code_size()
|
||||
|
||||
def _handle_called_process_error(self, e: subprocess.CalledProcessError,
|
||||
git_worktree_path):
|
||||
"""Handle a CalledProcessError and quit the program gracefully.
|
||||
Remove any extra worktrees so that the script may be called again."""
|
||||
|
||||
# Tell the user what went wrong
|
||||
print("The following command: {} failed and exited with code {}"
|
||||
.format(e.cmd, e.returncode))
|
||||
print("Process output:\n {}".format(str(e.output, "utf-8")))
|
||||
|
||||
# Quit gracefully by removing the existing worktree
|
||||
self._remove_worktree(git_worktree_path)
|
||||
sys.exit(-1)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description=(
|
||||
"""This script is for comparing the size of the library files
|
||||
from two different Git revisions within an Mbed TLS repository.
|
||||
The results of the comparison is formatted as csv, and stored at
|
||||
a configurable location.
|
||||
Note: must be run from Mbed TLS root."""
|
||||
)
|
||||
)
|
||||
parser.add_argument(
|
||||
parser = argparse.ArgumentParser(description=(__doc__))
|
||||
group_required = parser.add_argument_group(
|
||||
'required arguments',
|
||||
'required arguments to parse for running ' + os.path.basename(__file__))
|
||||
group_required.add_argument(
|
||||
"-o", "--old-rev", type=str, required=True,
|
||||
help="old revision for comparison.")
|
||||
|
||||
group_optional = parser.add_argument_group(
|
||||
'optional arguments',
|
||||
'optional arguments to parse for running ' + os.path.basename(__file__))
|
||||
group_optional.add_argument(
|
||||
"-r", "--result-dir", type=str, default="comparison",
|
||||
help="directory where comparison result is stored, \
|
||||
default is comparison",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--old-rev", type=str, help="old revision for comparison.",
|
||||
required=True,
|
||||
)
|
||||
parser.add_argument(
|
||||
default is comparison")
|
||||
group_optional.add_argument(
|
||||
"-n", "--new-rev", type=str, default=None,
|
||||
help="new revision for comparison, default is the current work \
|
||||
directory, including uncommitted changes."
|
||||
)
|
||||
directory, including uncommitted changes.")
|
||||
group_optional.add_argument(
|
||||
"-a", "--arch", type=str, default=detect_arch(),
|
||||
choices=list(map(lambda s: s.value, SupportedArch)),
|
||||
help="specify architecture for code size comparison, default is the\
|
||||
host architecture.")
|
||||
group_optional.add_argument(
|
||||
"-c", "--config", type=str, default=SupportedConfig.DEFAULT.value,
|
||||
choices=list(map(lambda s: s.value, SupportedConfig)),
|
||||
help="specify configuration type for code size comparison,\
|
||||
default is the current MbedTLS configuration.")
|
||||
comp_args = parser.parse_args()
|
||||
|
||||
if os.path.isfile(comp_args.result_dir):
|
||||
|
@ -214,8 +327,13 @@ def main():
|
|||
else:
|
||||
new_revision = "current"
|
||||
|
||||
code_size_info = CodeSizeInfo(comp_args.arch, comp_args.config,
|
||||
detect_arch())
|
||||
print("Measure code size for architecture: {}, configuration: {}"
|
||||
.format(code_size_info.arch, code_size_info.config))
|
||||
result_dir = comp_args.result_dir
|
||||
size_compare = CodeSizeComparison(old_revision, new_revision, result_dir)
|
||||
size_compare = CodeSizeComparison(old_revision, new_revision, result_dir,
|
||||
code_size_info)
|
||||
return_code = size_compare.get_comparision_results()
|
||||
sys.exit(return_code)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"""Mbed TLS configuration file manipulation library and tool
|
||||
|
||||
Basic usage, to read the Mbed TLS or Mbed Crypto configuration:
|
||||
Basic usage, to read the Mbed TLS configuration:
|
||||
config = ConfigFile()
|
||||
if 'MBEDTLS_RSA_C' in config: print('RSA is enabled')
|
||||
"""
|
||||
|
@ -467,7 +467,7 @@ if __name__ == '__main__':
|
|||
def main():
|
||||
"""Command line mbedtls_config.h manipulation tool."""
|
||||
parser = argparse.ArgumentParser(description="""
|
||||
Mbed TLS and Mbed Crypto configuration file manipulation tool.
|
||||
Mbed TLS configuration file manipulation tool.
|
||||
""")
|
||||
parser.add_argument('--file', '-f',
|
||||
help="""File to read (and modify if requested).
|
||||
|
|
|
@ -80,6 +80,23 @@ def hex_digits_for_limb(limbs: int, bits_in_limb: int) -> int:
|
|||
""" Retrun the hex digits need for a number of limbs. """
|
||||
return 2 * (limbs * bits_in_limb // 8)
|
||||
|
||||
def hex_digits_max_int(val: str, bits_in_limb: int) -> int:
|
||||
""" Return the first number exceeding maximum the limb space
|
||||
required to store the input hex-string value. This method
|
||||
weights on the input str_len rather than numerical value
|
||||
and works with zero-padded inputs"""
|
||||
n = ((1 << (len(val) * 4)) - 1)
|
||||
l = limbs_mpi(n, bits_in_limb)
|
||||
return bound_mpi_limbs(l, bits_in_limb)
|
||||
|
||||
def zfill_match(reference: str, target: str) -> str:
|
||||
""" Zero pad target hex-string to match the limb size of
|
||||
the reference input """
|
||||
lt = len(target)
|
||||
lr = len(reference)
|
||||
target_len = lr if lt < lr else lt
|
||||
return "{:x}".format(int(target, 16)).zfill(target_len)
|
||||
|
||||
class OperationCommon(test_data_generation.BaseTest):
|
||||
"""Common features for bignum binary operations.
|
||||
|
||||
|
|
|
@ -68,6 +68,68 @@ class BignumCoreShiftR(BignumCoreTarget, test_data_generation.BaseTest):
|
|||
for count in counts:
|
||||
yield cls(input_hex, descr, count).create_test_case()
|
||||
|
||||
|
||||
class BignumCoreShiftL(BignumCoreTarget, bignum_common.ModOperationCommon):
|
||||
"""Test cases for mbedtls_bignum_core_shift_l()."""
|
||||
|
||||
BIT_SHIFT_VALUES = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
|
||||
'1f', '20', '21', '3f', '40', '41', '47', '48', '4f',
|
||||
'50', '51', '58', '80', '81', '88']
|
||||
DATA = ["0", "1", "40", "dee5ca1a7ef10a75", "a1055eb0bb1efa1150ff",
|
||||
"002e7ab0070ad57001", "020100000000000000001011121314151617",
|
||||
"1946e2958a85d8863ae21f4904fcc49478412534ed53eaf321f63f2a222"
|
||||
"7a3c63acbf50b6305595f90cfa8327f6db80d986fe96080bcbb5df1bdbe"
|
||||
"9b74fb8dedf2bddb3f8215b54dffd66409323bcc473e45a8fe9d08e77a51"
|
||||
"1698b5dad0416305db7fcf"]
|
||||
arity = 1
|
||||
test_function = "mpi_core_shift_l"
|
||||
test_name = "Core shift(L)"
|
||||
input_style = "arch_split"
|
||||
symbol = "<<"
|
||||
input_values = BIT_SHIFT_VALUES
|
||||
moduli = DATA
|
||||
|
||||
@property
|
||||
def val_n_max_limbs(self) -> int:
|
||||
""" Return the limb count required to store the maximum number that can
|
||||
fit in a the number of digits used by val_n """
|
||||
m = bignum_common.hex_digits_max_int(self.val_n, self.bits_in_limb) - 1
|
||||
return bignum_common.limbs_mpi(m, self.bits_in_limb)
|
||||
|
||||
def arguments(self) -> List[str]:
|
||||
return [bignum_common.quote_str(self.val_n),
|
||||
str(self.int_a)
|
||||
] + self.result()
|
||||
|
||||
def description(self) -> str:
|
||||
""" Format the output as:
|
||||
#{count} {hex input} ({input bits} {limbs capacity}) << {bit shift} """
|
||||
bits = "({} bits in {} limbs)".format(self.int_n.bit_length(), self.val_n_max_limbs)
|
||||
return "{} #{} {} {} {} {}".format(self.test_name,
|
||||
self.count,
|
||||
self.val_n,
|
||||
bits,
|
||||
self.symbol,
|
||||
self.int_a)
|
||||
|
||||
def format_result(self, res: int) -> str:
|
||||
# Override to match zero-pading for leading digits between the output and input.
|
||||
res_str = bignum_common.zfill_match(self.val_n, "{:x}".format(res))
|
||||
return bignum_common.quote_str(res_str)
|
||||
|
||||
def result(self) -> List[str]:
|
||||
result = (self.int_n << self.int_a)
|
||||
# Calculate if there is space for shifting to the left(leading zero limbs)
|
||||
mx = bignum_common.hex_digits_max_int(self.val_n, self.bits_in_limb)
|
||||
# If there are empty limbs ahead, adjust the bitmask accordingly
|
||||
result = result & (mx - 1)
|
||||
return [self.format_result(result)]
|
||||
|
||||
@property
|
||||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
class BignumCoreCTLookup(BignumCoreTarget, test_data_generation.BaseTest):
|
||||
"""Test cases for mbedtls_mpi_core_ct_uint_table_lookup()."""
|
||||
test_function = "mpi_core_ct_uint_table_lookup"
|
||||
|
|
|
@ -97,7 +97,7 @@ class EcpP192R1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
def arguments(self)-> List[str]:
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP192R1"] + args
|
||||
|
||||
|
@ -174,7 +174,7 @@ class EcpP224R1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
def arguments(self)-> List[str]:
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP224R1"] + args
|
||||
|
||||
|
@ -258,7 +258,7 @@ class EcpP256R1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
def arguments(self)-> List[str]:
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP256R1"] + args
|
||||
|
||||
|
@ -380,7 +380,7 @@ class EcpP384R1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
def arguments(self)-> List[str]:
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP384R1"] + args
|
||||
|
||||
|
@ -485,7 +485,7 @@ class EcpP521R1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
def arguments(self)-> List[str]:
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP521R1"] + args
|
||||
|
||||
|
@ -494,8 +494,8 @@ class EcpP192K1Raw(bignum_common.ModOperationCommon,
|
|||
EcpTarget):
|
||||
"""Test cases for ECP P192K1 fast reduction."""
|
||||
symbol = "-"
|
||||
test_function = "ecp_mod_p192k1"
|
||||
test_name = "ecp_mod_p192k1"
|
||||
test_function = "ecp_mod_p_generic_raw"
|
||||
test_name = "ecp_mod_p192k1_raw"
|
||||
input_style = "fixed"
|
||||
arity = 1
|
||||
dependencies = ["MBEDTLS_ECP_DP_SECP192K1_ENABLED"]
|
||||
|
@ -518,6 +518,10 @@ class EcpP192K1Raw(bignum_common.ModOperationCommon,
|
|||
("fffffffffffffffffffffffffffffffffffffffdffffdc6c"
|
||||
"0000000000000000000000000000000100002394013c7364"),
|
||||
|
||||
# Test case for overflow during addition
|
||||
("00000007ffff71b809e27dd832cfd5e04d9d2dbb9f8da217"
|
||||
"0000000000000000000000000000000000000000520834f0"),
|
||||
|
||||
# First 8 number generated by random.getrandbits(384) - seed(2,2)
|
||||
("cf1822ffbc6887782b491044d5e341245c6e433715ba2bdd"
|
||||
"177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"),
|
||||
|
@ -553,13 +557,17 @@ class EcpP192K1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP192K1"] + args
|
||||
|
||||
|
||||
class EcpP224K1Raw(bignum_common.ModOperationCommon,
|
||||
EcpTarget):
|
||||
"""Test cases for ECP P224 fast reduction."""
|
||||
symbol = "-"
|
||||
test_function = "ecp_mod_p224k1"
|
||||
test_name = "ecp_mod_p224k1"
|
||||
test_function = "ecp_mod_p_generic_raw"
|
||||
test_name = "ecp_mod_p224k1_raw"
|
||||
input_style = "fixed"
|
||||
arity = 1
|
||||
dependencies = ["MBEDTLS_ECP_DP_SECP224K1_ENABLED"]
|
||||
|
@ -578,10 +586,14 @@ class EcpP224K1Raw(bignum_common.ModOperationCommon,
|
|||
# 2^224 - 1
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
|
||||
# Maximum canonical P224 multiplication result
|
||||
# Maximum canonical P224K1 multiplication result
|
||||
("fffffffffffffffffffffffffffffffffffffffffffffffdffffcad8"
|
||||
"00000000000000000000000000000000000000010000352802c26590"),
|
||||
|
||||
# Test case for overflow during addition
|
||||
("0000007ffff2b68161180fd8cd92e1a109be158a19a99b1809db8032"
|
||||
"0000000000000000000000000000000000000000000000000bf04f49"),
|
||||
|
||||
# First 8 number generated by random.getrandbits(448) - seed(2,2)
|
||||
("da94e3e8ab73738fcf1822ffbc6887782b491044d5e341245c6e4337"
|
||||
"15ba2bdd177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"),
|
||||
|
@ -618,13 +630,17 @@ class EcpP224K1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP224K1"] + args
|
||||
|
||||
|
||||
class EcpP256K1Raw(bignum_common.ModOperationCommon,
|
||||
EcpTarget):
|
||||
"""Test cases for ECP P256 fast reduction."""
|
||||
symbol = "-"
|
||||
test_function = "ecp_mod_p256k1"
|
||||
test_name = "ecp_mod_p256k1"
|
||||
test_function = "ecp_mod_p_generic_raw"
|
||||
test_name = "ecp_mod_p256k1_raw"
|
||||
input_style = "fixed"
|
||||
arity = 1
|
||||
dependencies = ["MBEDTLS_ECP_DP_SECP256K1_ENABLED"]
|
||||
|
@ -643,9 +659,17 @@ class EcpP256K1Raw(bignum_common.ModOperationCommon,
|
|||
# 2^256 - 1
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
|
||||
# Maximum canonical P256 multiplication result
|
||||
("fffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffff85c0"
|
||||
"00000000000000000000000000000000000000000000001000007a4000e9844"),
|
||||
# Maximum canonical P256K1 multiplication result
|
||||
("fffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffff85c"
|
||||
"000000000000000000000000000000000000000000000001000007a4000e9844"),
|
||||
|
||||
# Test case for overflow during addition
|
||||
("0000fffffc2f000e90a0c86a0a63234e5ba641f43a7e4aecc4040e67ec850562"
|
||||
"00000000000000000000000000000000000000000000000000000000585674fd"),
|
||||
|
||||
# Test case for overflow during addition
|
||||
("0000fffffc2f000e90a0c86a0a63234e5ba641f43a7e4aecc4040e67ec850562"
|
||||
"00000000000000000000000000000000000000000000000000000000585674fd"),
|
||||
|
||||
# First 8 number generated by random.getrandbits(512) - seed(2,2)
|
||||
("4067c3584ee207f8da94e3e8ab73738fcf1822ffbc6887782b491044d5e34124"
|
||||
|
@ -672,8 +696,7 @@ class EcpP256K1Raw(bignum_common.ModOperationCommon,
|
|||
|
||||
@property
|
||||
def arg_a(self) -> str:
|
||||
hex_digits = bignum_common.hex_digits_for_limb(448 // self.bits_in_limb, self.bits_in_limb)
|
||||
return super().format_arg('{:x}'.format(self.int_a)).zfill(hex_digits)
|
||||
return super().format_arg('{:x}'.format(self.int_a)).zfill(2 * self.hex_digits)
|
||||
|
||||
def result(self) -> List[str]:
|
||||
result = self.int_a % self.int_n
|
||||
|
@ -683,6 +706,79 @@ class EcpP256K1Raw(bignum_common.ModOperationCommon,
|
|||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self):
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_SECP256K1"] + args
|
||||
|
||||
|
||||
class EcpP255Raw(bignum_common.ModOperationCommon,
|
||||
EcpTarget):
|
||||
"""Test cases for ECP 25519 fast reduction."""
|
||||
symbol = "-"
|
||||
test_function = "ecp_mod_p_generic_raw"
|
||||
test_name = "mbedtls_ecp_mod_p255_raw"
|
||||
input_style = "fixed"
|
||||
arity = 1
|
||||
dependencies = ["MBEDTLS_ECP_DP_CURVE25519_ENABLED"]
|
||||
|
||||
moduli = [("7fffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
"ffffffffffffed")] # type: List[str]
|
||||
|
||||
input_values = [
|
||||
"0", "1",
|
||||
|
||||
# Modulus - 1
|
||||
("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
||||
|
||||
# Modulus + 1
|
||||
("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee"),
|
||||
|
||||
# 2^255 - 1
|
||||
("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
|
||||
|
||||
# Maximum canonical P255 multiplication result
|
||||
("3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"
|
||||
"0000000000000000000000000000000000000000000000000000000000000190"),
|
||||
|
||||
# First 8 number generated by random.getrandbits(510) - seed(2,2)
|
||||
("1019f0d64ee207f8da94e3e8ab73738fcf1822ffbc6887782b491044d5e34124"
|
||||
"5c6e433715ba2bdd177219d30e7a269fd95bafc8f2a4d27bdcf4bb99f4bea973"),
|
||||
("20948fa1feac7eb7dc38f519b91751dacdbd47d364be8049a372db8f6e405d93"
|
||||
"ffed9235288bc781ae66267594c9c9500925e4749b575bd13653f8dd9b1f282e"),
|
||||
("3a1893ea5186ee32ee8d7ee9770348a05d300cb90706a045defc044a09325626"
|
||||
"e6b58de744ab6cce80877b6f71e1f6d2ef8acd128b4f2fc15f3f57ebf30b94fa"),
|
||||
("20a6923522fe99a22c70501e533c91352d3d854e061b90303b08c6e33c729578"
|
||||
"2d6c797f8f7d9b782a1be9cd8697bbd0e2520e33e44c50556c71c4a66148a86f"),
|
||||
("3a248138e8168561867e5e15bc01bfce6a27e0dfcbf8754472154e76e4c11ab2"
|
||||
"fec3f6b32e8d4b8a8f54f8ceacaab39e83844b40ffa9b9f15c14bc4a829e07b0"),
|
||||
("2f450feab714210c665d7435c1066932f4767f26294365b2721dea3bf63f23d0"
|
||||
"dbe53fcafb2147df5ca495fa5a91c89b97eeab64ca2ce6bc5d3fd983c34c769f"),
|
||||
("1d199effe202849da9643a295a9ac6decbd4d3e2d4dec9ef83f0be4e80371eb9"
|
||||
"7f81375eecc1cb6347733e847d718d733ff98ff387c56473a7a83ee0761ebfd2"),
|
||||
("3423c6ec531d6460f0caeef038c89b38a8acb5137c9260dc74e088a9b9492f25"
|
||||
"8ebdbfe3eb9ac688b9d39cca91551e8259cc60b17604e4b4e73695c3e652c71a"),
|
||||
|
||||
# Next 2 number generated by random.getrandbits(255)
|
||||
("62f1243644a4a8f69dc8db48e86ec9c6e06f291b2a838af8d5c44a4eb3172062"),
|
||||
("6a606e54b4c9e755cc9c3adcf515a8234da4daeb4f3f87777ad1f45ae9500ec9"),
|
||||
]
|
||||
|
||||
@property
|
||||
def arg_a(self) -> str:
|
||||
return super().format_arg('{:x}'.format(self.int_a)).zfill(2 * self.hex_digits)
|
||||
|
||||
def result(self) -> List[str]:
|
||||
result = self.int_a % self.int_n
|
||||
return [self.format_result(result)]
|
||||
|
||||
@property
|
||||
def is_valid(self) -> bool:
|
||||
return True
|
||||
|
||||
def arguments(self)-> List[str]:
|
||||
args = super().arguments()
|
||||
return ["MBEDTLS_ECP_DP_CURVE25519"] + args
|
||||
|
||||
|
||||
class EcpP448Raw(bignum_common.ModOperationCommon,
|
||||
EcpTarget):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue