1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-07 12:21:11 +03:00
Commit Graph

7418 Commits

Author SHA1 Message Date
3ccb844117 Merge pull request #8373 from sergio-nsk/sergio-nsk/8372/1
Backport 2.28: Fix compiling AESNI in Mbed-TLS with clang on Windows
2023-10-26 15:59:05 +00:00
37b8478ab8 Merge pull request #8403 from daverodgman/iar-fixes-2.28
Backport 2.28: Stop IAR warning about goto skipping variable definition
2023-10-23 14:59:33 +01:00
2af05c857a Stop IAR warning about goto skipping variable definition
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-10-23 11:04:36 +01:00
f3c6e2ee34 aesni: select __cpuid impl based on compiler type
MinGW provides both kinds of implementations of `__cpuid`,
but since `cpuid.h` is provided by GNUC, so we should choose
the implementation by the compiler type instead of OS type.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-10-19 16:45:37 +08:00
79d7faf030 aesni: declare cpuinfo as int
Change the type of array that stores the cpuinfo
data to int[4] to match the signature of `__cpuinfo`
in `intrin.h` header file.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-10-19 16:45:37 +08:00
2856e076e6 aesni: support cpuid on WIN32
`__cpuid` has two kinds of signatures in different
headers depending on the target OS. We make it
consistent between the usages ang the included header.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-10-19 16:45:36 +08:00
9902a6b752 Fix #8372 - Error compiling AESNI in Mbed-TLS with clang on Windows
It can successfully compile w/ or w/o the clang options -maes -mpclmul.

Signed-off-by: Sergey Markelov <sergey@solidstatenetworks.com>
2023-10-18 20:26:01 -07:00
01902779a3 Merge pull request #8162 from yanrayw/2.28-save_stack_usage_pkwrite
Backport 2.28: pkwrite: use heap to save stack usage for writing keys in PEM string
2023-10-13 14:27:18 +00:00
1222ae67d5 Rename local variable in aes.c
This changes local variable name RCON to round_constants.

RCON being definition in xc32 compiler headers for some PIC32 register.
Without this change mynewt project for PIC32 platform fails to build due to
macro redefinition.

This does not changes behavior of library in any way.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
2023-10-12 09:16:34 +02:00
c7a8ea998d Bump version to 2.28.5
```
./scripts/bump_version.sh --version 2.28.5
```

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 22:24:04 +01:00
6d169947e9 Merge branch 'mbedtls-2.28-restricted' into mbedtls-2.28.5rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2023-10-03 22:22:36 +01:00
da635ab657 Merge pull request #8280 from gilles-peskine-arm/ssl_cache-negative_errors-2.28
Backport 2.28: ssl_cache: misc improvements
2023-09-29 17:58:10 +00:00
fe4d93ad4d ssl_cache: return error codes on error
mbedtls_ssl_cache_get() and mbedtls_ssl_cache_set() returned 1 on many error
conditions. Change this to returning a negative MBEDTLS_ERR_xxx error code.

Completeness: after this commit, there are no longer any occurrences of
`return 1` or `ret = 1`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-29 13:40:33 +02:00
917dd8bd81 Add new error code for SSL cache entry not found
There was no good error to return in this case.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-29 13:39:49 +02:00
930679a1d7 Make mbedtls_ecdsa_can_do definition unconditional
Signed-off-by: JonathanWitthoeft <jonw@gridconnect.com>
2023-09-29 13:31:48 +02:00
bfb0b39460 Bug Fix: mbedtls_ecdsa_verify_restartable fails with ECDSA_SIGN_ALT
When ECDSA_SIGN_ALT but not ECDSA_VERIFY_ALT, mbedtls_ecdsa_can_do was not being defined causing mbedtls_ecdsa_verify_restartable to always fail

Signed-off-by: JonathanWitthoeft <jonw@gridconnect.com>
2023-09-29 13:31:47 +02:00
7a8ec0f56c Merge pull request #8209 from lpy4105/issue/8168/2.28_fix-aesni-selection
2.28: Fix AESNI selection
2023-09-26 16:55:28 +00:00
0ab94d1239 Merge pull request #1077 from daverodgman/better-ct-2.28
2.28 backport - Use CT module more consistently
2023-09-25 11:50:16 +01:00
326ba3c0bb mbedtls_ssl_decrypt_buf(): fix buffer overread with stream cipher
With stream ciphers, add a check that there's enough room to read a MAC in
the record. Without this check, subtracting the MAC length from the data
length resulted in an integer underflow, causing the MAC calculation to try
reading (SIZE_MAX + 1 - maclen) bytes of input, which is a buffer overread.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-21 18:25:05 +02:00
6063d82f04 Correct macro guards in constant_time_internal.h
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 21:54:15 +01:00
5ea6bb06a7 Add cast for MSVC
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 20:14:15 +01:00
caa942569f Improve return value handling
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 19:26:08 +01:00
e0ad9a4707 Misc CT robustness improvements
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 19:26:08 +01:00
1924adbf99 Fix macro guards for mbedtls_ct_size_mask
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 18:00:47 +01:00
1d52368e85 build fixes
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 16:26:49 +01:00
c1a17f5458 CT fix for get_zeros_padding
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
51773aa68b CT fix for get_zeros_and_len_padding
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
df254f6bb6 CT fix for get_one_and_zeros_padding
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
9f3f73d212 CT fix for get_pkcs_padding
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
40dc3b3727 CT fixes in nist_kw
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
954a2da1e4 Use mbedtls_ct_memcmp in mbedtls_rsa_rsaes_oaep_decrypt
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
c280520999 Eliminate duplicate ct memcmp
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
f4cf4a6e25 Merge pull request #1070 from gilles-peskine-arm/merge-2.28-restricted-20230915
Merge mbedtls-2.28 into restricted
2023-09-20 12:07:55 +01:00
9cacae3c7a Merge remote-tracking branch 'upstream-public/mbedtls-2.28' into HEAD 2023-09-15 18:32:36 +02:00
f919393e05 Return back to modifying input parameters in pkcs12_parse_pbe_params
Return back to modifying input parameters in pkcs12_parse_pbe_params
to avoid change in behaviour.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-15 15:34:25 +01:00
6060cf1043 Add new mbedtls_pkcs12_pbe_ext function to replace old function
Add new mbedtls_pkcs12_pbe_ext function to replace
old mbedtls_pkcs12_pbe function that have security
issues.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-15 15:33:39 +01:00
7fb6fc60ce padlock: introduce MBEDTLS_VIA_PADLOCK_HAVE_CODE
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-14 14:02:02 +08:00
51616459fa Merge pull request #7211 from sergio-nsk/patch-3
mbedtls-2.28: Fix llvm error: variable 'default_iv_length' may be used uninitialized
2023-09-13 16:39:08 +02:00
f08ca83b4f Update spelling "mbed TLS" to "Mbed TLS"
The official spelling of the trade mark changed from all-lowercase "mbed"
to normal proper noun capitalization "Mbed" a few years ago. We've been
using the new spelling in new text but still have the old spelling in a
lot of text. This commit updates most occurrences of "mbed TLS":

