449 Commits

Author SHA1 Message Date
Dave Rodgman
d282e264cd Fix IAR warning
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2024-03-11 15:28:48 +00:00
Janos Follath
b888bc0be6 Fix typo
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-03-11 09:29:53 +00:00
Janos Follath
16ef486c2c Improve style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-03-08 17:25:57 +00:00
Janos Follath
4ec0fb5924 Avoid implementation defined behaviour
The conversion back to signed short is an issue: the uint cast results
in (-1 + UINT_MAX), which is OK. But then that can't be cast back to a
signed value: "if the new type is signed and the value cannot be
represented in it; either the result is implementation-defined or an
implementation-defined signal is raised."

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-03-08 17:22:40 +00:00
Janos Follath
0902572aa4 Fix style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-21 11:50:25 +00:00
Janos Follath
86258f51b5 Exp mod: handle negative zero
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-21 11:25:41 +00:00
Janos Follath
424c2655b9 Exp mod: tidy up temporary storage allocation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-21 09:26:36 +00:00
Janos Follath
0512d178e0 Exp mod: Make sure RR has enough limbs
When generated by exp_mod, RR has enough limbs to be passed as a
parameter to core functions. If it is received from the caller, it might
be of any length.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-20 14:30:46 +00:00
Janos Follath
518b5b60c6 Improve style
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-19 11:30:24 +00:00
Janos Follath
467a5499a5 Exp mod: clarify preprocessing
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-19 11:27:38 +00:00
Janos Follath
583f047c9f Exp mod: simplify 0 exponent handling
Removing E_core and returning early achieves the same and is simpler
(easier to read and maintain).

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-19 11:16:44 +00:00
Janos Follath
576087d836 Exp mod: use assignment instead memcpy
memcpy() has the advantage of making the reader stop and arguably signal
that the shallow copy here is intentional. But that hinges on having the
right amount of & and the right size. An assignment is clearer and less
risky.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-19 11:05:01 +00:00
Janos Follath
701ae1d3d9 Exp mod: move declarations before use
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-19 10:56:54 +00:00
Janos Follath
c9faea0f70 Bignum: Remove/update obsolete comments
- We have moved to fixed window exponentiation and the algorithm used is
properly documented and referenced in core already, no need for
duplication.
- A comment on mbedtls_mpi_copy states that mbedtls_mpi_exp_mod relies
on it not to shrink X. This is not the case anymore, however we
should probably still state that some functions might rely on this
property as we don't know it for sure and it is safer to keep it that
way.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-19 10:52:03 +00:00
Janos Follath
4b5edfa0bb Bignum: remove unused functions
Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-15 10:47:56 +00:00
Janos Follath
1ba40585f9 Use mpi_core_exp_mod in bignum.
The two algorithms are not equivalent. The original bignum
exponentiation was a sliding window algorithm. The one in
mpi_core_exp_mod uses a fixed window approach. This change is
intentional. We don't want to maintain two algorithms and decided to
keep the fixed window algorithm.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2024-02-15 10:47:56 +00:00
Valerio Setti
4e048f1749 bignum: removing usage of MPI_VALIDATE_RET()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-01-29 12:00:21 +01:00
Valerio Setti
a45a399a6b lib: remove NULL pointer checks performed with MBEDTLS_INTERNAL_VALIDATE[_RET]
Symbols defined starting from MBEDTLS_INTERNAL_VALIDATE[_RET]
are removed as well.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-01-29 12:00:15 +01:00
Dave Rodgman
59059ec503 Merge remote-tracking branch 'origin/development' into msft-aarch64
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-30 09:34:41 +00:00
Dave Rodgman
e4a6f5a7ec Use size_t cast for pointer subtractions
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-21 17:09:46 +00:00
Dave Rodgman
16799db69a update headers
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-02 19:47:20 +00:00
Dave Rodgman
0a48717b83 Simplify Windows-on-Arm macros
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-10-16 09:25:59 +01:00
Minos Galanakis
1a3ad265cc Merge branch 'development-restricted' into mbedtls-3.5.0rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 21:57:51 +01:00
Dave Rodgman
7e9af05409 Fix IAR control bypasses initialisation warning
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-28 17:08:49 +01:00
Dave Rodgman
73d8591f7f Fix IAR change of sign warning
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-28 17:00:50 +01:00
Gilles Peskine
ca1e605b9c Merge remote-tracking branch 'upstream-public/development' into development-restricted-merge-20230925
Conflicts:
* `include/mbedtls/build_info.h`: a new fragment to auto-enable
  `MBEDTLS_CIPHER_PADDING_PKCS7` was added in
  c9f4040f7f3356293e90c58d11f6567def641e08 in `development-restricted`.
  In `development`, this section of the file has moved to
  `include/mbedtls/config_adjust_legacy_crypto.h`.
