Commit graph

262 commits

Author SHA1 Message Date
Gabor Mezei
bd23f3b2b8
Add test generation for ecp_mod_p192_raw
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-31 14:40:05 +01:00
Gabor Mezei
95ecaaf56d
Add test generation support for the ecp module
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-31 14:40:05 +01:00
Gilles Peskine
470f10cfc5
Merge pull request #6941 from gabor-mezei-arm/6375_quasi-reduction_function
Add function to fix quasi-reduction
2023-01-31 11:25:25 +01:00
Gabor Mezei
b57c908855
Shorten the prefix of the test case belongs to the fix quasi-reduction function
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-27 14:37:42 +01:00
Gabor Mezei
26439bf692
Revert "Add dependency for generated test cases"
The 'MBEDTLS_TEST_HOOKS' belongs to a test function and
not to a test case.

This reverts commit 1e8c210b9d.

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-27 14:33:50 +01:00
Manuel Pégourié-Gonnard
169d9e6eb4
Merge pull request #6802 from gilles-peskine-arm/test_suite_psa_crypto_metadata-20221215
Add metadata tests for CCM* and TLS1.2-ECJPAKE-to-PMS
2023-01-27 10:05:00 +01:00
Gabor Mezei
1e8c210b9d
Add dependency for generated test cases
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-26 12:30:01 +01:00
David Horstmann
79f14e3990 Give proper Dict type hints in crypto_knowledge.py
This prevents a return type error in a later function that uses the
dictionaries here properly typed.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-01-24 18:59:07 +00:00
Gabor Mezei
246d66bb5f
Use reproductable random numbers
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-24 18:02:52 +01:00
Gabor Mezei
6f96c89fc3
Fix pylint issues
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-24 17:38:26 +01:00
Gabor Mezei
aaa1d2a276
Move the quasi reduction fixing function to bignum_mod_raw
Rename the function to 'fix_quasi_reduction' to better suite its functionality.
Also changed the name prefix to suite for the new module.

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-23 18:55:57 +01:00
Gilles Peskine
f6c6b64be2 A key agreement cannot be chained with PSA_ALG_TLS12_ECJPAKE_TO_PMS
Test accordingly.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-19 12:11:20 +01:00
Gilles Peskine
72f41562f2 Refactoring: new method Algorithm.is_valid_for_operation
No intended behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-19 12:11:18 +01:00
Gabor Mezei
7e14c66c4d
Fix lint issues
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-18 10:56:13 +01:00
Gabor Mezei
aec3eea064
Fix pylint issues
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-17 16:34:24 +01:00
Gabor Mezei
3c6f89b46a
Add generated test for ecp quasi-reduction
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-17 13:16:47 +01:00
Gabor Mezei
308132f641
Add test generation support for the ecp module
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2023-01-17 13:16:46 +01:00
Manuel Pégourié-Gonnard
676766ff77
Merge pull request #6776 from gabor-mezei-arm/6222_bignum_mod_mul
Bignum: Implement fixed width modular multiplication
2022-12-23 10:39:30 +01:00
Manuel Pégourié-Gonnard
2fcb4c1d06
Merge pull request #6747 from gilles-peskine-arm/bignum-mod-random
Bignum mod random
2022-12-23 10:36:22 +01:00
Gilles Peskine
5efe449a6a More robust dependency filtering
Only remove the MBEDTLS_HAVE_INTnn dependency, not any other dependency that
might be present.

No behavior change, this is just robustness.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-21 20:33:30 +01:00
Gilles Peskine
f287366376 Simplify logic and document test_cases_for_values
Explain what's going on in BignumModRawConvertRep.test_case_for_values.

Simplify the logic and the interdependencies related to limb sizes:
* Montgomery is the special case, so base the decisions on it.
* As soon as we've encountered one limb size, no matter what it is,
  give up.

No behavior change, other than changing the numbering of test cases (which
previously included more skipped test cases).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-21 20:31:14 +01:00
Gilles Peskine
394da2d857 Pacify pylint
Except for missing documentation, which will come in a subsequent commit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-21 20:22:38 +01:00
Gilles Peskine
6d40e54db0 Split the high nesting of BignumModRawConvertRep.generate_function_tests
Pylint complains about the nesting. It's not wrong.

No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-21 20:22:38 +01:00
Gilles Peskine
636809f2b9 Fix type declaration
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-21 20:12:31 +01:00
Minos Galanakis
342b9a903d bignum_mod_raw.py: Added a filtering logic to BignumModRawConvertRep.generate_function_tests()
This patch introduces a hybrid approach to input_styles, and will remove the
dependency requirements from test cases with `ModulusRepresentation.OPT_RED`

