The loop ends when there are no more bits to process, with one twist: when
that happens, we need to clear the window one last time. Since the window
does not start empty (E_limbs==0 is not supported), the loop always starts
with a non-empty window and some bits to process. So it's correct to move
the window clearing logic to the end of the loop. This lets us exit the loop
when the end of the exponent is reached.
It would be clearer not to do the final window clearing inside the loop, so
we wouldn't need to repeat the loop termination condition (end of exponent
reached) inside the loop. However, this requires duplicating the code to
clear the window. Empirically, this causes a significant code size increase,
even if the window clearing code is placed into a function.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
We are looking at the exponent at limb granularity and therefore
exponent bits can't go below 32.
The `mpi_` prefix is also removed as it is better not to have prefix at
all than to have just a partial. (Full prefix would be overly long and
would hurt readability.)
Signed-off-by: Janos Follath <janos.follath@arm.com>
The test cases aim to mirror the legacy function, but needed the some
cases to be removed because:
- Null representation is not valid in core
- There are no negative numbers in core
- Bignum core doesn't do parameter checking and there are no promises for
even N
The _size variant of the test has been removed as bignum core doesn't do
parameter checking and there is no promises for inputs that are larger
than MBEDTLS_MPI_MAX_SIZE.
Signed-off-by: Janos Follath <janos.follath@arm.com>
Now that we have a function that calls
mbedtls_mpi_core_ct_uint_table_lookup(), the compiler won't complain if
we make it static.
Signed-off-by: Janos Follath <janos.follath@arm.com>
On platforms with size_t different from int, mismatch between size_t and
mpi_uint can cause incorrect results or complaints from the compiler.
Signed-off-by: Janos Follath <janos.follath@arm.com>
mpi_core_exp_mod: Cast local variable explicitly
Signed-off-by: Janos Follath <janos.follath@arm.com>
Normally we need all the combinations, unique combinations make sense
only if the operation is commutative.
No changes to generated tests.
Signed-off-by: Janos Follath <janos.follath@arm.com>
Remove old dataset that was overriding the defaults in bignum_core. This
will change the datasets for core_sub and core_add to the default
inherited from bignum_common.
Signed-off-by: Janos Follath <janos.follath@arm.com>
Add data for small values, 192 bit and 1024 bit values, primes,
non-primes odd, even, and some typical corner cases.
All subclasses override this for the time being so there are no changes
to the test cases.
Signed-off-by: Janos Follath <janos.follath@arm.com>
The goal of this commit is to add some constants that can be used to
define datasets and add test data in a more readable and reusable
manner.
All platforms using ECC need to support calculations with at least 192
bits, therefore constants for this length are added. We are not using a
curve prime as those will be tested elsewhere and it is better not to
play favourites.
All platforms using RSA or FFDH need to support calculations with at
least 1024 bits, therefore numbers of this size are added too.
A safe prime is added for both sizes as it makes all elements generators
(except 0 and 1 of course), which in turn makes some tests more
effective.
Signed-off-by: Janos Follath <janos.follath@arm.com>
Only fixed width input_style uses the default value of the bits_in_limb
parameter, so set it to 32 in order to have less leading zeroes.
Signed-off-by: Janos Follath <janos.follath@arm.com>
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>
The special case list type depends on the arity and the subclass. Remove
type restriction to make defining special case lists more flexible and natural.
Signed-off-by: Janos Follath <janos.follath@arm.com>
Sometimes we don't want all possible combinations of the input data and
sometimes not all combinations make sense. We are adding a convenient
way to decide on a case by case basis. Now child classes only need to
implement the is_valid method and the invalid cases will be filtered out
automatically.
Signed-off-by: Janos Follath <janos.follath@arm.com>
Having int_ variants as an attribute has the advantage of the input
being validated when the object is instantiated. In theory otherwise if
a particular int_ attribute is not accessed, then the invalid argument
is passed to the tests as it is. (This would in all likelihood detected
by the actual test cases, still, it is more robust like this.)
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>
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>
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>
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>
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>
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>