blob: 2fb544239c00ba26cf226aaf4319f041c897e1fe [file] [log] [blame]
Ronald Cron00b7bfc2020-11-25 15:25:26 +01001/*
2 * PSA RSA layer on top of Mbed TLS crypto
3 */
4/*
5 * Copyright The Mbed TLS Contributors
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#ifndef PSA_CRYPTO_RSA_H
22#define PSA_CRYPTO_RSA_H
23
24#include <psa/crypto.h>
25#include <mbedtls/rsa.h>
26
27/** Load the contents of a key buffer into an internal RSA representation
28 *
29 * \param[in] type The type of key contained in \p data.
30 * \param[in] data The buffer from which to load the representation.
31 * \param[in] data_length The size in bytes of \p data.
32 * \param[out] p_rsa Returns a pointer to an RSA context on success.
33 * The caller is responsible for freeing both the
34 * contents of the context and the context itself
35 * when done.
36 */
37psa_status_t mbedtls_psa_rsa_load_representation( psa_key_type_t type,
38 const uint8_t *data,
39 size_t data_length,
40 mbedtls_rsa_context **p_rsa );
Ronald Crone5ca3d82020-11-26 16:36:16 +010041
42/** Export an RSA key to export representation
43 *
44 * \param[in] type The type of key (public/private) to export
45 * \param[in] rsa The internal RSA representation from which to export
46 * \param[out] data The buffer to export to
47 * \param[in] data_size The length of the buffer to export to
48 * \param[out] data_length The amount of bytes written to \p data
49 */
50psa_status_t mbedtls_psa_rsa_export_key( psa_key_type_t type,
51 mbedtls_rsa_context *rsa,
52 uint8_t *data,
53 size_t data_size,
54 size_t *data_length );
55
56/** Export a public RSA key or the public part of an RSA key pair in binary
57 * format.
58 *
59 * \note The signature of this function is that of a PSA driver
60 * export_public_key entry point. This function behaves as an
61 * export_public_key entry point as defined in the PSA driver interface
62 * specification.
63 *
64 * \param[in] attributes The attributes for the key to export.
65 * \param[in] key_buffer Material or context of the key to export.
66 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
67 * \param[out] data Buffer where the key data is to be written.
68 * \param[in] data_size Size of the \p data buffer in bytes.
69 * \param[out] data_length On success, the number of bytes written in
70 * \p data.
71 *
72 * \retval #PSA_SUCCESS The RSA public key was exported successfully.
73 * \retval #PSA_ERROR_NOT_SUPPORTED
74 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
75 * \retval #PSA_ERROR_HARDWARE_FAILURE
76 * \retval #PSA_ERROR_CORRUPTION_DETECTED
77 * \retval #PSA_ERROR_STORAGE_FAILURE
78 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
79 */
80psa_status_t mbedtls_psa_rsa_export_public_key(
81 const psa_key_attributes_t *attributes,
82 const uint8_t *key_buffer, size_t key_buffer_size,
83 uint8_t *data, size_t data_size, size_t *data_length );
84
Ronald Cron00b7bfc2020-11-25 15:25:26 +010085#endif /* PSA_CRYPTO_RSA_H */