As a result it is reducing testing input duplication.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-21 18:00:01 +00:00
Minos Galanakis
afa7c04105 bignum_common.py: Refactored BignumModRawConvertRep.generate_function_tests()
This patch adjusts the test generating method to calculate all possible combinations for
(modulo, input, limb_sizes, representation).

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-21 18:00:01 +00:00
Minos Galanakis
ae4d2cf3e3 bignum_common.py: Introduce the set_representation setter.
This patch adds the default representation attribute through a
setter() method in `BignumModRawConvertRep()`

It also adds standard common template properties:
    symbol = ""
    input_style = "arch_split"
    arity = 1

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-21 18:00:01 +00:00
Minos Galanakis
5689410083 bignum_mod_raw: Simplified BignumModRawCanonicalToFromModulusRep output expressions.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-21 17:31:56 +00:00
Minos Galanakis
3d2aab891b bignum_common: Adjusted format_arg to always size input according to modulo.
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-21 17:30:10 +00:00
Gilles Peskine
ad335b55ff Fix representation conversion with 32-bit limbs
The Montgomery representation depends on the limb size. So the
representation conversion test cases need separate 64-bit and 32-bit cases
when the representation is Montgomery.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-20 22:39:15 +01:00
Gilles Peskine
be69c7d559 Generate test cases for mpi_mod_raw_modulus_to_canonical_rep as well
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-20 20:28:02 +01:00
Gilles Peskine
23636aca98 Generate test cases for mpi_mod_raw_canonical_to_modulus_rep
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-20 19:55:51 +01:00
Gilles Peskine
7a708fd49f Helpers for generating representation-aware test cases
Add a class for modulus representations (mbedtls_mpi_mod_rep_selector).

Add a method to convert a number to any representation.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-20 19:52:49 +01:00
Gilles Peskine
5623ecc2d6 Mod operations: fill arguments to the width of the modulus
With the default input style (which is "variable"), fill all bignum test
case arguments to the same width as the modulus.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-20 19:52:49 +01:00
Gilles Peskine
f8a4463bd6 Add some missing type annotations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-20 19:52:49 +01:00
Gabor Mezei
8a26164684
Supress pylint's duplicated code warning
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-12-20 17:30:19 +01:00
Gabor Mezei
77b877d5a7
Generate operands in Mongomery representation for the test function
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-12-20 17:30:19 +01:00
Gabor Mezei
eca74668c7
Add tests for mod_mul
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-12-20 17:30:19 +01:00
Gilles Peskine
e162b4725c
Merge pull request #6777 from tom-cosgrove-arm/issue-6292-mod_inv
Bignum: Implement high level fixed width modular inversion
2022-12-17 13:26:02 +01:00
Tom Cosgrove
f723754f6d Fix typos
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-16 16:10:36 +00:00
Gabor Mezei
b31b2e62ec
Generate operands in Mongomery representation for the test function
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-12-16 14:27:48 +01:00
Tom Cosgrove
1133d2325b Attempt to pacify pylint in bignum tests
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-16 03:53:17 +00:00
Tom Cosgrove
dc19759327 Add tests for mbedtls_mpi_mod_inv()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-15 16:59:40 +00:00
Tom Cosgrove
dbac60924b mbedtls_mpi_mod_raw_inv_prime() tests should be arch_split
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-15 16:56:36 +00:00
Tom Cosgrove
30f3b4d601 Add mbedtls_mpi_core_check_zero_ct() and tests
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-15 16:56:36 +00:00
Gabor Mezei
80a334ada3
Add generated tests for mod_raw_mul
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-12-15 15:04:20 +01:00
Gilles Peskine
9fa4897839
Merge pull request #6772 from wernerlewis/bignum_refactor_sub
Bignum: Refactor mpi_core_sub tests to use arch_split
2022-12-15 12:32:44 +01:00
Manuel Pégourié-Gonnard
50faa55e4d
Merge pull request #6732 from wernerlewis/bignum_6019_mod_add
Bignum: Implement mbedtls_mpi_mod_add()
2022-12-15 11:39:24 +01:00
Manuel Pégourié-Gonnard
48232ed2c1
Merge pull request #6743 from minosgalanakis/bignum/implement_modular_negation
Bignum: Implement fixed width modular negation
2022-12-13 09:54:38 +01:00
Werner Lewis
91a2aabb86 Refactor mpi_core_sub tests to use arch_split
Tests are refactored to generate separate cases for 32-bit and 64-bit
limbs using arch_split. Duplicate arguments and branching in the test
function is removed.

Signed-off-by: Werner Lewis <werner.lewis@arm.com>
2022-12-12 17:18:43 +00:00