Commit graph

51 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Minos Galanakis
f3abea6641 bignum_mod_raw.py: Changed the symbol for modular negation to "-".
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-12 11:13:56 +00:00
Minos Galanakis
78665eba8f bignum_mod_raw.py: Added BignumModRawModNegate.
This patch adds autogenerated inputs for the
`mpi_mod_raw_neg()` test in the bignum_mod_raw suite.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-12-12 11:13:56 +00:00
Tom Cosgrove
9d8afd1ccf Have BignumModRawInvPrime() do Montgomery conversion in arg_a()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-09 10:58:46 +00:00
Tom Cosgrove
6129268fee Bignum: Implement mbedtls_mpi_mod_raw_inv_prime() and tests
Fixes #6023.

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-08 09:44:10 +00:00
Tom Cosgrove
c240600f24 Separate out to_montgomery and from_montgomery for bignum tests
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-06 12:20:43 +00:00
Janos Follath
590ae5363d
Merge pull request #6656 from tom-cosgrove-arm/bignum_pr_6225-updated
Bignum: add mod_raw_add
2022-11-25 17:53:31 +00:00
Tom Cosgrove
50fc127a4e Change order of test arguments for bignum_mod_raw to simplify Python script
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-24 21:29:23 +00:00
Tom Cosgrove
1923009cdb Add test generation for mbedtls_mpi_mod_raw_add()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-24 16:22:43 +00:00
Gabor Mezei
6b3c0c5943
Update the test case generator
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-11-23 16:45:05 +01:00
Gabor Mezei
c426d9b6cc
Add generated test for low level subtraction with modulus
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-11-23 14:44:13 +01:00
Janos Follath
f352c67bc3 Bignum tests: use default dataset in mod_raw
While at it, flatten class hierarchy as well.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:15 +00:00
Janos Follath
8ae7a657ac Bignum tests: improve mod descriptions
There are no semantic changes to the generated tests.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
284672ccfb Bignum tests: complete support for unary operators
There are no intended changes to generated tests. (The ordering of tests
in the mod_raw module has changed.)

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
1921fd585c Bignum tests: use arity in bignum_mod_raw
This makes a couple of properties redundant which are cleaned up.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
4c59d35e00 Bignum tests: make args use input_style
Before arg_ attributes were the arguments as they were defined in the
python script. Turning these into properties and having them take the
form respect the style set in input_style makes the class easier to use
and more consistent.

This change makes the hex_ properties redundant and therefore they are
removed.

There are no semantic changes to the generated test cases. (The order
of appearance of 64 and 32 bit mpi_core_add_and_add_if test cases has
changed.)

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
6fa3f0653a Bignum Tests: remove OperationCommonArchSplit
The ArchSplit functionality was duplicated and moved to OperationCommon
from the other copy. The remnants of the functionality is moved to the
only subclass using this.

There is no semantic change to the generated tests. The order has
changed however: core_add tests have been moved before core_mla tests
and the order of the 64 and 32 bit versions have been swapped.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
155ad8c297 Bignum Tests: remove ModOperationCommonArchSplit
The functionality of ModOperationCommonArchSplit is needed in several
subclasses, therefore moving it to a superclass.

There is another, redundant ArchSplit class, which will be removed in a
later commit.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
948afcecb9 Bignum Tests: move ModOperationArchSplit to common
The class BignumModRawOperationArchSplit has functionality that are
needed in other modules, therefore moving it to bignum_common.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
5b1dbb4cbc Bignum Tests: Move ModOperation to common
The class BignumModRawOperation implements functionality that are needed
in other modules, therefore we move it to common.

No intended changes to test cases. The order of add_and_add_if and sub tests
have been switched.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:14 +00:00
Janos Follath
0cd8967ba1 Split test generator base class
The class BaseTarget served two purposes:
- track test cases and target files for generation
- provide an abstract base class for individual test groups

Splitting these allows decoupling these two and to have further common
superclasses across targets.

No intended change in generated test cases.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 08:56:13 +00:00
Minos Galanakis
50de073c84 bignum_mod_raw.py: Added BignumModRawConvertfromMont
This patch adds test class for 'mpi_mod_raw_from_mont_rep()`.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-12 13:21:31 +00:00
Minos Galanakis
a252f6b24c bignum_mod_raw.py: Added BignumModRawConvertToMont
This patch adds test class for 'mpi_mod_raw_to_mont_rep()`.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-12 13:21:31 +00:00
Minos Galanakis
855c228b29 bignum_mod_raw.py: Moved Classes outside of slots
This patch moves `BignumModRawOperation` and `BignumModRawOperationArchSplit`
outside of the scaffolding merge slot.

It also renames `r_sqrt` property to `r2`.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-10 11:37:33 +00:00
Minos Galanakis
a461ece810 bignum_mod_raw.py: Refactoring BignumModRawOperation
This patch modifies the BignumModRawOperation class to
provide special access to key members commonly used
in tests.

It binds the module's getters to conversion functions
which enable automatic conversions such as:

* hex to int.
* zero padding hex strings.
* common Montgomery constants such as R, R^2 and R^01
  are now be calculated upon access.

class `BignumModRawOperationArchSplit` is also updated to
utilise the new design.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-10 11:37:33 +00:00
Minos Galanakis
e9c86a100a bignum_mod_raw.py: Added BignumModRawOperation
This patch is adding a basic instantance of `BignumModRawOperation`
and creates an `BignumModRawOperationArchSplit` class, copying
over the implementation of `BignumCoreRawOperationArchSplit`.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-10 11:37:33 +00:00
Janos Follath
d820ca5d07
Fix bignum test generator class names
Co-authored-by: minosgalanakis <30719586+minosgalanakis@users.noreply.github.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-03 08:42:54 +00:00
Janos Follath
9cf14cd6b0 Make pylint happy
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 17:28:39 +00:00
Janos Follath
1be322a795 Add merge slots to raw and mod_raw test generation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 17:27:36 +00:00