1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00
Commit Graph

18895 Commits

Author SHA1 Message Date
Dave Rodgman
e0ad9a4707 Misc CT robustness improvements
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 19:26:08 +01:00
Dave Rodgman
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
Dave Rodgman
1d52368e85 build fixes
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 16:26:49 +01:00
Dave Rodgman
c1a17f5458 CT fix for get_zeros_padding
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
Dave Rodgman
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
Dave Rodgman
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
Dave Rodgman
9f3f73d212 CT fix for get_pkcs_padding
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
Dave Rodgman
40dc3b3727 CT fixes in nist_kw
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
Dave Rodgman
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
Dave Rodgman
c280520999 Eliminate duplicate ct memcmp
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-09-20 15:14:28 +01:00
Dave Rodgman
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
Gilles Peskine
3591cc61f2 Merge pull request #8103 from gilles-peskine-arm/7961-2.28
Backport 2.28: parts of #7961
2023-09-18 08:13:08 +00:00
Gilles Peskine
433aa1cc5c Merge pull request #8218 from paul-elliott-arm/remove_unused_values_programs_2_28
Backport 2.28: Remove unneeded setting of ret from ssl programs
2023-09-18 08:13:05 +00:00
Paul Elliott
2391649e7e Remove unneeded setting of ret from ssl programs
Remove a coverity warning on unused values.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2023-09-15 17:45:43 +01:00
Gilles Peskine
fac34d7dbf Merge pull request #1065 from waleed-elmelegy-arm/backport-add-new-pkcs12-pbe2-ext-fun
Backport 2.28: Add new pkcs12 pbe2 ext fun
2023-09-15 18:43:00 +02:00
Gilles Peskine
9cacae3c7a Merge remote-tracking branch 'upstream-public/mbedtls-2.28' into HEAD 2023-09-15 18:32:36 +02:00
Waleed Elmelegy
d24b546f3d Reduce line size in new pkcs function changelog
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-15 15:35:08 +01:00
Waleed Elmelegy
58ed2318c5 Modify changelog entry to add pkcs12 pbe functions
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-15 15:34:47 +01:00
Waleed Elmelegy
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
Waleed Elmelegy
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
Pengyu Lv
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
Gilles Peskine
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
Gilles Peskine
3d9978e9b3 Merge pull request #8172 from ronald-cron-arm/psa-config-add-comment
Backport 2.28: Add comment about HKDF in config_psa.h
2023-09-13 12:56:02 +00:00
Pengyu Lv
e707dc1bb5 aesni: refine the condition of MBEDTLS_HAVE_X86_64
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-13 18:10:41 +08:00
Pengyu Lv
dc5a88b6a4 aesni: make AESNI only operate on X86 and X86_64
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-13 18:10:41 +08:00
Pengyu Lv
5a0915953a aesni: define MBEDTLS_HAVE_X86
Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2023-09-13 18:10:25 +08:00
Dave Rodgman
fcbcf57753 Merge pull request #8194 from gilles-peskine-arm/bump_version-doc_mainpage-2.28
Backport 2.28: Update capitalization of "Mbed" and fix bump_version.sh
2023-09-13 08:41:13 +00:00
Gilles Peskine
bd26a8de92 More spelling corrections
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-12 19:22:08 +02:00
Gilles Peskine
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
Gilles Peskine
bd44d93ee9 Allow "Mbed TLS" as the project name in Doxygen
Previously the code only recognized the old spelling "mbed TLS", so it
missed doxygen/input/doc_mainpage.h.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-12 19:21:37 +02:00
Ronald Cron
fa9392abcd PSA config: Add comment about HKDF.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-09-12 09:22:52 +02:00
Dave Rodgman
198fbc2c99 Merge pull request #8173 from gilles-peskine-arm/config-boolean-options-wrong-section-202309-2.28
Backport 2.28: Fix boolean options in the wrong section
2023-09-11 15:09:06 +00:00
Gilles Peskine
7fa5934302 Merge pull request #1056 from waleed-elmelegy-arm/Backport-improve-and-test-mbedtls_pkcs12_pbe
Backport 2.28: Improve & test legacy mbedtls_pkcs12_pbe
2023-09-11 14:32:20 +02:00
Waleed Elmelegy
6d5a5c17b1 Improve pkcs12 pbe tests
* Simplify pkcs12 tests to use algo parameters instead of asn1 buffers.
* Fix output buffers allocation size.

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-08 16:19:20 +01:00
Waleed Elmelegy
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
Gilles Peskine
3a11771bae Pacify pylint
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-08 11:17:09 +02:00
Gilles Peskine
e008890afa Update generated files
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-07 19:20:34 +02:00
Gilles Peskine
937b91eb6f Fix boolean options in the wrong section
Boolean options that modify the behavior of a module are supposed to be in
the "feature support" section, not in the "configuration options" support:
that section is documented to contain commented-out definitions with a
value, for which the comment contains the default version. In particular,
merely uncommenting a definition in the "configuration options" section is
not supposed to change anything.

Move the offending boolean options to the proper section.

This causes those options to be enabled by `config.py full` unless
explicitly excluded. For the moved options:

* Everest is already explicitly excluded.
* The ALT options need to link against a custom function, so exclude them.
* `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` is ok for testing, and is
  currently never tested in `all.sh`. With this commit, we will now test the
  library with it enabled in configurations based on `full`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-09-07 17:40:16 +02:00
Yanray Wang
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
Yanray Wang
c9d5ea9a9c pkwrite.c: write ChangeLog accurately
The heap memory is used for both RSA and EC keys. So removing `RSA`
in the ChangeLog.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:32:44 +08:00
Yanray Wang
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
Yanray Wang
79873bcf56 pkwrite: add Changelog entry
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-09-06 10:32:22 +08:00
Yanray Wang
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
Yanray Wang
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
Yanray Wang
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
Gilles Peskine
f0accf28ea Merge pull request #1054 from waleed-elmelegy-arm/backport-add-new-pkcs5-pbe2-ext-fun
Backport 2.28: Add new pkcs5 pbe2 ext fun
2023-09-05 18:52:21 +02:00
Dave Rodgman
06c466d869 Merge pull request #8158 from tom-cosgrove-arm/rename-assert_compare-to-test_assert_compare-2.28
Backport 2.28: Rename test macros ASSERT_COMPARE(), ASSERT_ALLOC() and ASSERT_ALLOC_WEAK()
2023-09-05 10:18:39 +00:00
Tom Cosgrove
5c46332184 Merge pull request #8146 from tom-cosgrove-arm/define-psa-macros-to-1-2.28
Backport 2.28: Define all PSA_xxx macros to 1 rather than have them empty, for consistency
2023-09-04 22:26:54 +01:00
Waleed Elmelegy
525e355563 Change pkcs5 test dependencies from MBEDTLS_SHA1_C to MBEDTLS_MD_CAN_SHA1
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2023-09-04 18:20:32 +01:00
Waleed-Ziad Maamoun-Elmelegy
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