0.2.0-dev Download ZIP
155 lines ·6.1 KB Raw
| 1 | /* |
| 2 | * PSA XOF (extendable-output function) layer on top of software crypto |
| 3 | */ |
| 4 | /* |
| 5 | * Copyright The Mbed TLS Contributors |
| 6 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef TF_PSA_CRYPTO_PSA_CRYPTO_XOF_H |
| 10 | #define TF_PSA_CRYPTO_PSA_CRYPTO_XOF_H |
| 11 | |
| 12 | #include <psa/crypto.h> |
| 13 | |
| 14 | /** Set up a multipart XOF operation using built-in code. |
| 15 | * |
| 16 | * If an error occurs at any step after a call to mbedtls_psa_xof_setup(), the |
| 17 | * operation will need to be reset by a call to mbedtls_psa_xof_abort(). The |
| 18 | * core may call mbedtls_psa_xof_abort() at any time after the operation |
| 19 | * has been initialized. |
| 20 | * |
| 21 | * After a successful call to mbedtls_psa_xof_setup(), the core must |
| 22 | * eventually terminate the operation by calling mbedtls_psa_xof_abort(). |
| 23 | * |
| 24 | * \warning The core must call the functions as directed. Otherwise, the |
| 25 | * behavior is undefined, although the driver will try to limit |
| 26 | * the damage to potentially data leakage and memory leaks but |
| 27 | * avoid memory corruption as long as the operation structure has |
| 28 | * been initialited. |
| 29 | * |
| 30 | * \param[in,out] operation The operation object to set up. It must have |
| 31 | * been initialized to all-zero and not yet be in use. |
| 32 | * \param alg The XOF algorithm to compute (\c PSA_ALG_XXX value |
| 33 | * such that #PSA_ALG_IS_XOF(\p alg) is true). |
| 34 | * |
| 35 | * \retval #PSA_SUCCESS |
| 36 | * Success. |
| 37 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 38 | * \p alg is not supported |
| 39 | * \retval #PSA_ERROR_BAD_STATE |
| 40 | * The operation state is not valid (it must be inactive). |
| 41 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 42 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 43 | */ |
| 44 | psa_status_t mbedtls_psa_xof_setup( |
| 45 | mbedtls_psa_xof_operation_t *operation, |
| 46 | psa_algorithm_t alg); |
| 47 | |
| 48 | /** Set the context in a multipart XOF operation. |
| 49 | * |
| 50 | * The core must call mbedtls_psa_xof_setup() before calling this function. |
| 51 | * The core must call this function as directed in the description of |
| 52 | * the XOF algorithm, generally before calling mbedtls_psa_xof_update(). |
| 53 | * The core must not call this function if the XOF algorithm does not use |
| 54 | * a context. |
| 55 | * |
| 56 | * If this function returns an error status, the operation enters an error |
| 57 | * state and must be aborted by calling mbedtls_psa_xof_abort(). |
| 58 | * |
| 59 | * \param[in,out] operation Active XOF operation. |
| 60 | * \param[in] context Buffer containing the message fragment to add. |
| 61 | * \param context_length Size of the \p input buffer in bytes. |
| 62 | * |
| 63 | * \retval #PSA_SUCCESS |
| 64 | * Success. |
| 65 | * \retval #PSA_ERROR_BAD_STATE |
| 66 | * The operation state is not valid (it must be active). |
| 67 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 68 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 69 | */ |
| 70 | psa_status_t mbedtls_psa_xof_set_context( |
| 71 | mbedtls_psa_xof_operation_t *operation, |
| 72 | const uint8_t *context, size_t context_length); |
| 73 | |
| 74 | /** Add an input fragment to a multipart XOF operation. |
| 75 | * |
| 76 | * The core must call mbedtls_psa_xof_setup() before calling this function. |
| 77 | * The core must not call this function after calling |
| 78 | * mbedtls_psa_xof_output() on the operation. |
| 79 | * |
| 80 | * This function can be called multiple times successively, to pass |
| 81 | * input incrementally. |
| 82 | * |
| 83 | * If the XOF algorithm requires a context, the core must call |
| 84 | * mbedtls_psa_xof_set_context() before this function. If the XOF |
| 85 | * algorithm can use an optional context, the core must call |
| 86 | * mbedtls_psa_xof_set_context() before this function, if at all. |
| 87 | * |
| 88 | * If this function returns an error status, the operation enters an error |
| 89 | * state and must be aborted by calling mbedtls_psa_xof_abort(). |
| 90 | * |
| 91 | * \param[in,out] operation Active XOF operation. |
| 92 | * \param[in] input Buffer containing the message fragment to add. |
| 93 | * \param input_length Size of the \p input buffer in bytes. |
| 94 | * |
| 95 | * \retval #PSA_SUCCESS |
| 96 | * Success. |
| 97 | * \retval #PSA_ERROR_BAD_STATE |
| 98 | * The operation state is not valid (it must be active). |
| 99 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 100 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 101 | */ |
| 102 | psa_status_t mbedtls_psa_xof_update( |
| 103 | mbedtls_psa_xof_operation_t *operation, |
| 104 | const uint8_t *input, size_t input_length); |
| 105 | |
| 106 | /** Obtain some output from a XOF operation. |
| 107 | * |
| 108 | * The core must call mbedtls_psa_xof_setup() before calling this function. |
| 109 | * |
| 110 | * This function calculates the incremental XOF output of the message formed |
| 111 | * by concatenating the inputs passed to preceding calls to |
| 112 | * mbedtls_psa_xof_update(). |
| 113 | * |
| 114 | * This function can be called multiple times successively, to obtain |
| 115 | * output incrementally. |
| 116 | * |
| 117 | * \param[in,out] operation Active xof operation. |
| 118 | * \param[out] output Buffer where the XOF output is to be written. |
| 119 | * \param output_size Size of the \p output buffer in bytes. |
| 120 | * |
| 121 | * \retval #PSA_SUCCESS |
| 122 | * Success. |
| 123 | * \retval #PSA_ERROR_BAD_STATE |
| 124 | * The operation state is not valid (it must be active). |
| 125 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription |
| 126 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 127 | */ |
| 128 | psa_status_t mbedtls_psa_xof_output( |
| 129 | mbedtls_psa_xof_operation_t *operation, |
| 130 | uint8_t *output, size_t output_size); |
| 131 | |
| 132 | /** Abort an Mbed TLS xof operation. |
| 133 | * |
| 134 | * \note The signature of this function is that of a PSA driver xof_abort |
| 135 | * entry point. This function behaves as a xof_abort entry point as |
| 136 | * defined in the PSA driver interface specification for transparent |
| 137 | * drivers. |
| 138 | * |
| 139 | * Aborting an operation frees all associated resources except for the |
| 140 | * \p operation structure itself. Once aborted, the operation object |
| 141 | * can be reused for another operation by calling |
| 142 | * mbedtls_psa_xof_setup() again. |
| 143 | * |
| 144 | * You may call this function any time after the operation object has |
| 145 | * been initialized by one of the methods described in #psa_xof_operation_t. |
| 146 | * |
| 147 | * \param[in,out] operation Initialized XOF operation. |
| 148 | * |
| 149 | * \retval #PSA_SUCCESS \emptydescription |
| 150 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 151 | */ |
| 152 | psa_status_t mbedtls_psa_xof_abort( |
| 153 | mbedtls_psa_xof_operation_t *operation); |
| 154 | |
| 155 | #endif /* TF_PSA_CRYPTO_PSA_CRYPTO_XOF_H */ |