1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00
Commit Graph

7617 Commits

Author SHA1 Message Date
2808a6047c Improve the presentation of assembly blocks
Uncrustify indents
```
    asm("foo"
        HELLO "bar"
              "wibble");
```
but we would like
```
    asm("foo"
        HELLO "bar"
        "wibble");
```
Make "bar" an argument of the macro HELLO, which makes the indentation from
uncrustify match the semantics (everything should be aligned to the same
column).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:10 +00:00
18d521a57d Don't warn about Msan/Valgrind if AESNI isn't actually built
The warning is only correct if the assembly code for AESNI is built, not if
MBEDTLS_AESNI_C is activated but MBEDTLS_HAVE_ASM is disabled or the target
architecture isn't x86_64.

This is a partial fix for #7236.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:07 +00:00
6055b78328 Update bibliographic references
There are new versions of the Intel whitepapers and they've moved.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-03-17 16:31:05 +00:00
6b8e8ff079 Fix segfault in mbedtls_oid_get_numeric_string
When passed an empty OID, mbedtls_oid_get_numeric_string would read one
byte from the zero-sized buffer and return an error code that depends on
its value.  This is demonstrated by the test suite changes, which
check that an OID with length zero and an invalid buffer pointer does
not cause Mbed TLS to segfault.

Also check that second and subsequent subidentifiers are terminated, and
add a test case for that.  Furthermore, stop relying on integer division
by 40, use the same loop for both the first and subsequent
subidentifiers, and add additional tests.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
2023-03-16 01:07:35 -04:00
39987ebde7 Merge pull request #7172 from daverodgman/fix_UB_in_ssl_read-2.28
Backport 2.28: Fix undefined behavior in ssl_read if buf parameter is NULL
2023-03-13 10:46:24 +00:00
04eb7c032e Fix llvm error: variable 'default_iv_length' may be used uninitialized
Backport of https://github.com/Mbed-TLS/mbedtls/pull/7210

Signed-off-by: Sergey <sergio_nsk@yahoo.de>
2023-03-06 15:37:23 -07:00
1215557e91 Add corresponding fix for mbedtls_ssl_write
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-24 16:02:26 +00:00
cf01d78e7e Update library/ssl_msg.c
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-24 16:02:26 +00:00
272cc19ab5 Fixed undefined behavior in ssl_read if buf parameter is NULL.
Signed-off-by: Ashley Duncan <ashes.man@gmail.com>
2023-02-24 16:02:25 +00:00
d784833a1b Silence a warning from Clang >=15 about an unused local variable
The assembly code uses t only on some architectures. Fixes #7166.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-02-24 12:08:57 +01:00
ec1eff386c Make \retval commands non-empty
Pacify Clang >=15 which complained:
```
include/psa/crypto.h:91:23: error: empty paragraph passed to '\retval' command [-Werror,-Wdocumentation]
 * \retval #PSA_SUCCESS
   ~~~~~~~~~~~~~~~~~~~^
```

This commit performs the following systematic replacement:
```
perl -i -0777 -p -e 's/([\\@])(retval +\S+)\n(?! *\*? *([^\n \\*\/]|\\[cp]\b))/$1$2 ${1}emptydescription\n/g' $(git ls-files '*.[hc]' '*.function' '*.jinja')
```
i.e. add an `\emptydescription` argument to `\retval` commands (or
`@retval`, which we don't normally used) that are followed by a single word,
unless the next line looks like it contains text which would be the
description.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-02-24 11:41:45 +01:00
4dcc08c244 Merge pull request #7138 from davidhorstmann-arm/2.28-fix-oid-printing-bug
[Backport 2.28] Fix bugs in OID to string conversion
2023-02-21 23:16:48 +01:00
b0926916f6 Merge pull request #7086 from tom-cosgrove-arm/dont-use-lstrlenW-228
Backport 2.28: Don't use lstrlenW() on Windows
2023-02-20 15:11:32 +00:00
0518d53ba7 Change error codes to more appropriate codes
The more precise error codes are borrowed from the ASN1 module.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
d138181190 Change += to |= for clearer semantics
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
8f81d8a305 Make overflow checks more readable
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
beb90e30de Disallow overlong encoding when parsing OIDs
OID subidentifiers are encoded as follow. For every byte:
* The top bit is 1 if there is another byte to come, 0 if this is the
last byte.
* The other 7 bits form 7 bits of the number. These groups of 7 are
concatenated together in big-endian order.

Overlong encodings are explicitly disallowed by the BER/DER/X690
specification. For example, the number 1 cannot be encoded as:

0x80 0x80 0x01

It must be encoded as:

0x01

Enforce this in Mbed TLS' OID DER-to-string parser.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-02-20 14:44:18 +00:00
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
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
26f53f107e Fix compiler warning: unreachable code
Signed-off-by: Sergey <sergio_nsk@yahoo.de>
2023-02-11 18:20:20 -07:00
0289c19b8a Don't use lstrlenW() on Windows
The lstrlenW() function isn't available to UWP apps, and isn't necessary, since
when given -1, WideCharToMultiByte() will process the terminating null character
itself (and the length returned by the function includes this character).

Resolves #2994

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-02-10 21:48:33 +00:00
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
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
ecb44208d1 Address missed instances of sizeof
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-02 15:34:23 +00:00
1868870fba Fix use of sizeof without brackets
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-02-02 12:46:39 +00:00
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
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
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
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
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
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
ec03b0431d Update generated files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:52:37 +01:00
1b6c09a62e Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:52:35 +01:00
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
b6466c88df Fix IAR warning
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-01-06 11:31:54 +00:00
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
b03c55892a Fix overflow in mbedtls_timing_hardclock()
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-12-20 13:20:01 +00:00
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
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
4364fc94c1 Fix typo in library/entropy.c
Signed-off-by: Zachary Fleckenstein <ZachFleck42@Gmail.com>
2022-12-09 09:26:42 -05:00
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
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
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
dbefba7b5c Merge branch 'mbedtls-2.28-restricted' into mbedtls-2.28.2rc0-pr 2022-12-08 10:57:08 +00:00
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
a03396a9df Fix additional mis-spellings
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-12-06 16:30:38 +00:00
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
f0090d85e5 Merge remote-tracking branch 'origin/mbedtls-2.28' into merge-2.28 2022-12-05 11:04:05 +00:00
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
49f99bc3db Fix typos prior to release
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-04 16:44:21 +00:00