Skip to content
0.2.0-dev Download ZIP
57 lines ·2.4 KB Raw
1/**
2 * \file rsa_invasive.h
3 *
4 * \brief Function declarations for invasive testing of built-in RSA.
5 */
6/**
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 */
10
11#ifndef TF_PSA_CRYPTO_RSA_INVASIVE_H
12#define TF_PSA_CRYPTO_RSA_INVASIVE_H
13
14#if defined(MBEDTLS_TEST_HOOKS)
15
16#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C)
17/** This function performs the unpadding part of a PKCS#1 v1.5 decryption
18 * operation (EME-PKCS1-v1_5 decoding).
19 *
20 * \note The return value from this function is a sensitive value
21 * (this is unusual). #PSA_ERROR_BUFFER_TOO_SMALL shouldn't happen
22 * in a well-written application, but 0 vs #PSA_ERROR_INVALID_PADDING
23 * is often a situation that an attacker can provoke and leaking which
24 * one is the result is precisely the information the attacker wants.
25 *
26 * \param input The input buffer which is the payload inside PKCS#1v1.5
27 * encryption padding, called the "encoded message EM"
28 * by the terminology.
29 * \param ilen The length of the payload in the \p input buffer.
30 * \param output The buffer for the payload, called "message M" by the
31 * PKCS#1 terminology. This must be a writable buffer of
32 * length \p output_max_len bytes.
33 * \param olen The address at which to store the length of
34 * the payload. This must not be \c NULL.
35 * \param output_max_len The length in bytes of the output buffer \p output.
36 *
37 * \return \c 0 on success.
38 * \return #PSA_ERROR_BUFFER_TOO_SMALL
39 * The output buffer is too small for the unpadded payload.
40 * \return #PSA_ERROR_INVALID_PADDING
41 * The input doesn't contain properly formatted padding.
42 */
43MBEDTLS_STATIC_TESTABLE int mbedtls_ct_rsaes_pkcs1_v15_unpadding(
44 unsigned char *input, size_t ilen,
45 unsigned char *output, size_t output_max_len, size_t *olen);
46#endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C */
47
48/* mbedtls_rsa_private() is not fully constant-time yet, so we can't do
49 * end-to-end constant-time testing by marking external inputs as secret.
50 *
51 * The next best thing we can do is mark its output as a secret, when we expect
52 * further processing to be constant-time, including error handling. */
53extern void (*mbedtls_rsa_cf_secret)(const void *ptr, size_t size);
54
55#endif /* MBEDTLS_TEST_HOOKS */
56
57#endif /* TF_PSA_CRYPTO_RSA_INVASIVE_H */