7249 Commits

Author SHA1 Message Date
David Horstmann
cdaee54773 Fix incorrect printing of OIDs
The first 2 components of an OID are combined together into the same
subidentifier via the formula:

subidentifier = (component1 * 40) + component2

The current code extracts component1 and component2 using division and
modulo as one would expect. However, there is a subtlety in the
specification[1]:

>This packing of the first two object identifier components recognizes
>that only three values are allocated from the root node, and at most
>39 subsequent values from nodes reached by X = 0 and X = 1.

If the root node (component1) is 2, the subsequent node (component2)
may be greater than 38. For example, the following are real OIDs:
* 2.40.0.25, UPU standard S25
* 2.49.0.0.826.0, Met Office
* 2.999, Allocated example OID

This has 2 implications that the current parsing code does not take
account of:
1. The second component may be > 39, so (subidentifier % 40) is not
correct in all circumstances.
2. The first subidentifier (containing the first 2 components) may be
more than one byte long. Currently we assume it is just 1 byte.

Improve parsing code to deal with these cases correctly.

[1] Rec. ITU-T X.690 (02/2021), 8.19.4

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
Paul Elliott
fc820d96e0 Fix IAR warnings
IAR was warning that conditional execution could bypass initialisation of
variables, although those same variables were not used uninitialised. Fix
this along with some other IAR warnings.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-02-13 15:07:44 +00:00
Sergey
26f53f107e
Fix compiler warning: unreachable code
Signed-off-by: Sergey <sergio_nsk@yahoo.de>
2023-02-11 18:20:20 -07:00
hanno-becker
c4f885dc02 X.509: Remove red'n bounds checks and zeroiz'n in OtherName parsing
- ASN.1 parsing functions check that length don't exceed buffer bounds,
  so checks `p + len > end` are redundant.
- If `p + len == end`, this is erroneous because we expect further fields,
  which is automatically caught by the next ASN.1 parsing call.

Hence, the two branches handling `p + len >= end` in x509_get_other_name()
can be removed.

