Ioannis Glaropoulos | 829aa75 | 2021-06-15 12:37:02 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019-2021, Arm Limited. All rights reserved. |
| 3 | * Copyright (c) 2021, Nordic Semiconductor ASA. |
| 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <stddef.h> |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include "tfm_mbedcrypto_include.h" |
| 13 | |
| 14 | #include "tfm_crypto_api.h" |
| 15 | #include "tfm_crypto_defs.h" |
| 16 | #include "tfm_crypto_private.h" |
| 17 | |
| 18 | |
| 19 | /*! |
| 20 | * \defgroup public_psa Public functions, PSA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | /*!@{*/ |
| 25 | psa_status_t tfm_crypto_generate_random(psa_invec in_vec[], |
| 26 | size_t in_len, |
| 27 | psa_outvec out_vec[], |
| 28 | size_t out_len) |
| 29 | { |
| 30 | #ifdef TFM_CRYPTO_RNG_MODULE_DISABLED |
| 31 | return PSA_ERROR_NOT_SUPPORTED; |
| 32 | #else |
| 33 | |
| 34 | CRYPTO_IN_OUT_LEN_VALIDATE(in_len, 1, 1, out_len, 0, 1); |
| 35 | |
| 36 | if (in_vec[0].len != sizeof(struct tfm_crypto_pack_iovec)) { |
| 37 | return PSA_ERROR_PROGRAMMER_ERROR; |
| 38 | } |
| 39 | uint8_t *output = out_vec[0].base; |
| 40 | size_t output_size = out_vec[0].len; |
| 41 | |
| 42 | return psa_generate_random(output, output_size); |
| 43 | #endif /* TFM_CRYPTO_RNG_MODULE_DISABLED */ |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /*!@}*/ |