```
sed -i -e 's/mbed TLS/Mbed TLS/g' $(git ls-files ':!ChangeLog' ':!tests/data_files/**' ':!tests/suites/*.data' ':!programs/x509/*' ':!configs/tfm*')
```

Justification for the omissions:

* `ChangeLog`: historical text.
* `test/data_files/**`, `tests/suites/*.data`, `programs/x509/*`: many
  occurrences are significant names in certificates and such. Changing
  the spelling would invalidate many signatures and tests.
* `configs/tfm*`: this is an imported file. We'll follow the upstream
  updates.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-12 19:21:54 +02:00
38a89ad507 Improve & test legacy mbedtls_pkcs12_pbe
* Prevent pkcs12_pbe encryption when PKCS7 padding has been
  disabled since this not part of the specs.
* Allow decryption when PKCS7 padding is disabled for legacy
  reasons, However, invalid padding is not checked.
* Document new behaviour, known limitations and possible
  security concerns.
* Add tests to check these scenarios. Test data has been
  generated by the below code using OpenSSL as a reference:

int main()
{
    char pass[] = "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB";
    unsigned char salt[] = "\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC";
    unsigned char plaintext[] = "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
    unsigned char *ciphertext = NULL;
    int iter = 10;
    X509_ALGOR *alg =  X509_ALGOR_new();
    int ciphertext_len = 0;
    int alg_nid = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
    alg->parameter = ASN1_TYPE_new();
    struct asn1_object_st * aobj;
    PKCS5_pbe_set0_algor(alg, alg_nid, iter,
                         salt, sizeof(salt)-1);

    aobj = alg->algorithm;
    printf("\"30%.2X", 2 + aobj->length + alg->parameter->value.asn1_string->length);
    printf("06%.2X", aobj->length);
    for (int i = 0; i < aobj->length; i++) {
        printf("%.2X", aobj->data[i]);
    }

    for (int i = 0; i < alg->parameter->value.asn1_string->length; i++) {
        printf("%.2X", alg->parameter->value.asn1_string->data[i]);
    }
    printf("\":\"");

    for (int i = 0; i < sizeof(pass)-1; i++) {
        printf("%.2X", pass[i] & 0xFF);
    }
    printf("\":\"");
    for (int i = 0; i < sizeof(plaintext)-1; i++) {
        printf("%.2X", plaintext[i]);
    }
    printf("\":");
    printf("0");
    printf(":\"");

    unsigned char * res = PKCS12_pbe_crypt(alg, pass, sizeof(pass)-1, plaintext, sizeof(plaintext)-1, &ciphertext, &ciphertext_len, 1);

    if (res == NULL)
        printf("Encryption failed!\n");
    for (int i = 0; i < ciphertext_len; i++) {
        printf("%.2X", res[i]);
    }
    printf("\"\n");

    return 0;
}

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-08 15:13:54 +01:00
e008890afa Update generated files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-07 19:20:34 +02:00
4b0b97e18b pkwrite: zeroize buf containing info of private key
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:36:17 +08:00
b59b7c643b pkwrite.c: call calloc and free properly
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:32:35 +08:00
a8f00508fe pkwrite.c: add a cleanup label to save code size
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:32:04 +08:00
7bbca1363f pkwrite.c: save stack usage for pk_write_key_pem
mbedtls_pk_write_key_pem would allocate 5679 bytes in writing a DER
encoded RSA private key. To save stack usage significantly, we use
heap memory instead.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:30:36 +08:00
217416a76e pkwrite.c: save stack usage for pk_write_pubkey_pem
mbedtls_pk_write_pubkey_pem would allocate 2086 bytes in writing a DER
encoded RSA public key. To save stack usage significantly, we use
heap memory instead.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:28:09 +08:00
09f0a97d74 Fix typo in pkcs5.c
Co-authored-by: Janos Follath <janos.follath@arm.com>
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 18:02:14 +01:00
dcad168acf Improve mbedtls_pkcs5_pbes2_ext function test data
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:56:39 +01:00
b66cb65410 Add new mbedtls_pkcs5_pbe2_ext function
Add new mbedtls_pkcs5_pbe2_ext function to replace old
function with possible security issues.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 17:46:26 +01:00
73285cc075 Define all PSA_xxx macros to 1 rather than have them empty, for consistency
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-01 13:07:39 +01:00