Further, zeroization of the `other_name` structure isn't necessary
because it's not confidential (and it's also not performed on other
error conditions in this function).
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-02-08 08:50:01 -05:00
hanno-becker
75ab076971 Fix X.509 SAN parsing
Fixes #2838. See the issue description for more information.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-02-08 08:46:42 -05:00
Dave Rodgman
ecb44208d1 Address missed instances of sizeof
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-02 15:34:23 +00:00
Dave Rodgman
1868870fba Fix use of sizeof without brackets
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-02 12:46:39 +00:00
Aaron M. Ucko
78b823ab0e mbedtls_mpi_sub_abs: Skip memcpy when redundant (#6701).
In some contexts, the output pointer may equal the first input
pointer, in which case copying is not only superfluous but results in
"Source and destination overlap in memcpy" errors from Valgrind (as I
observed in the context of ecp_double_jac) and a diagnostic message
from TrustInSoft Analyzer (as Pascal Cuoq reported in the context of
other ECP functions called by cert-app with a suitable certificate).

Signed-off-by: Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>
2023-01-31 15:45:44 -05:00
Manuel Pégourié-Gonnard
4b7cb8c737
Merge pull request #6919 from valeriosetti/issue6843-backport
Backport: Improve X.509 cert writing serial number management
2023-01-30 13:09:09 +01:00
Andrzej Kurek
3a261a4dfd Add a selftest run for the TIMING_ALT test
The fuzz programs require one layer of directories
more when adding include directories.
Also remove an unnecessary include directory in the Makefile.

Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-01-26 04:33:59 -05:00
Andrzej Kurek
c890b22fb3 Add a test for external alternate timing implementation
Copy the original implementation
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-01-17 05:11:29 -05:00
Andrzej Kurek
cf4e9999bc Enable the timing.c selftest with MBEDTLS_TIMING_ALT
This caused trouble for users that were using the selftest feature
along with an alternative implementation. They were forced to 
provide their own version of a selftest. Since it was not mentioned
in the define description, it should not be required, and is provided
roughly as it was before breaking changes in 77daaad198 were
introduced.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-01-13 19:01:51 -05:00
Valerio Setti
b37f6c1b95 x509write_crt: reject serial longer than X509_RFC5280_MAX_SERIAL_LEN
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2023-01-13 08:39:36 +01:00
Gilles Peskine
ec03b0431d Update generated files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:52:37 +01:00
Gilles Peskine
1b6c09a62e Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:52:35 +01:00
Gilles Peskine
dc633d9393 Remove redundant error code definitions
We're including psa/crypto_values.h, which defines the necessary error
codes. Remove redundant definitions, which hurt because they need to be
styled in exactly the same way (same presence/absence of spaces between
tokens).

This completes the fix of https://github.com/Mbed-TLS/mbedtls/issues/6875.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 11:33:11 +01:00
Glenn Strauss
b6466c88df Fix IAR warning
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-01-06 11:31:54 +00:00
David Horstmann
b6bf5f5533 Workaround Uncrustify parsing of "asm"
The following code:

 #ifndef asm
 #define asm __asm
 #endif

causes Uncrustify to stop correcting the rest of the file. This may be
due to parsing the "asm" keyword in the definition.

Work around this by wrapping the idiom in an *INDENT-OFF* comment
wherever it appears.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-01-03 11:27:18 +00:00
Dave Rodgman
b03c55892a Fix overflow in mbedtls_timing_hardclock()
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-12-20 13:20:01 +00:00
Dave Rodgman
4547eae341
Merge pull request #984 from Mbed-TLS/mbedtls-2.28.2-merge-back
Mbedtls 2.28.2 merge back
2022-12-14 17:51:58 +00:00
Manuel Pégourié-Gonnard
1d1baa7fc3
Merge pull request #6586 from lpy4105/2.28-check-psa-name-typo
Backport 2.28: check_names: extend typo check to PSA macro/enum names
2022-12-13 09:24:56 +01:00
Zachary Fleckenstein
4364fc94c1 Fix typo in library/entropy.c
Signed-off-by: Zachary Fleckenstein <ZachFleck42@Gmail.com>
2022-12-09 09:26:42 -05:00
Manuel Pégourié-Gonnard
0e0793f4ac
Merge pull request #6706 from davidhorstmann-arm/2.28-code-style-script-non-corrected
[Backport 2.28] Add code style correction script
2022-12-09 09:41:27 +01:00
Gilles Peskine
9f54092a01 Avoid unstructured macro usage with code duplication
Instead of
```
 #if CONDITION
    for(XXX)
        for(YYY)
 #else
    for(XXX)
        for(YYY)
 #endif
            BODY
```
duplicate the BODY code. This isn't ideal, but we can live with it.

The compelling reason to restructure the code is that this entanglement
of C preprocessor syntax with C grammar syntax confuses uncrustify.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-08 21:50:34 +01:00
Aditya Deshpande
7428c61df2 Bump LTS version to 2.28.2
Signed-off-by: Aditya Deshpande <aditya.deshpande@arm.com>
2022-12-08 11:05:11 +00:00
Aditya Deshpande
dbefba7b5c Merge branch 'mbedtls-2.28-restricted' into mbedtls-2.28.2rc0-pr 2022-12-08 10:57:08 +00:00
Dave Rodgman
5c581dd602
Merge pull request #6735 from daverodgman/fix_test_dep_spelling_2.28
Backport 2.28: Fix spelling of test dependency
2022-12-07 09:06:39 +00:00
Dave Rodgman
a03396a9df Fix additional mis-spellings
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-12-06 16:30:38 +00:00
Tom Cosgrove
e87c335272 Fix another typo where 'PSK' was 'PKS'
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-05 12:08:26 +00:00
Dave Rodgman
f0090d85e5 Merge remote-tracking branch 'origin/mbedtls-2.28' into merge-2.28 2022-12-05 11:04:05 +00:00
Tom Cosgrove
c1b9842da5 Don't change typos in debug messages used by ssl-opt.sh
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-05 08:29:36 +00:00
Tom Cosgrove
49f99bc3db Fix typos prior to release
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-04 16:44:21 +00:00
Dave Rodgman
ed179db976
Merge pull request #6657 from gilles-peskine-arm/psa-ecb-null-0-2.28
Backport 2.28: Fix NULL+0 undefined behavior in PSA crypto ECB
2022-11-25 17:07:36 +00:00
Gilles Peskine
ff97f336e3 Explain why p + n isn't good enough
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-25 13:35:51 +01:00
Gilles Peskine
d551413027 Remove now-redundant definitions of inline
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-25 13:27:34 +01:00
Dave Rodgman
b400fb0b76
Merge pull request #6452 from AndrzejKurek/depends-py-reloaded-2-28
[Backport 2.28] Unified tests/scripts/depends.py - reloaded
2022-11-24 10:59:31 +00:00
Gilles Peskine
8fe23a065a Fix MSVC 12 (Visual Studio 2013) choking on inline
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-23 17:24:37 +01:00
Gilles Peskine
01bf631159 Fix NULL+0 undefined behavior in ECB encryption and decryption
psa_cipher_encrypt() and psa_cipher_decrypt() sometimes add a zero offset to
a null pointer when the cipher does not use an IV. This is undefined
behavior, although it works as naively expected on most platforms. This
can cause a crash with modern Clang+ASan (depending on compiler optimizations).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-23 17:23:44 +01:00
Janos Follath
b118d54ff6 mpi_exp_mod: use x_index consistently
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 15:00:46 +00:00
Janos Follath
6c5b5adb46 mpi_exp_mod: reduce the table size by one
The first half of the table is not used, let's reuse index 0 for the
result instead of appending it in the end.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:47:10 +00:00
Janos Follath
6fa7a766cc mpi_exp_mod: fix out of bounds access
The table size was set before the configured window size bound was
applied which lead to out of bounds access when the configured window
size bound is less.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:21:52 +00:00
Janos Follath
2b72690e14 mpi_mod_exp: be pedantic about right shift
The window size starts giving diminishing returns around 6 on most
platforms and highly unlikely to be more than 31 in practical use cases.
Still, compilers and static analysers might complain about this and
better to be pedantic.

Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:21:03 +00:00
Gilles Peskine
b358e46c8e
Merge pull request #6618 from gilles-peskine-arm/mpi_sint-min-ub-2.28
Backport 2.28: Fix undefined behavior in bignum: NULL+0 and -most-negative-sint
2022-11-21 19:52:03 +01:00
Janos Follath
6e2d8e3e28 mpi_exp_mod: improve documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 16:14:54 +00:00
Janos Follath
d88e21941c mpi_exp_mod: remove the 'one' variable
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 15:54:20 +00:00
Janos Follath
a92f9155a5 mpi_exp_mod: simplify freeing loop
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 15:05:31 +00:00
Janos Follath
aadbadbf42 mpi_exp_mod: move X next to the precomputed values
With small exponents (for example, when doing RSA-1024 with CRT, each
prime is 512 bits and we'll use wsize = 5 which may be smaller that the
maximum - or even worse when doing public RSA operations which typically
have a 16-bit exponent so we'll use wsize = 1) the usage of W will have
pre-computed values, then empty space, then the accumulator at the very
end.

Move X next to the precomputed values to make accesses more efficient
and intuitive.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 14:55:05 +00:00
Janos Follath
6632383993 mpi_exp_mod: rename local variables
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 14:48:02 +00:00
Janos Follath
f0ceb1cae1 mpi_exp_mod: remove memory ownership confusion
Elements of W didn't all have the same owner: all were owned by this
function, except W[x_index]. It is more robust if we make a proper copy
of X.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 14:31:22 +00:00
Gilles Peskine
ae7cbd7576 Express abs(z) in a way that satisfies GCC and MSVC
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-17 11:03:46 +01:00