* `library/bignum.c`: function name change in `development-restricted` vs
  comment change in development. The comment change in `development` is not
  really relevant, so just take the line from `development-restricted`.
2023-09-25 16:16:26 +02:00
Dave Rodgman
1cfc43c77b Rename mbedtls_ct_bool_xor to mbedtls_ct_bool_ne
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-19 18:39:33 +01:00
Dave Rodgman
b69239c604 Improve docs in mbedtls_mpi_lt_mpi_ct
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-29 09:42:14 +01:00
Tom Cosgrove
3d2d599d3e
Merge pull request #7996 from gilles-peskine-arm/small_primes-gaps
Reduce the size of the small primes table used by primality testing
2023-08-22 12:48:56 +00:00
Gilles Peskine
30b0378008 Fix off-by-one error
The value of p after adding the last entry in the gap table is not used.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-22 11:06:47 +02:00
Tom Cosgrove
31b2d7414d
Merge pull request #8053 from gilles-peskine-arm/mpi_exp_mod-remove_initial_copy
mbedtls_mpi_exp_mod: remove spurious copy of the output variable
2023-08-21 15:50:28 +00:00
Tom Cosgrove
d29648026b
Merge pull request #8017 from ivq/unchecked_return
Fix a few unchecked return values
2023-08-21 13:02:53 +00:00
Chien Wong
2e3858f5eb
Undo a change
Signed-off-by: Chien Wong <m@xv97.com>
2023-08-11 18:16:06 +08:00
Manuel Pégourié-Gonnard
54da1a69a2
Merge pull request #7578 from daverodgman/safer-ct5
Improve constant-time interface
2023-08-10 16:57:39 +00:00
Gilles Peskine
e6cb45e68e mbedtls_mpi_exp_mod: remove spurious copy of the output variable
Clear some confusion between `X` as the output variable and "X" as a name
given to the accumulator. Previous iterations of the code used the variable
`X` as the accumulator, but now that the accumulator is `W[x_index]`, some
of the comments didn't make sense.

Remove the copy of the initial value of `X` into `W[x_index]`, which was
meaningless: the initial value of an output variable should not, and did
not, matter. `W[x_index]` is later overridden unconditionally to take the
value `RR`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-10 15:59:28 +02:00
Dave Rodgman
98ddc01a7c Rename ...if0 to ...else_0
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-10 12:11:31 +01:00
Dave Rodgman
b7825ceb3e Rename uint->bool operators to reflect input types
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-10 11:58:18 +01:00
Gilles Peskine
b2bc1712a5 Reduce the size of the small primes table used by primality testing
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-08-10 12:16:02 +02:00
Dave Rodgman
960eca997d code style
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-09 20:43:18 +01:00
Dave Rodgman
ebcd78561c Remove redundant code in mbedtls_mpi_cmp_abs
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-09 18:57:22 +01:00
Dave Rodgman
fa703e38a2 Use __builtin_ctz to count trailing zeros
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-09 18:56:07 +01:00
Dave Rodgman
f3df105b37 Generate smaller code for picking a sign value
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-09 18:55:41 +01:00
Dave Rodgman
c98f8d996a
Merge branch 'development' into safer-ct5
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-07 11:47:35 +01:00
Dave Rodgman
1d4d944e19
Merge pull request #7933 from tom-cosgrove-arm/add-mbedtls_zeroize_and_free
Provide and use internal function mbedtls_zeroize_and_free()
2023-08-03 12:56:21 +00:00
Chien Wong
e2caf4161b
Fix a few unchecked value issue
Signed-off-by: Chien Wong <m@xv97.com>
2023-08-01 22:41:17 +08:00
Dave Rodgman
1f39f037bf Improve variable name in mbedtls_mpi_lt_mpi_ct
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-08-01 09:19:16 +01:00
Dave Rodgman
32d726033b Improve comments in mbedtls_mpi_lt_mpi_ct
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-07-31 12:43:23 +01:00
Tom Cosgrove
bc345e8685 Protect macro parameter expansion with parentheses
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-07-25 15:17:39 +01:00
Tom Cosgrove
350226f636 Use a macro for mbedtls_mpi_zeroize_and_free()
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-07-25 15:10:14 +01:00
Dave Rodgman
8e8e6b9be3
Merge pull request #7934 from AgathiyanB/move-declarations-to-top
Move declarations to top of functions
2023-07-19 15:25:27 +01:00