mbedtls/tests/suites
Manuel Pégourié-Gonnard 4608c48b0c Rm useless use of MD in PK test functions
Same rationale as previous "Rm useless use of MD" commits.

Here the first two test functions were already not depending on MD_C,
but the new version is much simpler, as it avoids having two versions of
the code depending on the value of USE_PSA.

Changes to the data file generated with the following Python script:

import hashlib

suite = 'pk'
functions = {
        'pk_rsa_verify_test_vec': (2, 1, True),
        'pk_rsa_verify_ext_test_vec': (2, 1, True),
        'pk_sign_verify_restart': (6, 7, False),
}

def hash_ctx(s):
    if s == 'MBEDTLS_MD_MD5':
        return hashlib.md5()
    if s == 'MBEDTLS_MD_SHA1':
        return hashlib.sha1()
    if s == 'MBEDTLS_MD_SHA224':
        return hashlib.sha224()
    if s == 'MBEDTLS_MD_SHA256':
        return hashlib.sha256()
    if s == 'MBEDTLS_MD_SHA384':
        return hashlib.sha384()
    if s == 'MBEDTLS_MD_SHA512':
        return hashlib.sha512()
    if s == 'MBEDTLS_MD_RIPEMD160':
        return hashlib.new("ripemd160")

def fix(l):
    parts = l.rstrip().split(":")

    fun = parts[0]
    if fun not in functions:
        return l

    (alg_idx, msg_idx, is_hex) = functions[fun]

    alg_str = parts[alg_idx]
    if alg_str == "MBEDTLS_MD_NONE" or alg_str == "255":
        return l
    h = hash_ctx(alg_str)

    msg_str = parts[msg_idx][1:-1]
    msg = bytes.fromhex(msg_str) if is_hex else bytes(msg_str, 'ascii')
    h.update(msg)
    msg_hash = h.hexdigest()
    msg_hash_str = '"' + msg_hash + '"'

    parts[msg_idx] = msg_hash_str
    return ":".join(parts) + '\n'

filename = 'tests/suites/test_suite_' + suite + '.data'
with open(filename) as f:
    lines = f.readlines()

lines = [fix(l) for l in lines]

