mirror of
https://github.com/espressif/mbedtls.git
synced 2025-06-14 08:52:37 +08:00
Merge pull request #7503 from gilles-peskine-arm/test-argument-types-union-2.28
Backport 2.28: Support larger integer test arguments
This commit is contained in:
commit
5ead738269
43
tests/include/test/arguments.h
Normal file
43
tests/include/test/arguments.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* \file arguments.h
|
||||||
|
*
|
||||||
|
* \brief Manipulation of test arguments.
|
||||||
|
*
|
||||||
|
* Much of the code is in host_test.function, to be migrated here later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright The Mbed TLS Contributors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_ARGUMENTS_H
|
||||||
|
#define TEST_ARGUMENTS_H
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||||
|
#include "mbedtls/config.h"
|
||||||
|
#else
|
||||||
|
#include MBEDTLS_CONFIG_FILE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
size_t len;
|
||||||
|
intmax_t sint;
|
||||||
|
} mbedtls_test_argument_t;
|
||||||
|
|
||||||
|
#endif /* TEST_ARGUMENTS_H */
|
@ -196,7 +196,7 @@ class BignumOperation(BignumTarget, metaclass=ABCMeta):
|
|||||||
class BignumCmp(BignumOperation):
|
class BignumCmp(BignumOperation):
|
||||||
"""Test cases for bignum value comparison."""
|
"""Test cases for bignum value comparison."""
|
||||||
count = 0
|
count = 0
|
||||||
test_function = "mbedtls_mpi_cmp_mpi"
|
test_function = "mpi_cmp_mpi"
|
||||||
test_name = "MPI compare"
|
test_name = "MPI compare"
|
||||||
input_cases = [
|
input_cases = [
|
||||||
("-2", "-3"),
|
("-2", "-3"),
|
||||||
@ -217,7 +217,7 @@ class BignumCmp(BignumOperation):
|
|||||||
class BignumCmpAbs(BignumCmp):
|
class BignumCmpAbs(BignumCmp):
|
||||||
"""Test cases for absolute bignum value comparison."""
|
"""Test cases for absolute bignum value comparison."""
|
||||||
count = 0
|
count = 0
|
||||||
test_function = "mbedtls_mpi_cmp_abs"
|
test_function = "mpi_cmp_abs"
|
||||||
test_name = "MPI compare (abs)"
|
test_name = "MPI compare (abs)"
|
||||||
|
|
||||||
def __init__(self, val_a, val_b) -> None:
|
def __init__(self, val_a, val_b) -> None:
|
||||||
@ -228,7 +228,7 @@ class BignumAdd(BignumOperation):
|
|||||||
"""Test cases for bignum value addition."""
|
"""Test cases for bignum value addition."""
|
||||||
count = 0
|
count = 0
|
||||||
symbol = "+"
|
symbol = "+"
|
||||||
test_function = "mbedtls_mpi_add_mpi"
|
test_function = "mpi_add_mpi"
|
||||||
test_name = "MPI add"
|
test_name = "MPI add"
|
||||||
input_cases = combination_pairs(
|
input_cases = combination_pairs(
|
||||||
[
|
[
|
||||||
|
@ -171,6 +171,28 @@ import string
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
# Types recognized as signed integer arguments in test functions.
|
||||||
|
SIGNED_INTEGER_TYPES = frozenset([
|
||||||
|
'char',
|
||||||
|
'short',
|
||||||
|
'short int',
|
||||||
|
'int',
|
||||||
|
'int8_t',
|
||||||
|
'int16_t',
|
||||||
|
'int32_t',
|
||||||
|
'int64_t',
|
||||||
|
'intmax_t',
|
||||||
|
'long',
|
||||||
|
'long int',
|
||||||
|
'long long int',
|
||||||
|
'mbedtls_mpi_sint',
|
||||||
|
'psa_status_t',
|
||||||
|
])
|
||||||
|
# Types recognized as string arguments in test functions.
|
||||||
|
STRING_TYPES = frozenset(['char*', 'const char*', 'char const*'])
|
||||||
|
# Types recognized as hex data arguments in test functions.
|
||||||
|
DATA_TYPES = frozenset(['data_t*', 'const data_t*', 'data_t const*'])
|
||||||
|
|
||||||
BEGIN_HEADER_REGEX = r'/\*\s*BEGIN_HEADER\s*\*/'
|
BEGIN_HEADER_REGEX = r'/\*\s*BEGIN_HEADER\s*\*/'
|
||||||
END_HEADER_REGEX = r'/\*\s*END_HEADER\s*\*/'
|
END_HEADER_REGEX = r'/\*\s*END_HEADER\s*\*/'
|
||||||
|
|
||||||
@ -192,9 +214,6 @@ CONDITION_REGEX = r'({})(?:\s*({})\s*({}))?$'.format(C_IDENTIFIER_REGEX,
|
|||||||
CONDITION_OPERATOR_REGEX,
|
CONDITION_OPERATOR_REGEX,
|
||||||
CONDITION_VALUE_REGEX)
|
CONDITION_VALUE_REGEX)
|
||||||
TEST_FUNCTION_VALIDATION_REGEX = r'\s*void\s+(?P<func_name>\w+)\s*\('
|
TEST_FUNCTION_VALIDATION_REGEX = r'\s*void\s+(?P<func_name>\w+)\s*\('
|
||||||
INT_CHECK_REGEX = r'int\s+.*'
|
|
||||||
CHAR_CHECK_REGEX = r'char\s*\*\s*.*'
|
|
||||||
DATA_T_CHECK_REGEX = r'data_t\s*\*\s*.*'
|
|
||||||
FUNCTION_ARG_LIST_END_REGEX = r'.*\)'
|
FUNCTION_ARG_LIST_END_REGEX = r'.*\)'
|
||||||
EXIT_LABEL_REGEX = r'^exit:'
|
EXIT_LABEL_REGEX = r'^exit:'
|
||||||
|
|
||||||
@ -303,7 +322,7 @@ def gen_function_wrapper(name, local_vars, args_dispatch):
|
|||||||
:param name: Test function name
|
:param name: Test function name
|
||||||
:param local_vars: Local variables declaration code
|
:param local_vars: Local variables declaration code
|
||||||
:param args_dispatch: List of dispatch arguments.
|
:param args_dispatch: List of dispatch arguments.
|
||||||
Ex: ['(char *)params[0]', '*((int *)params[1])']
|
Ex: ['(char *) params[0]', '*((int *) params[1])']
|
||||||
:return: Test function wrapper.
|
:return: Test function wrapper.
|
||||||
"""
|
"""
|
||||||
# Then create the wrapper
|
# Then create the wrapper
|
||||||
@ -444,6 +463,49 @@ def parse_function_dependencies(line):
|
|||||||
return dependencies
|
return dependencies
|
||||||
|
|
||||||
|
|
||||||
|
ARGUMENT_DECLARATION_REGEX = re.compile(r'(.+?) ?(?:\bconst\b)? ?(\w+)\Z', re.S)
|
||||||
|
def parse_function_argument(arg, arg_idx, args, local_vars, args_dispatch):
|
||||||
|
"""
|
||||||
|
Parses one test function's argument declaration.
|
||||||
|
|
||||||
|
:param arg: argument declaration.
|
||||||
|
:param arg_idx: current wrapper argument index.
|
||||||
|
:param args: accumulator of arguments' internal types.
|
||||||
|
:param local_vars: accumulator of internal variable declarations.
|
||||||
|
:param args_dispatch: accumulator of argument usage expressions.
|
||||||
|
:return: the number of new wrapper arguments,
|
||||||
|
or None if the argument declaration is invalid.
|
||||||
|
"""
|
||||||
|
# Normalize whitespace
|
||||||
|
arg = arg.strip()
|
||||||
|
arg = re.sub(r'\s*\*\s*', r'*', arg)
|
||||||
|
arg = re.sub(r'\s+', r' ', arg)
|
||||||
|
# Extract name and type
|
||||||
|
m = ARGUMENT_DECLARATION_REGEX.search(arg)
|
||||||
|
if not m:
|
||||||
|
# E.g. "int x[42]"
|
||||||
|
return None
|
||||||
|
typ, _ = m.groups()
|
||||||
|
if typ in SIGNED_INTEGER_TYPES:
|
||||||
|
args.append('int')
|
||||||
|
args_dispatch.append('((mbedtls_test_argument_t *) params[%d])->sint' % arg_idx)
|
||||||
|
return 1
|
||||||
|
if typ in STRING_TYPES:
|
||||||
|
args.append('char*')
|
||||||
|
args_dispatch.append('(char *) params[%d]' % arg_idx)
|
||||||
|
return 1
|
||||||
|
if typ in DATA_TYPES:
|
||||||
|
args.append('hex')
|
||||||
|
# create a structure
|
||||||
|
pointer_initializer = '(uint8_t *) params[%d]' % arg_idx
|
||||||
|
len_initializer = '((mbedtls_test_argument_t *) params[%d])->len' % (arg_idx+1)
|
||||||
|
local_vars.append(' data_t data%d = {%s, %s};\n' %
|
||||||
|
(arg_idx, pointer_initializer, len_initializer))
|
||||||
|
args_dispatch.append('&data%d' % arg_idx)
|
||||||
|
return 2
|
||||||
|
return None
|
||||||
|
|
||||||
|
ARGUMENT_LIST_REGEX = re.compile(r'\((.*?)\)', re.S)
|
||||||
def parse_function_arguments(line):
|
def parse_function_arguments(line):
|
||||||
"""
|
"""
|
||||||
Parses test function signature for validation and generates
|
Parses test function signature for validation and generates
|
||||||
@ -455,42 +517,27 @@ def parse_function_arguments(line):
|
|||||||
:return: argument list, local variables for
|
:return: argument list, local variables for
|
||||||
wrapper function and argument dispatch code.
|
wrapper function and argument dispatch code.
|
||||||
"""
|
"""
|
||||||
args = []
|
|
||||||
local_vars = ''
|
|
||||||
args_dispatch = []
|
|
||||||
arg_idx = 0
|
|
||||||
# Remove characters before arguments
|
|
||||||
line = line[line.find('(') + 1:]
|
|
||||||
# Process arguments, ex: <type> arg1, <type> arg2 )
|
# Process arguments, ex: <type> arg1, <type> arg2 )
|
||||||
# This script assumes that the argument list is terminated by ')'
|
# This script assumes that the argument list is terminated by ')'
|
||||||
# i.e. the test functions will not have a function pointer
|
# i.e. the test functions will not have a function pointer
|
||||||
# argument.
|
# argument.
|
||||||
for arg in line[:line.find(')')].split(','):
|
m = ARGUMENT_LIST_REGEX.search(line)
|
||||||
arg = arg.strip()
|
arg_list = m.group(1).strip()
|
||||||
if arg == '':
|
if arg_list in ['', 'void']:
|
||||||
continue
|
return [], '', []
|
||||||
if re.search(INT_CHECK_REGEX, arg.strip()):
|
args = []
|
||||||
args.append('int')
|
local_vars = []
|
||||||
args_dispatch.append('*( (int *) params[%d] )' % arg_idx)
|
args_dispatch = []
|
||||||
elif re.search(CHAR_CHECK_REGEX, arg.strip()):
|
arg_idx = 0
|
||||||
args.append('char*')
|
for arg in arg_list.split(','):
|
||||||
args_dispatch.append('(char *) params[%d]' % arg_idx)
|
indexes = parse_function_argument(arg, arg_idx,
|
||||||
elif re.search(DATA_T_CHECK_REGEX, arg.strip()):
|
args, local_vars, args_dispatch)
|
||||||
args.append('hex')
|
if indexes is None:
|
||||||
# create a structure
|
|
||||||
pointer_initializer = '(uint8_t *) params[%d]' % arg_idx
|
|
||||||
len_initializer = '*( (uint32_t *) params[%d] )' % (arg_idx+1)
|
|
||||||
local_vars += """ data_t data%d = {%s, %s};
|
|
||||||
""" % (arg_idx, pointer_initializer, len_initializer)
|
|
||||||
|
|
||||||
args_dispatch.append('&data%d' % arg_idx)
|
|
||||||
arg_idx += 1
|
|
||||||
else:
|
|
||||||
raise ValueError("Test function arguments can only be 'int', "
|
raise ValueError("Test function arguments can only be 'int', "
|
||||||
"'char *' or 'data_t'\n%s" % line)
|
"'char *' or 'data_t'\n%s" % line)
|
||||||
arg_idx += 1
|
arg_idx += indexes
|
||||||
|
|
||||||
return args, local_vars, args_dispatch
|
return args, ''.join(local_vars), args_dispatch
|
||||||
|
|
||||||
|
|
||||||
def generate_function_code(name, code, local_vars, args_dispatch,
|
def generate_function_code(name, code, local_vars, args_dispatch,
|
||||||
@ -705,7 +752,7 @@ def parse_test_data(data_f):
|
|||||||
execution.
|
execution.
|
||||||
|
|
||||||
:param data_f: file object of the data file.
|
:param data_f: file object of the data file.
|
||||||
:return: Generator that yields test name, function name,
|
:return: Generator that yields line number, test name, function name,
|
||||||
dependency list and function argument list.
|
dependency list and function argument list.
|
||||||
"""
|
"""
|
||||||
__state_read_name = 0
|
__state_read_name = 0
|
||||||
@ -748,7 +795,7 @@ def parse_test_data(data_f):
|
|||||||
parts = escaped_split(line, ':')
|
parts = escaped_split(line, ':')
|
||||||
test_function = parts[0]
|
test_function = parts[0]
|
||||||
args = parts[1:]
|
args = parts[1:]
|
||||||
yield name, test_function, dependencies, args
|
yield data_f.line_no, name, test_function, dependencies, args
|
||||||
dependencies = []
|
dependencies = []
|
||||||
state = __state_read_name
|
state = __state_read_name
|
||||||
if state == __state_read_args:
|
if state == __state_read_args:
|
||||||
@ -846,6 +893,14 @@ def write_dependencies(out_data_f, test_dependencies, unique_dependencies):
|
|||||||
return dep_check_code
|
return dep_check_code
|
||||||
|
|
||||||
|
|
||||||
|
INT_VAL_REGEX = re.compile(r'-?(\d+|0x[0-9a-f]+)$', re.I)
|
||||||
|
def val_is_int(val: str) -> bool:
|
||||||
|
"""Whether val is suitable as an 'int' parameter in the .datax file."""
|
||||||
|
if not INT_VAL_REGEX.match(val):
|
||||||
|
return False
|
||||||
|
# Limit the range to what is guaranteed to get through strtol()
|
||||||
|
return abs(int(val, 0)) <= 0x7fffffff
|
||||||
|
|
||||||
def write_parameters(out_data_f, test_args, func_args, unique_expressions):
|
def write_parameters(out_data_f, test_args, func_args, unique_expressions):
|
||||||
"""
|
"""
|
||||||
Writes test parameters to the intermediate data file, replacing
|
Writes test parameters to the intermediate data file, replacing
|
||||||
@ -864,9 +919,9 @@ def write_parameters(out_data_f, test_args, func_args, unique_expressions):
|
|||||||
typ = func_args[i]
|
typ = func_args[i]
|
||||||
val = test_args[i]
|
val = test_args[i]
|
||||||
|
|
||||||
# check if val is a non literal int val (i.e. an expression)
|
# Pass small integer constants literally. This reduces the size of
|
||||||
if typ == 'int' and not re.match(r'(\d+|0x[0-9a-f]+)$',
|
# the C code. Register anything else as an expression.
|
||||||
val, re.I):
|
if typ == 'int' and not val_is_int(val):
|
||||||
typ = 'exp'
|
typ = 'exp'
|
||||||
if val not in unique_expressions:
|
if val not in unique_expressions:
|
||||||
unique_expressions.append(val)
|
unique_expressions.append(val)
|
||||||
@ -909,6 +964,24 @@ def gen_suite_dep_checks(suite_dependencies, dep_check_code, expression_code):
|
|||||||
return dep_check_code, expression_code
|
return dep_check_code, expression_code
|
||||||
|
|
||||||
|
|
||||||
|
def get_function_info(func_info, function_name, line_no):
|
||||||
|
"""Look up information about a test function by name.
|
||||||
|
|
||||||
|
Raise an informative expression if function_name is not found.
|
||||||
|
|
||||||
|
:param func_info: dictionary mapping function names to their information.
|
||||||
|
:param function_name: the function name as written in the .function and
|
||||||
|
.data files.
|
||||||
|
:param line_no: line number for error messages.
|
||||||
|
:return Function information (id, args).
|
||||||
|
"""
|
||||||
|
test_function_name = 'test_' + function_name
|
||||||
|
if test_function_name not in func_info:
|
||||||
|
raise GeneratorInputError("%d: Function %s not found!" %
|
||||||
|
(line_no, test_function_name))
|
||||||
|
return func_info[test_function_name]
|
||||||
|
|
||||||
|
|
||||||
def gen_from_test_data(data_f, out_data_f, func_info, suite_dependencies):
|
def gen_from_test_data(data_f, out_data_f, func_info, suite_dependencies):
|
||||||
"""
|
"""
|
||||||
This function reads test case name, dependencies and test vectors
|
This function reads test case name, dependencies and test vectors
|
||||||
@ -931,7 +1004,7 @@ def gen_from_test_data(data_f, out_data_f, func_info, suite_dependencies):
|
|||||||
unique_expressions = []
|
unique_expressions = []
|
||||||
dep_check_code = ''
|
dep_check_code = ''
|
||||||
expression_code = ''
|
expression_code = ''
|
||||||
for test_name, function_name, test_dependencies, test_args in \
|
for line_no, test_name, function_name, test_dependencies, test_args in \
|
||||||
parse_test_data(data_f):
|
parse_test_data(data_f):
|
||||||
out_data_f.write(test_name + '\n')
|
out_data_f.write(test_name + '\n')
|
||||||
|
|
||||||
@ -940,18 +1013,15 @@ def gen_from_test_data(data_f, out_data_f, func_info, suite_dependencies):
|
|||||||
unique_dependencies)
|
unique_dependencies)
|
||||||
|
|
||||||
# Write test function name
|
# Write test function name
|
||||||
test_function_name = 'test_' + function_name
|
func_id, func_args = \
|
||||||
if test_function_name not in func_info:
|
get_function_info(func_info, function_name, line_no)
|
||||||
raise GeneratorInputError("Function %s not found!" %
|
|
||||||
test_function_name)
|
|
||||||
func_id, func_args = func_info[test_function_name]
|
|
||||||
out_data_f.write(str(func_id))
|
out_data_f.write(str(func_id))
|
||||||
|
|
||||||
# Write parameters
|
# Write parameters
|
||||||
if len(test_args) != len(func_args):
|
if len(test_args) != len(func_args):
|
||||||
raise GeneratorInputError("Invalid number of arguments in test "
|
raise GeneratorInputError("%d: Invalid number of arguments in test "
|
||||||
"%s. See function %s signature." %
|
"%s. See function %s signature." %
|
||||||
(test_name, function_name))
|
(line_no, test_name, function_name))
|
||||||
expression_code += write_parameters(out_data_f, test_args, func_args,
|
expression_code += write_parameters(out_data_f, test_args, func_args,
|
||||||
unique_expressions)
|
unique_expressions)
|
||||||
|
|
||||||
|
@ -485,9 +485,10 @@ class ParseFuncSignature(TestCase):
|
|||||||
args, local, arg_dispatch = parse_function_arguments(line)
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
self.assertEqual(args, ['char*', 'int', 'int'])
|
self.assertEqual(args, ['char*', 'int', 'int'])
|
||||||
self.assertEqual(local, '')
|
self.assertEqual(local, '')
|
||||||
self.assertEqual(arg_dispatch, ['(char *) params[0]',
|
self.assertEqual(arg_dispatch,
|
||||||
'*( (int *) params[1] )',
|
['(char *) params[0]',
|
||||||
'*( (int *) params[2] )'])
|
'((mbedtls_test_argument_t *) params[1])->sint',
|
||||||
|
'((mbedtls_test_argument_t *) params[2])->sint'])
|
||||||
|
|
||||||
def test_hex_params(self):
|
def test_hex_params(self):
|
||||||
"""
|
"""
|
||||||
@ -499,22 +500,22 @@ class ParseFuncSignature(TestCase):
|
|||||||
self.assertEqual(args, ['char*', 'hex', 'int'])
|
self.assertEqual(args, ['char*', 'hex', 'int'])
|
||||||
self.assertEqual(local,
|
self.assertEqual(local,
|
||||||
' data_t data1 = {(uint8_t *) params[1], '
|
' data_t data1 = {(uint8_t *) params[1], '
|
||||||
'*( (uint32_t *) params[2] )};\n')
|
'((mbedtls_test_argument_t *) params[2])->len};\n')
|
||||||
self.assertEqual(arg_dispatch, ['(char *) params[0]',
|
self.assertEqual(arg_dispatch, ['(char *) params[0]',
|
||||||
'&data1',
|
'&data1',
|
||||||
'*( (int *) params[3] )'])
|
'((mbedtls_test_argument_t *) params[3])->sint'])
|
||||||
|
|
||||||
def test_unsupported_arg(self):
|
def test_unsupported_arg(self):
|
||||||
"""
|
"""
|
||||||
Test unsupported arguments (not among int, char * and data_t)
|
Test unsupported argument type
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
line = 'void entropy_threshold( char * a, data_t * h, char result )'
|
line = 'void entropy_threshold( char * a, data_t * h, unknown_t result )'
|
||||||
self.assertRaises(ValueError, parse_function_arguments, line)
|
self.assertRaises(ValueError, parse_function_arguments, line)
|
||||||
|
|
||||||
def test_no_params(self):
|
def test_empty_params(self):
|
||||||
"""
|
"""
|
||||||
Test no parameters.
|
Test no parameters (nothing between parentheses).
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
line = 'void entropy_threshold()'
|
line = 'void entropy_threshold()'
|
||||||
@ -523,6 +524,39 @@ class ParseFuncSignature(TestCase):
|
|||||||
self.assertEqual(local, '')
|
self.assertEqual(local, '')
|
||||||
self.assertEqual(arg_dispatch, [])
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
def test_blank_params(self):
|
||||||
|
"""
|
||||||
|
Test no parameters (space between parentheses).
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
line = 'void entropy_threshold( )'
|
||||||
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
|
self.assertEqual(args, [])
|
||||||
|
self.assertEqual(local, '')
|
||||||
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
def test_void_params(self):
|
||||||
|
"""
|
||||||
|
Test no parameters (void keyword).
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
line = 'void entropy_threshold(void)'
|
||||||
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
|
self.assertEqual(args, [])
|
||||||
|
self.assertEqual(local, '')
|
||||||
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
def test_void_space_params(self):
|
||||||
|
"""
|
||||||
|
Test no parameters (void with spaces).
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
line = 'void entropy_threshold( void )'
|
||||||
|
args, local, arg_dispatch = parse_function_arguments(line)
|
||||||
|
self.assertEqual(args, [])
|
||||||
|
self.assertEqual(local, '')
|
||||||
|
self.assertEqual(arg_dispatch, [])
|
||||||
|
|
||||||
|
|
||||||
class ParseFunctionCode(TestCase):
|
class ParseFunctionCode(TestCase):
|
||||||
"""
|
"""
|
||||||
@ -1264,29 +1298,33 @@ dhm_selftest:
|
|||||||
# List of (name, function_name, dependencies, args)
|
# List of (name, function_name, dependencies, args)
|
||||||
tests = list(parse_test_data(stream))
|
tests = list(parse_test_data(stream))
|
||||||
test1, test2, test3, test4 = tests
|
test1, test2, test3, test4 = tests
|
||||||
self.assertEqual(test1[0], 'Diffie-Hellman full exchange #1')
|
self.assertEqual(test1[0], 3)
|
||||||
self.assertEqual(test1[1], 'dhm_do_dhm')
|
self.assertEqual(test1[1], 'Diffie-Hellman full exchange #1')
|
||||||
self.assertEqual(test1[2], [])
|
self.assertEqual(test1[2], 'dhm_do_dhm')
|
||||||
self.assertEqual(test1[3], ['10', '"23"', '10', '"5"'])
|
self.assertEqual(test1[3], [])
|
||||||
|
self.assertEqual(test1[4], ['10', '"23"', '10', '"5"'])
|
||||||
|
|
||||||
self.assertEqual(test2[0], 'Diffie-Hellman full exchange #2')
|
self.assertEqual(test2[0], 6)
|
||||||
self.assertEqual(test2[1], 'dhm_do_dhm')
|
self.assertEqual(test2[1], 'Diffie-Hellman full exchange #2')
|
||||||
self.assertEqual(test2[2], [])
|
self.assertEqual(test2[2], 'dhm_do_dhm')
|
||||||
self.assertEqual(test2[3], ['10', '"93450983094850938450983409623"',
|
self.assertEqual(test2[3], [])
|
||||||
|
self.assertEqual(test2[4], ['10', '"93450983094850938450983409623"',
|
||||||
'10', '"9345098304850938450983409622"'])
|
'10', '"9345098304850938450983409622"'])
|
||||||
|
|
||||||
self.assertEqual(test3[0], 'Diffie-Hellman full exchange #3')
|
self.assertEqual(test3[0], 9)
|
||||||
self.assertEqual(test3[1], 'dhm_do_dhm')
|
self.assertEqual(test3[1], 'Diffie-Hellman full exchange #3')
|
||||||
self.assertEqual(test3[2], [])
|
self.assertEqual(test3[2], 'dhm_do_dhm')
|
||||||
self.assertEqual(test3[3], ['10',
|
self.assertEqual(test3[3], [])
|
||||||
|
self.assertEqual(test3[4], ['10',
|
||||||
'"9345098382739712938719287391879381271"',
|
'"9345098382739712938719287391879381271"',
|
||||||
'10',
|
'10',
|
||||||
'"9345098792137312973297123912791271"'])
|
'"9345098792137312973297123912791271"'])
|
||||||
|
|
||||||
self.assertEqual(test4[0], 'Diffie-Hellman selftest')
|
self.assertEqual(test4[0], 12)
|
||||||
self.assertEqual(test4[1], 'dhm_selftest')
|
self.assertEqual(test4[1], 'Diffie-Hellman selftest')
|
||||||
self.assertEqual(test4[2], [])
|
self.assertEqual(test4[2], 'dhm_selftest')
|
||||||
self.assertEqual(test4[3], [])
|
self.assertEqual(test4[3], [])
|
||||||
|
self.assertEqual(test4[4], [])
|
||||||
|
|
||||||
def test_with_dependencies(self):
|
def test_with_dependencies(self):
|
||||||
"""
|
"""
|
||||||
@ -1306,15 +1344,17 @@ dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
|
|||||||
# List of (name, function_name, dependencies, args)
|
# List of (name, function_name, dependencies, args)
|
||||||
tests = list(parse_test_data(stream))
|
tests = list(parse_test_data(stream))
|
||||||
test1, test2 = tests
|
test1, test2 = tests
|
||||||
self.assertEqual(test1[0], 'Diffie-Hellman full exchange #1')
|
self.assertEqual(test1[0], 4)
|
||||||
self.assertEqual(test1[1], 'dhm_do_dhm')
|
self.assertEqual(test1[1], 'Diffie-Hellman full exchange #1')
|
||||||
self.assertEqual(test1[2], ['YAHOO'])
|
self.assertEqual(test1[2], 'dhm_do_dhm')
|
||||||
self.assertEqual(test1[3], ['10', '"23"', '10', '"5"'])
|
self.assertEqual(test1[3], ['YAHOO'])
|
||||||
|
self.assertEqual(test1[4], ['10', '"23"', '10', '"5"'])
|
||||||
|
|
||||||
self.assertEqual(test2[0], 'Diffie-Hellman full exchange #2')
|
self.assertEqual(test2[0], 7)
|
||||||
self.assertEqual(test2[1], 'dhm_do_dhm')
|
self.assertEqual(test2[1], 'Diffie-Hellman full exchange #2')
|
||||||
self.assertEqual(test2[2], [])
|
self.assertEqual(test2[2], 'dhm_do_dhm')
|
||||||
self.assertEqual(test2[3], ['10', '"93450983094850938450983409623"',
|
self.assertEqual(test2[3], [])
|
||||||
|
self.assertEqual(test2[4], ['10', '"93450983094850938450983409623"',
|
||||||
'10', '"9345098304850938450983409622"'])
|
'10', '"9345098304850938450983409622"'])
|
||||||
|
|
||||||
def test_no_args(self):
|
def test_no_args(self):
|
||||||
@ -1335,7 +1375,7 @@ dhm_do_dhm:10:"93450983094850938450983409623":10:"9345098304850938450983409622"
|
|||||||
stream = StringIOWrapper('test_suite_ut.function', data)
|
stream = StringIOWrapper('test_suite_ut.function', data)
|
||||||
err = None
|
err = None
|
||||||
try:
|
try:
|
||||||
for _, _, _, _ in parse_test_data(stream):
|
for _, _, _, _, _ in parse_test_data(stream):
|
||||||
pass
|
pass
|
||||||
except GeneratorInputError as err:
|
except GeneratorInputError as err:
|
||||||
self.assertEqual(type(err), GeneratorInputError)
|
self.assertEqual(type(err), GeneratorInputError)
|
||||||
@ -1353,7 +1393,7 @@ depends_on:YAHOO
|
|||||||
stream = StringIOWrapper('test_suite_ut.function', data)
|
stream = StringIOWrapper('test_suite_ut.function', data)
|
||||||
err = None
|
err = None
|
||||||
try:
|
try:
|
||||||
for _, _, _, _ in parse_test_data(stream):
|
for _, _, _, _, _ in parse_test_data(stream):
|
||||||
pass
|
pass
|
||||||
except GeneratorInputError as err:
|
except GeneratorInputError as err:
|
||||||
self.assertEqual(type(err), GeneratorInputError)
|
self.assertEqual(type(err), GeneratorInputError)
|
||||||
|
@ -2,12 +2,17 @@
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Headers */
|
/* Headers */
|
||||||
|
|
||||||
#include <test/macros.h>
|
#include <test/arguments.h>
|
||||||
#include <test/helpers.h>
|
#include <test/helpers.h>
|
||||||
|
#include <test/macros.h>
|
||||||
#include <test/random.h>
|
#include <test/random.h>
|
||||||
#include <test/psa_crypto_helpers.h>
|
#include <test/psa_crypto_helpers.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
|
|
||||||
@ -20,22 +25,8 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <basetsd.h>
|
|
||||||
typedef UINT8 uint8_t;
|
|
||||||
typedef INT32 int32_t;
|
|
||||||
typedef UINT32 uint32_t;
|
|
||||||
#define strncasecmp _strnicmp
|
|
||||||
#define strcasecmp _stricmp
|
|
||||||
#else
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -28,50 +28,28 @@ int verify_string(char **str)
|
|||||||
* integer value.
|
* integer value.
|
||||||
*
|
*
|
||||||
* \param str Input string.
|
* \param str Input string.
|
||||||
* \param value Pointer to int for output value.
|
* \param p_value Pointer to output value.
|
||||||
*
|
*
|
||||||
* \return 0 if success else 1
|
* \return 0 if success else 1
|
||||||
*/
|
*/
|
||||||
int verify_int(char *str, int32_t *value)
|
int verify_int(char *str, intmax_t *p_value)
|
||||||
{
|
{
|
||||||
size_t i;
|
char *end = NULL;
|
||||||
int minus = 0;
|
errno = 0;
|
||||||
int digits = 1;
|
/* Limit the range to long: for large integers, the test framework will
|
||||||
int hex = 0;
|
* use expressions anyway. */
|
||||||
|
long value = strtol(str, &end, 0);
|
||||||
for (i = 0; i < strlen(str); i++) {
|
if (errno == EINVAL || *end != '\0') {
|
||||||
if (i == 0 && str[i] == '-') {
|
mbedtls_fprintf(stderr,
|
||||||
minus = 1;
|
"Expected integer for parameter and got: %s\n", str);
|
||||||
continue;
|
return KEY_VALUE_MAPPING_NOT_FOUND;
|
||||||
}
|
|
||||||
|
|
||||||
if (((minus && i == 2) || (!minus && i == 1)) &&
|
|
||||||
str[i - 1] == '0' && (str[i] == 'x' || str[i] == 'X')) {
|
|
||||||
hex = 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!((str[i] >= '0' && str[i] <= '9') ||
|
|
||||||
(hex && ((str[i] >= 'a' && str[i] <= 'f') ||
|
|
||||||
(str[i] >= 'A' && str[i] <= 'F'))))) {
|
|
||||||
digits = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (errno == ERANGE) {
|
||||||
if (digits) {
|
mbedtls_fprintf(stderr, "Integer out of range: %s\n", str);
|
||||||
if (hex) {
|
return KEY_VALUE_MAPPING_NOT_FOUND;
|
||||||
*value = strtol(str, NULL, 16);
|
|
||||||
} else {
|
|
||||||
*value = strtol(str, NULL, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
*p_value = value;
|
||||||
mbedtls_fprintf(stderr,
|
return 0;
|
||||||
"Expected integer for parameter and got: %s\n", str);
|
|
||||||
return KEY_VALUE_MAPPING_NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,24 +158,24 @@ static int parse_arguments(char *buf, size_t len, char **params,
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Replace newlines, question marks and colons in strings */
|
/* Replace backslash escapes in strings */
|
||||||
for (i = 0; i < cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
p = params[i];
|
p = params[i];
|
||||||
q = params[i];
|
q = params[i];
|
||||||
|
|
||||||
while (*p != '\0') {
|
while (*p != '\0') {
|
||||||
if (*p == '\\' && *(p + 1) == 'n') {
|
if (*p == '\\') {
|
||||||
p += 2;
|
++p;
|
||||||
*(q++) = '\n';
|
switch (*p) {
|
||||||
} else if (*p == '\\' && *(p + 1) == ':') {
|
case 'n':
|
||||||
p += 2;
|
*p = '\n';
|
||||||
*(q++) = ':';
|
break;
|
||||||
} else if (*p == '\\' && *(p + 1) == '?') {
|
default:
|
||||||
p += 2;
|
// Fall through to copying *p
|
||||||
*(q++) = '?';
|
break;
|
||||||
} else {
|
}
|
||||||
*(q++) = *(p++);
|
|
||||||
}
|
}
|
||||||
|
*(q++) = *(p++);
|
||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
}
|
}
|
||||||
@ -223,7 +201,8 @@ static int parse_arguments(char *buf, size_t len, char **params,
|
|||||||
*
|
*
|
||||||
* \return 0 for success else 1
|
* \return 0 for success else 1
|
||||||
*/
|
*/
|
||||||
static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
|
static int convert_params(size_t cnt, char **params,
|
||||||
|
mbedtls_test_argument_t *int_params_store)
|
||||||
{
|
{
|
||||||
char **cur = params;
|
char **cur = params;
|
||||||
char **out = params;
|
char **out = params;
|
||||||
@ -241,7 +220,7 @@ static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (strcmp(type, "int") == 0) {
|
} else if (strcmp(type, "int") == 0) {
|
||||||
if (verify_int(val, int_params_store) == 0) {
|
if (verify_int(val, &int_params_store->sint) == 0) {
|
||||||
*out++ = (char *) int_params_store++;
|
*out++ = (char *) int_params_store++;
|
||||||
} else {
|
} else {
|
||||||
ret = (DISPATCH_INVALID_TEST_DATA);
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
||||||
@ -255,7 +234,7 @@ static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
|
|||||||
mbedtls_test_unhexify((unsigned char *) val, strlen(val),
|
mbedtls_test_unhexify((unsigned char *) val, strlen(val),
|
||||||
val, &len) == 0);
|
val, &len) == 0);
|
||||||
|
|
||||||
*int_params_store = len;
|
int_params_store->len = len;
|
||||||
*out++ = val;
|
*out++ = val;
|
||||||
*out++ = (char *) (int_params_store++);
|
*out++ = (char *) (int_params_store++);
|
||||||
} else {
|
} else {
|
||||||
@ -264,7 +243,7 @@ static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
|
|||||||
}
|
}
|
||||||
} else if (strcmp(type, "exp") == 0) {
|
} else if (strcmp(type, "exp") == 0) {
|
||||||
int exp_id = strtol(val, NULL, 10);
|
int exp_id = strtol(val, NULL, 10);
|
||||||
if (get_expression(exp_id, int_params_store) == 0) {
|
if (get_expression(exp_id, &int_params_store->sint) == 0) {
|
||||||
*out++ = (char *) int_params_store++;
|
*out++ = (char *) int_params_store++;
|
||||||
} else {
|
} else {
|
||||||
ret = (DISPATCH_INVALID_TEST_DATA);
|
ret = (DISPATCH_INVALID_TEST_DATA);
|
||||||
@ -483,7 +462,7 @@ int execute_tests(int argc, const char **argv)
|
|||||||
char buf[5000];
|
char buf[5000];
|
||||||
char *params[50];
|
char *params[50];
|
||||||
/* Store for processed integer params. */
|
/* Store for processed integer params. */
|
||||||
int32_t int_params[50];
|
mbedtls_test_argument_t int_params[50];
|
||||||
void *pointer;
|
void *pointer;
|
||||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||||
int stdout_fd = -1;
|
int stdout_fd = -1;
|
||||||
|
@ -81,7 +81,7 @@ __MBEDTLS_TEST_TEMPLATE__FUNCTIONS_CODE
|
|||||||
*
|
*
|
||||||
* \return 0 if exp_id is found. 1 otherwise.
|
* \return 0 if exp_id is found. 1 otherwise.
|
||||||
*/
|
*/
|
||||||
int get_expression(int32_t exp_id, int32_t *out_value)
|
int get_expression(int32_t exp_id, intmax_t *out_value)
|
||||||
{
|
{
|
||||||
int ret = KEY_VALUE_MAPPING_FOUND;
|
int ret = KEY_VALUE_MAPPING_FOUND;
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ void mpi_read_write_string(int radix_X, char *input_X, int radix_A,
|
|||||||
TEST_ASSERT(sign_is_valid(&X));
|
TEST_ASSERT(sign_is_valid(&X));
|
||||||
TEST_ASSERT(mbedtls_mpi_write_string(&X, radix_A, str, output_size, &len) == result_write);
|
TEST_ASSERT(mbedtls_mpi_write_string(&X, radix_A, str, output_size, &len) == result_write);
|
||||||
if (result_write == 0) {
|
if (result_write == 0) {
|
||||||
TEST_ASSERT(strcasecmp(str, input_A) == 0);
|
TEST_ASSERT(strcmp(str, input_A) == 0);
|
||||||
TEST_ASSERT(str[len] == '!');
|
TEST_ASSERT(str[len] == '!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_read_binary(data_t *buf, char *input_A)
|
void mpi_read_binary(data_t *buf, char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
char str[1000];
|
char str[1000];
|
||||||
@ -422,7 +422,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_read_binary_le(data_t *buf, char *input_A)
|
void mpi_read_binary_le(data_t *buf, char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
char str[1000];
|
char str[1000];
|
||||||
@ -442,8 +442,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_write_binary(char *input_X, data_t *input_A,
|
void mpi_write_binary(char *input_X, data_t *input_A,
|
||||||
int output_size, int result)
|
int output_size, int result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
unsigned char buf[1000];
|
unsigned char buf[1000];
|
||||||
@ -473,8 +473,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_write_binary_le(char *input_X, data_t *input_A,
|
void mpi_write_binary_le(char *input_X, data_t *input_A,
|
||||||
int output_size, int result)
|
int output_size, int result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
unsigned char buf[1000];
|
unsigned char buf[1000];
|
||||||
@ -504,7 +504,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||||
void mbedtls_mpi_read_file(char *input_file, data_t *input_A, int result)
|
void mpi_read_file(char *input_file, data_t *input_A, int result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
unsigned char buf[1000];
|
unsigned char buf[1000];
|
||||||
@ -538,7 +538,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||||
void mbedtls_mpi_write_file(char *input_X, char *output_file)
|
void mpi_write_file(char *input_X, char *output_file)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y;
|
mbedtls_mpi X, Y;
|
||||||
FILE *file_out, *file_in;
|
FILE *file_out, *file_in;
|
||||||
@ -568,7 +568,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_get_bit(char *input_X, int pos, int val)
|
void mpi_get_bit(char *input_X, int pos, int val)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
mbedtls_mpi_init(&X);
|
mbedtls_mpi_init(&X);
|
||||||
@ -581,8 +581,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_set_bit(char *input_X, int pos, int val,
|
void mpi_set_bit(char *input_X, int pos, int val,
|
||||||
char *output_Y, int result)
|
char *output_Y, int result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y;
|
mbedtls_mpi X, Y;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||||
@ -602,7 +602,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_lsb(char *input_X, int nr_bits)
|
void mpi_lsb(char *input_X, int nr_bits)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
mbedtls_mpi_init(&X);
|
mbedtls_mpi_init(&X);
|
||||||
@ -616,7 +616,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_bitlen(char *input_X, int nr_bits)
|
void mpi_bitlen(char *input_X, int nr_bits)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
mbedtls_mpi_init(&X);
|
mbedtls_mpi_init(&X);
|
||||||
@ -630,8 +630,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_gcd(char *input_X, char *input_Y,
|
void mpi_gcd(char *input_X, char *input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi A, X, Y, Z;
|
mbedtls_mpi A, X, Y, Z;
|
||||||
mbedtls_mpi_init(&A); mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
|
mbedtls_mpi_init(&A); mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z);
|
||||||
@ -649,7 +649,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_cmp_int(int input_X, int input_A, int result_CMP)
|
void mpi_cmp_int(int input_X, int input_A, int result_CMP)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
mbedtls_mpi_init(&X);
|
mbedtls_mpi_init(&X);
|
||||||
@ -663,8 +663,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_cmp_mpi(char *input_X, char *input_Y,
|
void mpi_cmp_mpi(char *input_X, char *input_Y,
|
||||||
int input_A)
|
int input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y;
|
mbedtls_mpi X, Y;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||||
@ -679,9 +679,9 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_lt_mpi_ct(int size_X, char *input_X,
|
void mpi_lt_mpi_ct(int size_X, char *input_X,
|
||||||
int size_Y, char *input_Y,
|
int size_Y, char *input_Y,
|
||||||
int input_ret, int input_err)
|
int input_ret, int input_err)
|
||||||
{
|
{
|
||||||
unsigned ret = -1;
|
unsigned ret = -1;
|
||||||
unsigned input_uret = input_ret;
|
unsigned input_uret = input_ret;
|
||||||
@ -705,8 +705,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_cmp_abs(char *input_X, char *input_Y,
|
void mpi_cmp_abs(char *input_X, char *input_Y,
|
||||||
int input_A)
|
int input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y;
|
mbedtls_mpi X, Y;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||||
@ -721,7 +721,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_copy(char *src_hex, char *dst_hex)
|
void mpi_copy(char *src_hex, char *dst_hex)
|
||||||
{
|
{
|
||||||
mbedtls_mpi src, dst, ref;
|
mbedtls_mpi src, dst, ref;
|
||||||
mbedtls_mpi_init(&src);
|
mbedtls_mpi_init(&src);
|
||||||
@ -779,7 +779,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_swap(char *X_hex, char *Y_hex)
|
void mpi_swap(char *X_hex, char *Y_hex)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, X0, Y0;
|
mbedtls_mpi X, Y, X0, Y0;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y);
|
||||||
@ -844,7 +844,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_shrink(int before, int used, int min, int after)
|
void mpi_shrink(int before, int used, int min, int after)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
mbedtls_mpi_init(&X);
|
mbedtls_mpi_init(&X);
|
||||||
@ -864,8 +864,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_add_mpi(char *input_X, char *input_Y,
|
void mpi_add_mpi(char *input_X, char *input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Z, A;
|
mbedtls_mpi X, Y, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -894,7 +894,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_add_mpi_inplace(char *input_X, char *input_A)
|
void mpi_add_mpi_inplace(char *input_X, char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, A;
|
mbedtls_mpi X, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
|
||||||
@ -923,8 +923,8 @@ exit:
|
|||||||
|
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_add_abs(char *input_X, char *input_Y,
|
void mpi_add_abs(char *input_X, char *input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Z, A;
|
mbedtls_mpi X, Y, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -953,8 +953,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_add_int(char *input_X, int input_Y,
|
void mpi_add_int(char *input_X, int input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Z, A;
|
mbedtls_mpi X, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -971,8 +971,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_sub_mpi(char *input_X, char *input_Y,
|
void mpi_sub_mpi(char *input_X, char *input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Z, A;
|
mbedtls_mpi X, Y, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -1001,8 +1001,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_sub_abs(char *input_X, char *input_Y,
|
void mpi_sub_abs(char *input_X, char *input_Y,
|
||||||
char *input_A, int sub_result)
|
char *input_A, int sub_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Z, A;
|
mbedtls_mpi X, Y, Z, A;
|
||||||
int res;
|
int res;
|
||||||
@ -1040,8 +1040,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_sub_int(char *input_X, int input_Y,
|
void mpi_sub_int(char *input_X, int input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Z, A;
|
mbedtls_mpi X, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -1058,8 +1058,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_mul_mpi(char *input_X, char *input_Y,
|
void mpi_mul_mpi(char *input_X, char *input_Y,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Z, A;
|
mbedtls_mpi X, Y, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -1077,8 +1077,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_mul_int(char *input_X, int input_Y,
|
void mpi_mul_int(char *input_X, int input_Y,
|
||||||
char *input_A, char *result_comparison)
|
char *input_A, char *result_comparison)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Z, A;
|
mbedtls_mpi X, Z, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&Z); mbedtls_mpi_init(&A);
|
||||||
@ -1101,9 +1101,9 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_div_mpi(char *input_X, char *input_Y,
|
void mpi_div_mpi(char *input_X, char *input_Y,
|
||||||
char *input_A, char *input_B,
|
char *input_A, char *input_B,
|
||||||
int div_result)
|
int div_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Q, R, A, B;
|
mbedtls_mpi X, Y, Q, R, A, B;
|
||||||
int res;
|
int res;
|
||||||
@ -1130,9 +1130,9 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_div_int(char *input_X, int input_Y,
|
void mpi_div_int(char *input_X, int input_Y,
|
||||||
char *input_A, char *input_B,
|
char *input_A, char *input_B,
|
||||||
int div_result)
|
int div_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Q, R, A, B;
|
mbedtls_mpi X, Q, R, A, B;
|
||||||
int res;
|
int res;
|
||||||
@ -1158,8 +1158,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_mod_mpi(char *input_X, char *input_Y,
|
void mpi_mod_mpi(char *input_X, char *input_Y,
|
||||||
char *input_A, int div_result)
|
char *input_A, int div_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, A;
|
mbedtls_mpi X, Y, A;
|
||||||
int res;
|
int res;
|
||||||
@ -1181,47 +1181,16 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_mod_int(char *input_X, char *input_Y,
|
void mpi_mod_int(char *input_X, mbedtls_mpi_sint y,
|
||||||
char *input_A, int mod_result)
|
mbedtls_mpi_sint a, int mod_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
mbedtls_mpi Y;
|
|
||||||
mbedtls_mpi A;
|
|
||||||
int res;
|
int res;
|
||||||
mbedtls_mpi_uint r;
|
mbedtls_mpi_uint r;
|
||||||
|
|
||||||
mbedtls_mpi_init(&X);
|
mbedtls_mpi_init(&X);
|
||||||
mbedtls_mpi_init(&Y);
|
|
||||||
mbedtls_mpi_init(&A);
|
|
||||||
|
|
||||||
/* We use MPIs to read Y and A since the test framework limits us to
|
|
||||||
* ints, so we can't have 64-bit values */
|
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi(&X, input_X), 0);
|
TEST_EQUAL(mbedtls_test_read_mpi(&X, input_X), 0);
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi(&Y, input_Y), 0);
|
|
||||||
TEST_EQUAL(mbedtls_test_read_mpi(&A, input_A), 0);
|
|
||||||
|
|
||||||
TEST_EQUAL(Y.n, 1);
|
|
||||||
TEST_EQUAL(A.n, 1);
|
|
||||||
|
|
||||||
/* Convert the MPIs for Y and A to (signed) mbedtls_mpi_sints */
|
|
||||||
|
|
||||||
/* Since we're converting sign+magnitude to two's complement, we lose one
|
|
||||||
* bit of value in the output. This means there are some values we can't
|
|
||||||
* represent, e.g. (hex) -A0000000 on 32-bit systems. These are technically
|
|
||||||
* invalid test cases, so could be considered "won't happen", but they are
|
|
||||||
* easy to test for, and this helps guard against human error. */
|
|
||||||
|
|
||||||
mbedtls_mpi_sint y = (mbedtls_mpi_sint) Y.p[0];
|
|
||||||
TEST_ASSERT(y >= 0); /* If y < 0 here, we can't make negative y */
|
|
||||||
if (Y.s == -1) {
|
|
||||||
y = -y;
|
|
||||||
}
|
|
||||||
|
|
||||||
mbedtls_mpi_sint a = (mbedtls_mpi_sint) A.p[0];
|
|
||||||
TEST_ASSERT(a >= 0); /* Same goes for a */
|
|
||||||
if (A.s == -1) {
|
|
||||||
a = -a;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = mbedtls_mpi_mod_int(&r, &X, y);
|
res = mbedtls_mpi_mod_int(&r, &X, y);
|
||||||
TEST_EQUAL(res, mod_result);
|
TEST_EQUAL(res, mod_result);
|
||||||
@ -1231,15 +1200,13 @@ void mbedtls_mpi_mod_int(char *input_X, char *input_Y,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_mpi_free(&X);
|
mbedtls_mpi_free(&X);
|
||||||
mbedtls_mpi_free(&Y);
|
|
||||||
mbedtls_mpi_free(&A);
|
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_exp_mod(char *input_A, char *input_E,
|
void mpi_exp_mod(char *input_A, char *input_E,
|
||||||
char *input_N, char *input_X,
|
char *input_N, char *input_X,
|
||||||
int exp_result)
|
int exp_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi A, E, N, RR, Z, X;
|
mbedtls_mpi A, E, N, RR, Z, X;
|
||||||
int res;
|
int res;
|
||||||
@ -1281,8 +1248,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_exp_mod_size(int A_bytes, int E_bytes, int N_bytes,
|
void mpi_exp_mod_size(int A_bytes, int E_bytes, int N_bytes,
|
||||||
char *input_RR, int exp_result)
|
char *input_RR, int exp_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi A, E, N, RR, Z;
|
mbedtls_mpi A, E, N, RR, Z;
|
||||||
mbedtls_mpi_init(&A); mbedtls_mpi_init(&E); mbedtls_mpi_init(&N);
|
mbedtls_mpi_init(&A); mbedtls_mpi_init(&E); mbedtls_mpi_init(&N);
|
||||||
@ -1316,8 +1283,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_inv_mod(char *input_X, char *input_Y,
|
void mpi_inv_mod(char *input_X, char *input_Y,
|
||||||
char *input_A, int div_result)
|
char *input_A, int div_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, Y, Z, A;
|
mbedtls_mpi X, Y, Z, A;
|
||||||
int res;
|
int res;
|
||||||
@ -1339,7 +1306,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
||||||
void mbedtls_mpi_is_prime(char *input_X, int div_result)
|
void mpi_is_prime(char *input_X, int div_result)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
int res;
|
int res;
|
||||||
@ -1355,8 +1322,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
||||||
void mbedtls_mpi_is_prime_det(data_t *input_X, data_t *witnesses,
|
void mpi_is_prime_det(data_t *input_X, data_t *witnesses,
|
||||||
int chunk_len, int rounds)
|
int chunk_len, int rounds)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
int res;
|
int res;
|
||||||
@ -1388,7 +1355,7 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
|
||||||
void mbedtls_mpi_gen_prime(int bits, int flags, int ref_ret)
|
void mpi_gen_prime(int bits, int flags, int ref_ret)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X;
|
mbedtls_mpi X;
|
||||||
int my_ret;
|
int my_ret;
|
||||||
@ -1424,8 +1391,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_shift_l(char *input_X, int shift_X,
|
void mpi_shift_l(char *input_X, int shift_X,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, A;
|
mbedtls_mpi X, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
|
||||||
@ -1442,8 +1409,8 @@ exit:
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_mpi_shift_r(char *input_X, int shift_X,
|
void mpi_shift_r(char *input_X, int shift_X,
|
||||||
char *input_A)
|
char *input_A)
|
||||||
{
|
{
|
||||||
mbedtls_mpi X, A;
|
mbedtls_mpi X, A;
|
||||||
mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
|
mbedtls_mpi_init(&X); mbedtls_mpi_init(&A);
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
114
tests/suites/test_suite_platform_printf.data
Normal file
114
tests/suites/test_suite_platform_printf.data
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
# The test cases for printf and integers have two purposes: they exercise
|
||||||
|
# the printf function family, and they exercise the passing of integers
|
||||||
|
# and strings through the test framework.
|
||||||
|
|
||||||
|
printf "%d", 0
|
||||||
|
printf_int:"%d":0:"0"
|
||||||
|
|
||||||
|
printf "%d", -0
|
||||||
|
printf_int:"%d":-0:"0"
|
||||||
|
|
||||||
|
printf "%d", 0x0
|
||||||
|
printf_int:"%d":0x0:"0"
|
||||||
|
|
||||||
|
printf "%d", 0x00
|
||||||
|
printf_int:"%d":0x00:"0"
|
||||||
|
|
||||||
|
printf "%d", 0x000000000000000000000000000000000000000000
|
||||||
|
printf_int:"%d":0x000000000000000000000000000000000000000000:"0"
|
||||||
|
|
||||||
|
printf "%d", -0x0
|
||||||
|
printf_int:"%d":-0x0:"0"
|
||||||
|
|
||||||
|
printf "%d", 1
|
||||||
|
printf_int:"%d":1:"1"
|
||||||
|
|
||||||
|
printf "%d", 0x1
|
||||||
|
printf_int:"%d":0x1:"1"
|
||||||
|
|
||||||
|
printf "%d", 0x0000000000000000000000000000000000000000001
|
||||||
|
printf_int:"%d":0x0000000000000000000000000000000000000000001:"1"
|
||||||
|
|
||||||
|
printf "%d", -1
|
||||||
|
printf_int:"%d":-1:"-1"
|
||||||
|
|
||||||
|
printf "%d", -0x1
|
||||||
|
printf_int:"%d":-0x1:"-1"
|
||||||
|
|
||||||
|
printf "%d", -0x0000000000000000000000000000000000000000001
|
||||||
|
printf_int:"%d":-0x0000000000000000000000000000000000000000001:"-1"
|
||||||
|
|
||||||
|
printf "%d", 2147483647
|
||||||
|
printf_int:"%d":2147483647:"2147483647"
|
||||||
|
|
||||||
|
printf "%d", 0x7fffffff
|
||||||
|
printf_int:"%d":0x7fffffff:"2147483647"
|
||||||
|
|
||||||
|
printf "%d", -2147483647
|
||||||
|
printf_int:"%d":-2147483647:"-2147483647"
|
||||||
|
|
||||||
|
printf "%d", -0x7fffffff
|
||||||
|
printf_int:"%d":-0x7fffffff:"-2147483647"
|
||||||
|
|
||||||
|
printf "%d", -2147483648
|
||||||
|
printf_int:"%d":-2147483648:"-2147483648"
|
||||||
|
|
||||||
|
printf "%d", -0x80000000
|
||||||
|
printf_int:"%d":-0x80000000:"-2147483648"
|
||||||
|
|
||||||
|
# Test that LONG_MAX is coming out untruncated through the test framework.
|
||||||
|
printf "%lx", LONG_MAX
|
||||||
|
printf_long_max:"%lx":LONG_MAX
|
||||||
|
|
||||||
|
# The next few test cases exercise how the test framework handles special
|
||||||
|
# characters in strings.
|
||||||
|
printf "%c%c", SPACE, SPACE
|
||||||
|
printf_char2:"%c%c":SPACE_CHAR:SPACE_CHAR:" "
|
||||||
|
|
||||||
|
printf "%c%c", NEWLINE, SPACE
|
||||||
|
printf_char2:"%c%c":NEWLINE_CHAR:SPACE_CHAR:"\n "
|
||||||
|
|
||||||
|
printf "%c%c", DOUBLE QUOTE, SPACE
|
||||||
|
printf_char2:"%c%c":DOUBLE_QUOTE_CHAR:SPACE_CHAR:"\" "
|
||||||
|
|
||||||
|
printf "%c%c", COLON, SPACE
|
||||||
|
printf_char2:"%c%c":COLON_CHAR:SPACE_CHAR:"\: "
|
||||||
|
|
||||||
|
printf "%c%c", QUESTION, SPACE
|
||||||
|
printf_char2:"%c%c":QUESTION_CHAR:SPACE_CHAR:"? "
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, SPACE
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:SPACE_CHAR:"\\ "
|
||||||
|
|
||||||
|
printf "%c%c", SPACE, BACKSLASH
|
||||||
|
printf_char2:"%c%c":SPACE_CHAR:BACKSLASH_CHAR:" \\"
|
||||||
|
|
||||||
|
printf "%c%c", COLON, COLON
|
||||||
|
printf_char2:"%c%c":COLON_CHAR:COLON_CHAR:"\:\:"
|
||||||
|
|
||||||
|
printf "%c%c", COLON, NEWLINE
|
||||||
|
printf_char2:"%c%c":COLON_CHAR:NEWLINE_CHAR:"\:\n"
|
||||||
|
|
||||||
|
printf "%c%c", QUESTION, QUESTION
|
||||||
|
printf_char2:"%c%c":QUESTION_CHAR:QUESTION_CHAR:"??"
|
||||||
|
|
||||||
|
printf "%c%c", QUESTION, NEWLINE
|
||||||
|
printf_char2:"%c%c":QUESTION_CHAR:NEWLINE_CHAR:"?\n"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, NEWLINE
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:NEWLINE_CHAR:"\\\n"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, DOUBLE QUOTE
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:DOUBLE_QUOTE_CHAR:"\\\""
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, COLON
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:COLON_CHAR:"\\\:"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, QUESTION
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:QUESTION_CHAR:"\\?"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, BACKSLASH
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:BACKSLASH_CHAR:"\\\\"
|
||||||
|
|
||||||
|
printf "%c%c", BACKSLASH, n
|
||||||
|
printf_char2:"%c%c":BACKSLASH_CHAR:LOWERCASE_N_CHAR:"\\n"
|
89
tests/suites/test_suite_platform_printf.function
Normal file
89
tests/suites/test_suite_platform_printf.function
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/* BEGIN_HEADER */
|
||||||
|
|
||||||
|
/* The printf test functions take a format argument from the test data
|
||||||
|
* for several reasons:
|
||||||
|
* - For some tests, it makes sense to vary the format.
|
||||||
|
* - For all tests, it means we're testing the actual printf function
|
||||||
|
* that parses the format at runtime, and not a compiler optimization.
|
||||||
|
* (It may be useful to add tests that allow compiler optimizations.
|
||||||
|
* There aren't any yet at the time of writing.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define NEWLINE_CHAR '\n'
|
||||||
|
#define SPACE_CHAR ' '
|
||||||
|
#define DOUBLE_QUOTE_CHAR '"'
|
||||||
|
#define COLON_CHAR ':'
|
||||||
|
#define QUESTION_CHAR '?'
|
||||||
|
#define BACKSLASH_CHAR '\\'
|
||||||
|
#define LOWERCASE_N_CHAR 'n'
|
||||||
|
/* END_HEADER */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void printf_int(char *format, /* any format expecting one int argument, e.g. "%d" */
|
||||||
|
int x, char *result)
|
||||||
|
{
|
||||||
|
char *output = NULL;
|
||||||
|
const size_t n = strlen(result);
|
||||||
|
|
||||||
|
/* Nominal case: buffer just large enough */
|
||||||
|
ASSERT_ALLOC(output, n + 1);
|
||||||
|
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, x));
|
||||||
|
ASSERT_COMPARE(result, n + 1, output, n + 1);
|
||||||
|
mbedtls_free(output);
|
||||||
|
output = NULL;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_free(output);
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void printf_long_max(const char *format, /* "%lx" or longer type */
|
||||||
|
long value)
|
||||||
|
{
|
||||||
|
char *expected = NULL;
|
||||||
|
char *output = NULL;
|
||||||
|
/* 2 hex digits per byte */
|
||||||
|
const size_t n = sizeof(value) * 2;
|
||||||
|
|
||||||
|
/* We assume that long has no padding bits! */
|
||||||
|
ASSERT_ALLOC(expected, n + 1);
|
||||||
|
expected[0] = '7';
|
||||||
|
memset(expected + 1, 'f', sizeof(value) * 2 - 1);
|
||||||
|
|
||||||
|
ASSERT_ALLOC(output, n + 1);
|
||||||
|
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, value));
|
||||||
|
ASSERT_COMPARE(expected, n + 1, output, n + 1);
|
||||||
|
mbedtls_free(output);
|
||||||
|
output = NULL;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_free(output);
|
||||||
|
mbedtls_free(expected);
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void printf_char2(char *format, /* "%c%c" */
|
||||||
|
int arg1, int arg2, char *result)
|
||||||
|
{
|
||||||
|
char *output = NULL;
|
||||||
|
const size_t n = strlen(result);
|
||||||
|
|
||||||
|
/* Nominal case: buffer just large enough */
|
||||||
|
ASSERT_ALLOC(output, n + 1);
|
||||||
|
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, arg1, arg2));
|
||||||
|
ASSERT_COMPARE(result, n + 1, output, n + 1);
|
||||||
|
mbedtls_free(output);
|
||||||
|
output = NULL;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_free(output);
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
@ -328,7 +328,7 @@ mbedtls_x509_csr_info:"data_files/server1.req.sha512":"CSR version \: 1\nsubje
|
|||||||
|
|
||||||
X509 CSR Information RSA with SHA-256, containing commas
|
X509 CSR Information RSA with SHA-256, containing commas
|
||||||
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA256_C:MBEDTLS_RSA_C:MBEDTS_X509_INFO
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA256_C:MBEDTLS_RSA_C:MBEDTS_X509_INFO
|
||||||
mbedtls_x509_csr_info:"data_files/server1.req.commas.sha256":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL\, Commas, CN=PolarSSL Server 1\nsigned using \: RSA with SHA-256\nRSA key size \: 2048 bits\n"
|
mbedtls_x509_csr_info:"data_files/server1.req.commas.sha256":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL\\, Commas, CN=PolarSSL Server 1\nsigned using \: RSA with SHA-256\nRSA key size \: 2048 bits\n"
|
||||||
|
|
||||||
X509 CSR Information EC with SHA1
|
X509 CSR Information EC with SHA1
|
||||||
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C
|
depends_on:MBEDTLS_ECDSA_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C
|
||||||
@ -413,7 +413,7 @@ mbedtls_x509_dn_gets:"data_files/server2.crt":"issuer":"C=NL, O=PolarSSL, CN=Pol
|
|||||||
|
|
||||||
X509 Get Distinguished Name #5
|
X509 Get Distinguished Name #5
|
||||||
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_SHA1_C
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_SHA1_C
|
||||||
mbedtls_x509_dn_gets:"data_files/server1.commas.crt":"subject":"C=NL, O=PolarSSL\, Commas, CN=PolarSSL Server 1"
|
mbedtls_x509_dn_gets:"data_files/server1.commas.crt":"subject":"C=NL, O=PolarSSL\\, Commas, CN=PolarSSL Server 1"
|
||||||
|
|
||||||
X509 Get Modified DN #1
|
X509 Get Modified DN #1
|
||||||
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_SHA1_C
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_SHA1_C
|
||||||
@ -2950,7 +2950,7 @@ x509_get_time:MBEDTLS_ASN1_UTC_TIME:"0002291212+0300":MBEDTLS_ERR_X509_INVALID_D
|
|||||||
|
|
||||||
X509 Get time (UTC invalid character in year)
|
X509 Get time (UTC invalid character in year)
|
||||||
depends_on:MBEDTLS_X509_USE_C
|
depends_on:MBEDTLS_X509_USE_C
|
||||||
x509_get_time:MBEDTLS_ASN1_UTC_TIME:"0\1130231212Z":MBEDTLS_ERR_X509_INVALID_DATE:0:0:0:0:0:0
|
x509_get_time:MBEDTLS_ASN1_UTC_TIME:"0\\1130231212Z":MBEDTLS_ERR_X509_INVALID_DATE:0:0:0:0:0:0
|
||||||
|
|
||||||
X509 Get time (UTC invalid character in month)
|
X509 Get time (UTC invalid character in month)
|
||||||
depends_on:MBEDTLS_X509_USE_C
|
depends_on:MBEDTLS_X509_USE_C
|
||||||
|
@ -116,7 +116,7 @@ x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1
|
|||||||
|
|
||||||
|
|
||||||
X509 String to Names #1
|
X509 String to Names #1
|
||||||
mbedtls_x509_string_to_names:"C=NL,O=Offspark\, Inc., OU=PolarSSL":"C=NL, O=Offspark\, Inc., OU=PolarSSL":0
|
mbedtls_x509_string_to_names:"C=NL,O=Offspark\\, Inc., OU=PolarSSL":"C=NL, O=Offspark\\, Inc., OU=PolarSSL":0
|
||||||
|
|
||||||
X509 String to Names #2
|
X509 String to Names #2
|
||||||
mbedtls_x509_string_to_names:"C=NL, O=Offspark, Inc., OU=PolarSSL":"":MBEDTLS_ERR_X509_UNKNOWN_OID
|
mbedtls_x509_string_to_names:"C=NL, O=Offspark, Inc., OU=PolarSSL":"":MBEDTLS_ERR_X509_UNKNOWN_OID
|
||||||
@ -128,10 +128,10 @@ X509 String to Names #4 (Name larger than 255 bytes)
|
|||||||
mbedtls_x509_string_to_names:"C=NL, O=1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456, OU=PolarSSL":"":MBEDTLS_ERR_X509_INVALID_NAME
|
mbedtls_x509_string_to_names:"C=NL, O=1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456, OU=PolarSSL":"":MBEDTLS_ERR_X509_INVALID_NAME
|
||||||
|
|
||||||
X509 String to Names #5 (Escape non-allowed characters)
|
X509 String to Names #5 (Escape non-allowed characters)
|
||||||
mbedtls_x509_string_to_names:"C=NL, O=Offspark\a Inc., OU=PolarSSL":"":MBEDTLS_ERR_X509_INVALID_NAME
|
mbedtls_x509_string_to_names:"C=NL, O=Offspark\\a Inc., OU=PolarSSL":"":MBEDTLS_ERR_X509_INVALID_NAME
|
||||||
|
|
||||||
X509 String to Names #6 (Escape at end)
|
X509 String to Names #6 (Escape at end)
|
||||||
mbedtls_x509_string_to_names:"C=NL, O=Offspark\":"":MBEDTLS_ERR_X509_INVALID_NAME
|
mbedtls_x509_string_to_names:"C=NL, O=Offspark\\":"":MBEDTLS_ERR_X509_INVALID_NAME
|
||||||
|
|
||||||
Check max serial length
|
Check max serial length
|
||||||
x509_set_serial_check:
|
x509_set_serial_check:
|
||||||
|
@ -237,6 +237,7 @@
|
|||||||
<ClInclude Include="..\..\include\psa\crypto_struct.h" />
|
<ClInclude Include="..\..\include\psa\crypto_struct.h" />
|
||||||
<ClInclude Include="..\..\include\psa\crypto_types.h" />
|
<ClInclude Include="..\..\include\psa\crypto_types.h" />
|
||||||
<ClInclude Include="..\..\include\psa\crypto_values.h" />
|
<ClInclude Include="..\..\include\psa\crypto_values.h" />
|
||||||
|
<ClInclude Include="..\..\tests\include\test\arguments.h" />
|
||||||
<ClInclude Include="..\..\tests\include\test\asn1_helpers.h" />
|
<ClInclude Include="..\..\tests\include\test\asn1_helpers.h" />
|
||||||
<ClInclude Include="..\..\tests\include\test\constant_flow.h" />
|
<ClInclude Include="..\..\tests\include\test\constant_flow.h" />
|
||||||
<ClInclude Include="..\..\tests\include\test\fake_external_rng_for_test.h" />
|
<ClInclude Include="..\..\tests\include\test\fake_external_rng_for_test.h" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user