xref: /isa-l_crypto/include/isal_crypto_api.h (revision 122c17795e4bee7e9242fceb7a09851e8f4e3a31)
1 /**********************************************************************
2   Copyright(c) 2024 Intel Corporation All rights reserved.
3 
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in
11       the documentation and/or other materials provided with the
12       distribution.
13     * Neither the name of Intel Corporation nor the names of its
14       contributors may be used to endorse or promote products derived
15       from this software without specific prior written permission.
16 
17   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29 
30 #ifndef _ISAL_CRYPTO_API_H
31 #define _ISAL_CRYPTO_API_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef enum {
38         ISAL_CRYPTO_ERR_NONE = 0,
39         ISAL_CRYPTO_ERR_NULL_SRC = 2000,
40         ISAL_CRYPTO_ERR_NULL_DST,
41         ISAL_CRYPTO_ERR_NULL_CTX,
42         ISAL_CRYPTO_ERR_NULL_MGR,
43         ISAL_CRYPTO_ERR_NULL_KEY,
44         ISAL_CRYPTO_ERR_NULL_EXP_KEY,
45         ISAL_CRYPTO_ERR_NULL_IV,
46         ISAL_CRYPTO_ERR_NULL_AUTH,
47         ISAL_CRYPTO_ERR_NULL_AAD,
48         ISAL_CRYPTO_ERR_CIPH_LEN,
49         ISAL_CRYPTO_ERR_AUTH_LEN,
50         ISAL_CRYPTO_ERR_IV_LEN,
51         ISAL_CRYPTO_ERR_KEY_LEN,
52         ISAL_CRYPTO_ERR_AUTH_TAG_LEN,
53         ISAL_CRYPTO_ERR_AAD_LEN,
54         ISAL_CRYPTO_ERR_INVALID_FLAGS,
55         ISAL_CRYPTO_ERR_ALREADY_PROCESSING,
56         ISAL_CRYPTO_ERR_ALREADY_COMPLETED,
57         ISAL_CRYPTO_ERR_XTS_NULL_TWEAK,
58         ISAL_CRYPTO_ERR_XTS_SAME_KEYS,
59         ISAL_CRYPTO_ERR_SELF_TEST,
60         /* add new error types above this comment */
61         ISAL_CRYPTO_ERR_MAX /* don't move this one */
62 } ISAL_CRYPTO_ERROR;
63 
64 /**
65  * @brief Run all crypto self tests
66  *
67  * When FIPS Mode is enabled, all isal_XXX API which performs any crypto processing
68  * on a NIST-approved algorithm (such as isal_aes_cbc_enc_128) will require this function
69  * to be run.
70  *
71  * This API can be run from the application or it will be run internally in the library,
72  * after calling any of the isal_XXX API.
73  *
74  * Either way, once the self tests have passed, all API calls will be able to start
75  * performing the crypto operation. If the self tests fail, no crypto processing will be done.
76  *
77  * This function is thread safe, so only one thread will run the tests and the rest of the threads
78  * will wait until the tests are finished.
79  *
80  * @return  Self test result
81  * @retval  0 on success, ISAL_CRYPTO_ERR_SELF_TEST on failure
82  */
83 int
84 isal_self_tests(void);
85 
86 #ifdef __cplusplus
87 }
88 #endif //__cplusplus
89 #endif // ifndef _ISAL_CRYPTO_API_H
90