TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_crypto_private.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __TFM_CRYPTO_PRIVATE_H__
9 #define __TFM_CRYPTO_PRIVATE_H__
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #ifdef TFM_PSA_API
16 /*
17  * Validate the IOVEC[] lengths for IPC model. The tfm_crypto_call_sfn()
18  * reduces the entries in IOVEC[] which are empty from `in_len` and `out_len`.
19  * This means that Crypto service APIs need to ensure that the `in_len`
20  * and `out_len` are within the expected range.
21  *
22  * Also tfm_crypto_call_sfn() ensures that all entries in IOVEC[] are
23  * initialised. Hence all entries in IOVEC[] can be accessed to
24  * initialize internal variables even if they are outside `in_len`
25  * and `out_len`.
26  */
27 #define CRYPTO_IN_OUT_LEN_VALIDATE(in_len, in_min, in_max, out_len, out_min, out_max) \
28  if (!(((in_len) >= (in_min)) && ((in_len) <= (in_max))) || \
29  !(((out_len) >= (out_min)) && ((out_len) <= (out_max)))) { \
30  return PSA_ERROR_PROGRAMMER_ERROR; \
31  }
32 #else
33 /*
34  * Validate the IOVEC[] lengths for Library model. Unlike the IPC model, the
35  * service APIs expects to receive the exact of `in_len` and `out_len`
36  * as expected by the API.
37  */
38 #define CRYPTO_IN_OUT_LEN_VALIDATE(in_len, in_min, in_max, out_len, out_min, out_max) \
39  if (((in_len) != (in_max)) || ((out_len) != (out_max))) { \
40  return PSA_ERROR_PROGRAMMER_ERROR; \
41  }
42 #endif
43 
44 
45 #ifdef __cplusplus
46 }
47 #endif
48 
49 #endif /* __TFM_CRYPTO_PRIVATE_H__ */