xref: /isa-l_crypto/include/isal_crypto_api.h (revision d28f1034f736e3eb791c3cf6bff3e2fa81fb5331)
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 /* Utility macros */
38 #define CONCAT_VERSION_(a, b, c) a##.##b##.##c
39 #define CONCAT_VERSION(a, b, c)  CONCAT_VERSION_(a, b, c)
40 #define TO_STRING_(a)            #a
41 #define TO_STRING(a)             TO_STRING_(a)
42 
43 /* Library version numbers */
44 #define ISAL_CRYPTO_MAJOR_VERSION 2
45 #define ISAL_CRYPTO_MINOR_VERSION 24
46 #define ISAL_CRYPTO_PATCH_VERSION 0
47 
48 #define ISAL_CRYPTO_MAKE_VERSION(maj, min, patch) ((maj) * 0x10000 + (min) * 0x100 + (patch))
49 #define ISAL_CRYPTO_VERSION                                                                        \
50         ISAL_CRYPTO_MAKE_VERSION(ISAL_CRYPTO_MAJOR_VERSION, ISAL_CRYPTO_MINOR_VERSION,             \
51                                  ISAL_CRYPTO_PATCH_VERSION)
52 #define ISAL_CRYPTO_VERSION_STR                                                                    \
53         TO_STRING(CONCAT_VERSION(ISAL_CRYPTO_MAJOR_VERSION, ISAL_CRYPTO_MINOR_VERSION,             \
54                                  ISAL_CRYPTO_PATCH_VERSION))
55 
56 /**
57  * @brief Library error types
58  */
59 typedef enum {
60         ISAL_CRYPTO_ERR_NONE = 0,
61         ISAL_CRYPTO_ERR_NULL_SRC = 2000,
62         ISAL_CRYPTO_ERR_NULL_DST,
63         ISAL_CRYPTO_ERR_NULL_CTX,
64         ISAL_CRYPTO_ERR_NULL_MGR,
65         ISAL_CRYPTO_ERR_NULL_KEY,
66         ISAL_CRYPTO_ERR_NULL_EXP_KEY,
67         ISAL_CRYPTO_ERR_NULL_IV,
68         ISAL_CRYPTO_ERR_NULL_AUTH,
69         ISAL_CRYPTO_ERR_NULL_AAD,
70         ISAL_CRYPTO_ERR_CIPH_LEN,
71         ISAL_CRYPTO_ERR_AUTH_TAG_LEN,
72         ISAL_CRYPTO_ERR_INVALID_FLAGS,
73         ISAL_CRYPTO_ERR_ALREADY_PROCESSING,
74         ISAL_CRYPTO_ERR_ALREADY_COMPLETED,
75         ISAL_CRYPTO_ERR_XTS_NULL_TWEAK,
76         ISAL_CRYPTO_ERR_XTS_SAME_KEYS,
77         ISAL_CRYPTO_ERR_SELF_TEST,
78         ISAL_CRYPTO_ERR_FIPS_INVALID_ALGO,
79         ISAL_CRYPTO_ERR_WINDOW_SIZE,
80         ISAL_CRYPTO_ERR_NULL_OFFSET,
81         ISAL_CRYPTO_ERR_NULL_MATCH,
82         ISAL_CRYPTO_ERR_NULL_MASK,
83         ISAL_CRYPTO_ERR_NULL_INIT_VAL,
84         /* add new error types above this comment */
85         ISAL_CRYPTO_ERR_MAX /* don't move this one */
86 } ISAL_CRYPTO_ERROR;
87 
88 /**
89  * @brief Run all crypto self tests
90  *
91  * When FIPS Mode is enabled, all isal_XXX API which performs any crypto processing
92  * on a NIST-approved algorithm (such as isal_aes_cbc_enc_128) will require this function
93  * to be run.
94  *
95  * This API can be run from the application or it will be run internally in the library,
96  * after calling any of the isal_XXX API.
97  *
98  * Either way, once the self tests have passed, all API calls will be able to start
99  * performing the crypto operation. If the self tests fail, no crypto processing will be done.
100  *
101  * This function is thread safe, so only one thread will run the tests and the rest of the threads
102  * will wait until the tests are finished.
103  *
104  * @return  Self test result
105  * @retval  0 on success, ISAL_CRYPTO_ERR_SELF_TEST on failure
106  */
107 int
108 isal_self_tests(void);
109 
110 /**
111  * @brief Get library version in string format
112  *
113  * @return library version string
114  */
115 const char *
116 isal_crypto_get_version_str(void);
117 
118 /**
119  * @brief Get library version in numerical format
120  *
121  * Use ISAL_CRYPTO_MAKE_VERSION macro to compare this
122  * numerical version against known library version.
123  *
124  * @return library version number
125  */
126 unsigned
127 isal_crypto_get_version(void);
128 
129 #ifdef __cplusplus
130 }
131 #endif //__cplusplus
132 #endif // ifndef _ISAL_CRYPTO_API_H
133