with open(filename, 'w') as f:
    f.writelines(lines)

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-07-18 10:55:56 +02:00
..
helpers.function
host_test.function
main_test.function
test_suite_aes.cbc.data
test_suite_aes.cfb.data
test_suite_aes.ecb.data
test_suite_aes.function
test_suite_aes.ofb.data
test_suite_aes.rest.data
test_suite_aes.xts.data
test_suite_aria.data
test_suite_aria.function
test_suite_asn1parse.data
test_suite_asn1parse.function
test_suite_asn1write.data Fix copypasta in test data 2022-06-15 21:16:42 +02:00
test_suite_asn1write.function Don't call memcpy(NULL, 0) which has undefined behavior 2022-06-27 23:59:53 +02:00
test_suite_base64.data
test_suite_base64.function
test_suite_camellia.data
test_suite_camellia.function
test_suite_ccm.data
test_suite_ccm.function
test_suite_chacha20.data
test_suite_chacha20.function
test_suite_chachapoly.data
test_suite_chachapoly.function
test_suite_cipher.aes.data Use MBEDTLS_TEST_DEPRECATED only in tests 2022-05-19 14:11:06 +02:00
test_suite_cipher.aria.data
test_suite_cipher.camellia.data
test_suite_cipher.ccm.data Use MBEDTLS_TEST_DEPRECATED only in tests 2022-05-19 14:11:06 +02:00
test_suite_cipher.chacha20.data
test_suite_cipher.chachapoly.data
test_suite_cipher.des.data
test_suite_cipher.function Use MBEDTLS_TEST_DEPRECATED only in tests 2022-05-19 14:11:06 +02:00
test_suite_cipher.gcm.data Use MBEDTLS_TEST_DEPRECATED only in tests 2022-05-19 14:11:06 +02:00
test_suite_cipher.misc.data
test_suite_cipher.nist_kw.data
test_suite_cipher.null.data
test_suite_cipher.padding.data
test_suite_cmac.data
test_suite_cmac.function
test_suite_ctr_drbg.data
test_suite_ctr_drbg.function
test_suite_debug.data
test_suite_debug.function
test_suite_des.data
test_suite_des.function
test_suite_dhm.data
test_suite_dhm.function
test_suite_ecdh.data
test_suite_ecdh.function
test_suite_ecdsa.data
test_suite_ecdsa.function
test_suite_ecjpake.data
test_suite_ecjpake.function
test_suite_ecp.data Add test-case for checking curve order 2022-06-17 13:42:40 +01:00
test_suite_ecp.function Fix missing newline 2022-06-17 14:59:36 +01:00
test_suite_entropy.data
test_suite_entropy.function
test_suite_error.data
test_suite_error.function
test_suite_gcm.aes128_de.data
test_suite_gcm.aes128_en.data
test_suite_gcm.aes192_de.data
test_suite_gcm.aes192_en.data
test_suite_gcm.aes256_de.data
test_suite_gcm.aes256_en.data
test_suite_gcm.camellia.data
test_suite_gcm.function
test_suite_gcm.misc.data
test_suite_hkdf.data
test_suite_hkdf.function
test_suite_hmac_drbg.function
test_suite_hmac_drbg.misc.data
test_suite_hmac_drbg.no_reseed.data
test_suite_hmac_drbg.nopr.data
test_suite_hmac_drbg.pr.data
test_suite_md.data
test_suite_md.function
test_suite_mdx.data
test_suite_mdx.function
test_suite_memory_buffer_alloc.data
test_suite_memory_buffer_alloc.function
test_suite_mpi.data Fix null pointer dereference in mpi_mod_int(0, 2) 2022-06-09 19:32:46 +02:00
test_suite_mpi.function
test_suite_mps.data
test_suite_mps.function
test_suite_net.data
test_suite_net.function
test_suite_nist_kw.data
test_suite_nist_kw.function
test_suite_oid.data
test_suite_oid.function
test_suite_pem.data
test_suite_pem.function
test_suite_pk.data Rm useless use of MD in PK test functions 2022-07-18 10:55:56 +02:00
test_suite_pk.function Rm useless use of MD in PK test functions 2022-07-18 10:55:56 +02:00
test_suite_pkcs1_v15.data Adjust test dependencies after last commit 2022-07-16 08:07:51 +02:00
test_suite_pkcs1_v15.function Adjust test dependencies after last commit 2022-07-16 08:07:51 +02:00
test_suite_pkcs1_v21.data
test_suite_pkcs1_v21.function
test_suite_pkcs5.data
test_suite_pkcs5.function
test_suite_pkcs12.data
test_suite_pkcs12.function
test_suite_pkparse.data
test_suite_pkparse.function
test_suite_pkwrite.data
test_suite_pkwrite.function
test_suite_poly1305.data
test_suite_poly1305.function
test_suite_psa_crypto.data Merge pull request #5834 from mprse/HKDF_1 2022-06-20 15:27:46 +02:00
test_suite_psa_crypto.function Merge pull request #5834 from mprse/HKDF_1 2022-06-20 15:27:46 +02:00
test_suite_psa_crypto_attributes.data
test_suite_psa_crypto_attributes.function
test_suite_psa_crypto_driver_wrappers.data
test_suite_psa_crypto_driver_wrappers.function
test_suite_psa_crypto_entropy.data
test_suite_psa_crypto_entropy.function
test_suite_psa_crypto_generate_key.function
test_suite_psa_crypto_hash.data
test_suite_psa_crypto_hash.function
test_suite_psa_crypto_init.data
test_suite_psa_crypto_init.function
test_suite_psa_crypto_metadata.data Add PSA_WANT_ALG_HKDF_EXPAND, PSA_WANT_ALG_HKDF_EXTRACT, adapt code and dependencies 2022-06-03 16:18:15 +02:00
test_suite_psa_crypto_metadata.function test_suite_psa_crypto_metadata: add test cases for the HKDF-Extract/Expand algorithms 2022-06-03 16:18:15 +02:00
test_suite_psa_crypto_not_supported.function
test_suite_psa_crypto_not_supported.misc.data
test_suite_psa_crypto_op_fail.function
test_suite_psa_crypto_op_fail.misc.data
test_suite_psa_crypto_persistent_key.data Add warnings to test code and data about storage format stability 2022-06-20 19:10:35 +02:00
test_suite_psa_crypto_persistent_key.function Add warnings to test code and data about storage format stability 2022-06-20 19:10:35 +02:00
test_suite_psa_crypto_se_driver_hal.data
test_suite_psa_crypto_se_driver_hal.function
test_suite_psa_crypto_se_driver_hal_mocks.data
test_suite_psa_crypto_se_driver_hal_mocks.function
test_suite_psa_crypto_slot_management.data
test_suite_psa_crypto_slot_management.function
test_suite_psa_crypto_storage_format.function exercise_key_agreement_key: add special handling for HKDF_EXPAND 2022-06-14 14:41:42 +02:00
test_suite_psa_crypto_storage_format.misc.data
test_suite_psa_its.data
test_suite_psa_its.function Add warnings to test code and data about storage format stability 2022-06-20 19:10:35 +02:00
test_suite_random.data
test_suite_random.function
test_suite_rsa.data Adjust test dependencies after last commit 2022-07-16 08:38:35 +02:00
test_suite_rsa.function Don't depend on strong entropy for RSA tests 2022-07-16 08:57:19 +02:00
test_suite_shax.data
test_suite_shax.function
test_suite_ssl.data Merge remote-tracking branch 'mbedtls-restricted/development-restricted' into mbedtls-3.2.0rc0-pr 2022-07-11 10:22:37 +02:00
test_suite_ssl.function Fixup test tls13_server_certificate_msg_invalid_vector_len 2022-07-11 11:34:14 +01:00
test_suite_timing.data
test_suite_timing.function
test_suite_version.data Bump library and so versions for 3.2.0 release 2022-07-11 13:56:01 +01:00
test_suite_version.function
test_suite_x509parse.data Fix case where final special char exceeds buffer 2022-06-27 12:01:22 +01:00
test_suite_x509parse.function Add tests for exceeded buffer size 2022-06-27 11:23:43 +01:00
test_suite_x509write.data Fix parsing of special chars in X509 DN values 2022-06-27 11:19:50 +01:00
test_suite_x509write.function Use ASN1 UTC tags for dates before 2000 2022-06-01 16:24:28 +01:00