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 #include <stdio.h> 31 #include <string.h> 32 33 #include "isal_crypto_api.h" 34 #include "aes_keyexp.h" 35 #include "aes_cbc.h" 36 #include "aes_xts.h" 37 #include "aes_gcm.h" 38 #include "test.h" 39 #include "aes/gcm_vectors.h" 40 41 #ifdef SAFE_PARAM 42 #define CHECK_RETURN(state, expected, func) \ 43 do { \ 44 if ((state) != (expected)) { \ 45 printf("test: %s() - expected return " \ 46 "value %d, got %d\n", \ 47 func, expected, state); \ 48 return 1; \ 49 } \ 50 } while (0) 51 52 typedef int (*aes_keyexp_func)(const uint8_t *, uint8_t *, uint8_t *); 53 typedef int (*aes_cbc_func)(const void *, const void *, const void *, void *, const uint64_t); 54 typedef int (*aes_xts_func)(const uint8_t *, const uint8_t *, const uint8_t *, const uint64_t, 55 const void *, void *); 56 typedef int (*aes_gcm_func)(const struct gcm_key_data *, struct gcm_context_data *, uint8_t *, 57 const uint8_t *, const uint64_t, const uint8_t *, const uint8_t *, 58 const uint64_t, uint8_t *, const uint64_t); 59 typedef int (*aes_gcm_init_func)(const struct gcm_key_data *, struct gcm_context_data *, 60 const uint8_t *, const uint8_t *, const uint64_t); 61 typedef int (*aes_gcm_update_func)(const struct gcm_key_data *, struct gcm_context_data *, 62 uint8_t *, const uint8_t *, const uint64_t); 63 typedef int (*aes_gcm_finalize_func)(const struct gcm_key_data *, struct gcm_context_data *, 64 uint8_t *, const uint64_t); 65 typedef int (*aes_gcm_pre_func)(const void *, struct gcm_key_data *); 66 67 struct test_func { 68 union { 69 aes_keyexp_func keyexp_func_ptr; 70 aes_cbc_func cbc_func_ptr; 71 aes_xts_func xts_func_ptr; 72 aes_gcm_func gcm_func_ptr; 73 aes_gcm_init_func gcm_init_func_ptr; 74 aes_gcm_update_func gcm_update_func_ptr; 75 aes_gcm_finalize_func gcm_finalize_func_ptr; 76 aes_gcm_pre_func gcm_pre_func_ptr; 77 }; 78 char *func_name; 79 }; 80 81 static int 82 test_aes_keyexp_api(aes_keyexp_func aes_keyexp_func_ptr, const char *name) 83 { 84 uint8_t key[ISAL_CBC_ROUND_KEY_LEN] = { 0 }; 85 uint8_t enc_keys[ISAL_CBC_MAX_KEYS_SIZE] = { 0 }; 86 uint8_t dec_keys[ISAL_CBC_MAX_KEYS_SIZE] = { 0 }; 87 88 // test null key 89 CHECK_RETURN(aes_keyexp_func_ptr(NULL, enc_keys, dec_keys), ISAL_CRYPTO_ERR_NULL_KEY, name); 90 91 // test null exp key ptr 92 CHECK_RETURN(aes_keyexp_func_ptr(key, NULL, dec_keys), ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 93 94 // test null exp key ptr 95 CHECK_RETURN(aes_keyexp_func_ptr(key, enc_keys, NULL), ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 96 97 // test valid params 98 CHECK_RETURN(aes_keyexp_func_ptr(key, enc_keys, dec_keys), ISAL_CRYPTO_ERR_NONE, name); 99 100 return 0; 101 } 102 103 static int 104 test_aes_cbc_api(aes_cbc_func aes_cbc_func_ptr, const char *name) 105 { 106 uint8_t exp_keys[ISAL_CBC_MAX_KEYS_SIZE] = { 0 }; 107 uint8_t buf[16] = { 0 }; 108 uint8_t iv[16] = { 0 }; 109 110 // test null input ptr 111 CHECK_RETURN(aes_cbc_func_ptr(NULL, iv, exp_keys, buf, 16), ISAL_CRYPTO_ERR_NULL_SRC, name); 112 113 // test null IV ptr 114 CHECK_RETURN(aes_cbc_func_ptr(buf, NULL, exp_keys, buf, 16), ISAL_CRYPTO_ERR_NULL_IV, name); 115 116 // test null exp key ptr 117 CHECK_RETURN(aes_cbc_func_ptr(buf, iv, NULL, buf, 16), ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 118 119 // test null output ptr 120 CHECK_RETURN(aes_cbc_func_ptr(buf, iv, exp_keys, NULL, 16), ISAL_CRYPTO_ERR_NULL_DST, name); 121 122 // test invalid length (not multiple of 16 bytes) 123 CHECK_RETURN(aes_cbc_func_ptr(buf, iv, exp_keys, buf, 15), ISAL_CRYPTO_ERR_CIPH_LEN, name); 124 125 // test valid params 126 CHECK_RETURN(aes_cbc_func_ptr(buf, iv, exp_keys, buf, 16), ISAL_CRYPTO_ERR_NONE, name); 127 128 return 0; 129 } 130 131 static int 132 test_aes_xts_api(aes_xts_func aes_xts_func_ptr, const char *name, const int expanded_key) 133 { 134 uint8_t key1[32] = { 0 }; 135 uint8_t exp_keys1[ISAL_CBC_MAX_KEYS_SIZE] = { 0 }; 136 uint8_t key2[32]; 137 uint8_t exp_keys2[ISAL_CBC_MAX_KEYS_SIZE]; 138 uint8_t buf[16] = { 0 }; 139 uint8_t tweak[16] = { 0 }; 140 141 uint8_t *key1_ptr = (expanded_key) ? exp_keys1 : key1; 142 uint8_t *key2_ptr = (expanded_key) ? exp_keys2 : key2; 143 144 /* Key1 and key2 must be different, to avoid error */ 145 memset(key2, 0xff, sizeof(key2)); 146 memset(exp_keys2, 0xff, sizeof(exp_keys2)); 147 148 if (expanded_key) { 149 // test null expanded key ptr 150 CHECK_RETURN(aes_xts_func_ptr(NULL, exp_keys1, tweak, 16, buf, buf), 151 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 152 CHECK_RETURN(aes_xts_func_ptr(exp_keys1, NULL, tweak, 16, buf, buf), 153 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 154 } else { 155 CHECK_RETURN(aes_xts_func_ptr(NULL, key2, tweak, 16, buf, buf), 156 ISAL_CRYPTO_ERR_NULL_KEY, name); 157 CHECK_RETURN(aes_xts_func_ptr(key1, NULL, tweak, 16, buf, buf), 158 ISAL_CRYPTO_ERR_NULL_KEY, name); 159 } 160 161 // test null tweak ptr 162 CHECK_RETURN(aes_xts_func_ptr(key1_ptr, key2_ptr, NULL, 16, buf, buf), 163 ISAL_CRYPTO_ERR_XTS_NULL_TWEAK, name); 164 165 // test invalid length (outside range) 166 CHECK_RETURN( 167 aes_xts_func_ptr(key1_ptr, key2_ptr, tweak, ISAL_AES_XTS_MIN_LEN - 1, buf, buf), 168 ISAL_CRYPTO_ERR_CIPH_LEN, name); 169 170 CHECK_RETURN( 171 aes_xts_func_ptr(key1_ptr, key2_ptr, tweak, ISAL_AES_XTS_MAX_LEN + 1, buf, buf), 172 ISAL_CRYPTO_ERR_CIPH_LEN, name); 173 174 // test null input ptr 175 CHECK_RETURN(aes_xts_func_ptr(key1_ptr, key2_ptr, tweak, 16, NULL, buf), 176 ISAL_CRYPTO_ERR_NULL_SRC, name); 177 178 // test null output ptr 179 CHECK_RETURN(aes_xts_func_ptr(key1_ptr, key2_ptr, tweak, 16, buf, NULL), 180 ISAL_CRYPTO_ERR_NULL_DST, name); 181 182 #ifdef FIPS_MODE 183 // test same key error 184 CHECK_RETURN(aes_xts_func_ptr(key1_ptr, key1_ptr, tweak, 16, buf, buf), 185 ISAL_CRYPTO_ERR_XTS_SAME_KEYS, name); 186 #endif 187 // test valid params 188 CHECK_RETURN(aes_xts_func_ptr(key1_ptr, key2_ptr, tweak, 16, buf, buf), 189 ISAL_CRYPTO_ERR_NONE, name); 190 191 return 0; 192 } 193 194 static int 195 test_aes_gcm_api(aes_gcm_func aes_gcm_func_ptr, const char *name) 196 { 197 struct gcm_key_data gkey; 198 struct gcm_context_data gctx; 199 uint8_t buf[256] = { 0 }; 200 uint8_t iv[ISAL_GCM_IV_LEN] = { 0 }; 201 uint8_t *aad = buf; 202 uint8_t *tag = buf; 203 204 // test null key data 205 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, buf, buf, sizeof(buf), iv, aad, 16, tag, 206 ISAL_GCM_MAX_TAG_LEN), 207 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 208 209 // test null context 210 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, buf, buf, sizeof(buf), iv, aad, 16, tag, 211 ISAL_GCM_MAX_TAG_LEN), 212 ISAL_CRYPTO_ERR_NULL_CTX, name); 213 214 // test null dst 215 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, buf, sizeof(buf), iv, aad, 16, tag, 216 ISAL_GCM_MAX_TAG_LEN), 217 ISAL_CRYPTO_ERR_NULL_DST, name); 218 219 // test null dst with zero len 220 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, buf, 0, iv, aad, 16, tag, 221 ISAL_GCM_MAX_TAG_LEN), 222 ISAL_CRYPTO_ERR_NONE, name); 223 224 // test null src 225 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, sizeof(buf), iv, aad, 16, tag, 226 ISAL_GCM_MAX_TAG_LEN), 227 ISAL_CRYPTO_ERR_NULL_SRC, name); 228 229 // test null src with zero len 230 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, 0, iv, aad, 16, tag, 231 ISAL_GCM_MAX_TAG_LEN), 232 ISAL_CRYPTO_ERR_NONE, name); 233 234 // test invalid len 235 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, ISAL_GCM_MAX_LEN + 1, iv, aad, 16, 236 tag, ISAL_GCM_MAX_TAG_LEN), 237 ISAL_CRYPTO_ERR_CIPH_LEN, name); 238 239 // test zero len 240 CHECK_RETURN( 241 aes_gcm_func_ptr(&gkey, &gctx, buf, buf, 0, iv, aad, 16, tag, ISAL_GCM_MAX_TAG_LEN), 242 ISAL_CRYPTO_ERR_NONE, name); 243 244 // test null iv 245 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), NULL, aad, 16, tag, 246 ISAL_GCM_MAX_TAG_LEN), 247 ISAL_CRYPTO_ERR_NULL_IV, name); 248 249 // test null aad 250 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, NULL, 16, tag, 251 ISAL_GCM_MAX_TAG_LEN), 252 ISAL_CRYPTO_ERR_NULL_AAD, name); 253 254 // test null aad with zero len 255 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, NULL, 0, tag, 256 ISAL_GCM_MAX_TAG_LEN), 257 ISAL_CRYPTO_ERR_NONE, name); 258 259 // test null tag 260 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, aad, 16, NULL, 261 ISAL_GCM_MAX_TAG_LEN), 262 ISAL_CRYPTO_ERR_NULL_AUTH, name); 263 264 // test auth tag lens 265 for (int i = 5; i <= ISAL_GCM_MAX_TAG_LEN + 1; i++) 266 if (i % 4 == 0) 267 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, aad, 268 16, tag, i), 269 ISAL_CRYPTO_ERR_NONE, name); 270 else 271 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, aad, 272 16, tag, i), 273 ISAL_CRYPTO_ERR_AUTH_TAG_LEN, name); 274 return 0; 275 } 276 277 static int 278 test_aes_gcm_init_api(aes_gcm_init_func aes_gcm_func_ptr, const char *name) 279 { 280 struct gcm_key_data gkey; 281 struct gcm_context_data gctx; 282 uint8_t iv[ISAL_GCM_IV_LEN] = { 0 }; 283 uint8_t aad[64] = { 0 }; 284 285 // test null key data 286 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, iv, aad, sizeof(aad)), 287 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 288 289 // test null context 290 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, iv, aad, sizeof(aad)), ISAL_CRYPTO_ERR_NULL_CTX, 291 name); 292 293 // test null iv 294 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, aad, sizeof(aad)), 295 ISAL_CRYPTO_ERR_NULL_IV, name); 296 297 // test null aad 298 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, iv, NULL, sizeof(aad)), 299 ISAL_CRYPTO_ERR_NULL_AAD, name); 300 301 // test null aad with zero len 302 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, iv, aad, 0), ISAL_CRYPTO_ERR_NONE, name); 303 304 return 0; 305 } 306 307 static int 308 test_aes_gcm_update_api(aes_gcm_update_func aes_gcm_func_ptr, const char *name) 309 { 310 struct gcm_key_data gkey; 311 struct gcm_context_data gctx; 312 uint8_t buf[256] = { 0 }; 313 314 // test null key data 315 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, buf, buf, sizeof(buf)), 316 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 317 318 // test null context 319 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, buf, buf, sizeof(buf)), ISAL_CRYPTO_ERR_NULL_CTX, 320 name); 321 322 // test null dst 323 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, buf, sizeof(buf)), 324 ISAL_CRYPTO_ERR_NULL_DST, name); 325 326 // test null dst with zero len 327 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, buf, 0), ISAL_CRYPTO_ERR_NONE, name); 328 329 // test null src 330 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, sizeof(buf)), 331 ISAL_CRYPTO_ERR_NULL_SRC, name); 332 333 // test null src with zero len 334 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, 0), ISAL_CRYPTO_ERR_NONE, name); 335 336 // test invalid len 337 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, ISAL_GCM_MAX_LEN + 1), 338 ISAL_CRYPTO_ERR_CIPH_LEN, name); 339 340 return 0; 341 } 342 343 static int 344 test_aes_gcm_finalize_api(aes_gcm_finalize_func aes_gcm_func_ptr, const char *name, 345 const gcm_key_size key_size) 346 { 347 struct gcm_key_data gkey = { 0 }; 348 struct gcm_context_data gctx = { 0 }; 349 uint8_t tag[ISAL_GCM_MAX_TAG_LEN] = { 0 }; 350 uint8_t iv[ISAL_GCM_IV_LEN] = { 0 }; 351 uint8_t aad[64] = { 0 }; 352 353 // init required for valid cases 354 if (key_size == BITS_128) 355 isal_aes_gcm_init_128(&gkey, &gctx, iv, aad, sizeof(aad)); 356 else 357 isal_aes_gcm_init_256(&gkey, &gctx, iv, aad, sizeof(aad)); 358 359 // test null key data 360 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, tag, ISAL_GCM_MAX_TAG_LEN), 361 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 362 363 // test null context 364 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, tag, ISAL_GCM_MAX_TAG_LEN), 365 ISAL_CRYPTO_ERR_NULL_CTX, name); 366 367 // test null tag 368 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, ISAL_GCM_MAX_TAG_LEN), 369 ISAL_CRYPTO_ERR_NULL_AUTH, name); 370 371 // test auth tag lens 372 for (int i = 5; i <= ISAL_GCM_MAX_TAG_LEN + 1; i++) 373 if (i % 4 == 0) 374 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, tag, i), ISAL_CRYPTO_ERR_NONE, 375 name); 376 else 377 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, tag, i), 378 ISAL_CRYPTO_ERR_AUTH_TAG_LEN, name); 379 return 0; 380 } 381 382 static int 383 test_aes_gcm_pre_api(aes_gcm_pre_func aes_gcm_func_ptr, const char *name) 384 { 385 struct gcm_key_data gkey; 386 int key[8] = { 0 }; 387 388 // test null key 389 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gkey), ISAL_CRYPTO_ERR_NULL_KEY, name); 390 391 // test null key data 392 CHECK_RETURN(aes_gcm_func_ptr(key, NULL), ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 393 394 // test valid params 395 CHECK_RETURN(aes_gcm_func_ptr(key, &gkey), ISAL_CRYPTO_ERR_NONE, name); 396 397 return 0; 398 } 399 400 #endif /* SAFE_PARAM */ 401 402 int 403 main(void) 404 { 405 int fail = 0; 406 #ifdef SAFE_PARAM 407 /* Test AES key expansion API */ 408 const struct test_func keyexp_test_funcs[] = { 409 { .keyexp_func_ptr = isal_aes_keyexp_128, "isal_aes_keyexp_128" }, 410 { .keyexp_func_ptr = isal_aes_keyexp_192, "isal_aes_keyexp_192" }, 411 { .keyexp_func_ptr = isal_aes_keyexp_256, "isal_aes_keyexp_256" }, 412 }; 413 414 for (int i = 0; i < DIM(keyexp_test_funcs); i++) { 415 fail |= test_aes_keyexp_api(keyexp_test_funcs[i].keyexp_func_ptr, 416 keyexp_test_funcs[i].func_name); 417 } 418 419 /* Test AES-CBC API */ 420 const struct test_func cbc_test_funcs[] = { 421 { .cbc_func_ptr = isal_aes_cbc_enc_128, "isal_aes_cbc_enc_128" }, 422 { .cbc_func_ptr = isal_aes_cbc_enc_192, "isal_aes_cbc_enc_192" }, 423 { .cbc_func_ptr = isal_aes_cbc_enc_256, "isal_aes_cbc_enc_256" }, 424 { .cbc_func_ptr = isal_aes_cbc_dec_128, "isal_aes_cbc_dec_128" }, 425 { .cbc_func_ptr = isal_aes_cbc_dec_192, "isal_aes_cbc_dec_192" }, 426 { .cbc_func_ptr = isal_aes_cbc_dec_256, "isal_aes_cbc_dec_256" }, 427 }; 428 429 for (int i = 0; i < DIM(cbc_test_funcs); i++) { 430 fail |= test_aes_cbc_api(cbc_test_funcs[i].cbc_func_ptr, 431 cbc_test_funcs[i].func_name); 432 } 433 434 /* Test AES-XTS API */ 435 const struct test_func xts_test_funcs[] = { 436 { .xts_func_ptr = isal_aes_xts_enc_128, "isal_aes_xts_enc_128" }, 437 { .xts_func_ptr = isal_aes_xts_enc_256, "isal_aes_xts_enc_256" }, 438 { .xts_func_ptr = isal_aes_xts_dec_128, "isal_aes_xts_dec_128" }, 439 { .xts_func_ptr = isal_aes_xts_dec_256, "isal_aes_xts_dec_256" }, 440 }; 441 442 for (int i = 0; i < DIM(xts_test_funcs); i++) { 443 fail |= test_aes_xts_api(xts_test_funcs[i].xts_func_ptr, 444 xts_test_funcs[i].func_name, 0); 445 } 446 /* Test AES-XTS expanded key API */ 447 const struct test_func xts_exp_test_funcs[] = { 448 { .xts_func_ptr = isal_aes_xts_enc_128_expanded_key, 449 "isal_aes_xts_enc_128_expanded_key" }, 450 { .xts_func_ptr = isal_aes_xts_enc_256_expanded_key, 451 "isal_aes_xts_enc_256_expanded_key" }, 452 { .xts_func_ptr = isal_aes_xts_dec_128_expanded_key, 453 "isal_aes_xts_dec_128_expanded_key" }, 454 { .xts_func_ptr = isal_aes_xts_dec_256_expanded_key, 455 "isal_aes_xts_dec_256_expanded_key" }, 456 }; 457 458 for (int i = 0; i < DIM(xts_exp_test_funcs); i++) { 459 fail |= test_aes_xts_api(xts_exp_test_funcs[i].xts_func_ptr, 460 xts_exp_test_funcs[i].func_name, 1); 461 } 462 463 /* Test AES-GCM enc / dec API */ 464 const struct test_func gcm_test_funcs[] = { 465 { .gcm_func_ptr = isal_aes_gcm_enc_128, "isal_aes_gcm_enc_128" }, 466 { .gcm_func_ptr = isal_aes_gcm_enc_256, "isal_aes_gcm_enc_256" }, 467 { .gcm_func_ptr = isal_aes_gcm_dec_128, "isal_aes_gcm_dec_128" }, 468 { .gcm_func_ptr = isal_aes_gcm_dec_256, "isal_aes_gcm_dec_256" }, 469 { .gcm_func_ptr = isal_aes_gcm_enc_128_nt, "isal_aes_gcm_enc_128_nt" }, 470 { .gcm_func_ptr = isal_aes_gcm_enc_256_nt, "isal_aes_gcm_enc_256_nt" }, 471 { .gcm_func_ptr = isal_aes_gcm_dec_128_nt, "isal_aes_gcm_dec_128_nt" }, 472 { .gcm_func_ptr = isal_aes_gcm_dec_256_nt, "isal_aes_gcm_dec_256_nt" }, 473 }; 474 475 for (int i = 0; i < DIM(gcm_test_funcs); i++) { 476 fail |= test_aes_gcm_api(gcm_test_funcs[i].gcm_func_ptr, 477 gcm_test_funcs[i].func_name); 478 } 479 480 /* Test AES-GCM init API */ 481 const struct test_func gcm_init_test_funcs[] = { 482 { .gcm_init_func_ptr = isal_aes_gcm_init_128, "isal_aes_gcm_init_128" }, 483 { .gcm_init_func_ptr = isal_aes_gcm_init_256, "isal_aes_gcm_init_256" }, 484 }; 485 486 for (int i = 0; i < DIM(gcm_init_test_funcs); i++) { 487 fail |= test_aes_gcm_init_api(gcm_init_test_funcs[i].gcm_init_func_ptr, 488 gcm_init_test_funcs[i].func_name); 489 } 490 491 /* Test AES-GCM update API */ 492 const struct test_func gcm_update_test_funcs[] = { 493 { .gcm_update_func_ptr = isal_aes_gcm_enc_128_update, 494 "isal_aes_gcm_enc_128_update" }, 495 { .gcm_update_func_ptr = isal_aes_gcm_enc_256_update, 496 "isal_aes_gcm_enc_256_update" }, 497 { .gcm_update_func_ptr = isal_aes_gcm_dec_128_update, 498 "isal_aes_gcm_dec_128_update" }, 499 { .gcm_update_func_ptr = isal_aes_gcm_dec_256_update, 500 "isal_aes_gcm_dec_256_update" }, 501 { .gcm_update_func_ptr = isal_aes_gcm_enc_128_update_nt, 502 "isal_aes_gcm_enc_128_update_nt" }, 503 { .gcm_update_func_ptr = isal_aes_gcm_enc_256_update_nt, 504 "isal_aes_gcm_enc_256_update_nt" }, 505 { .gcm_update_func_ptr = isal_aes_gcm_dec_128_update_nt, 506 "isal_aes_gcm_dec_128_update_nt" }, 507 { .gcm_update_func_ptr = isal_aes_gcm_dec_256_update_nt, 508 "isal_aes_gcm_dec_256_update_nt" }, 509 }; 510 511 for (int i = 0; i < DIM(gcm_update_test_funcs); i++) { 512 fail |= test_aes_gcm_update_api(gcm_update_test_funcs[i].gcm_update_func_ptr, 513 gcm_update_test_funcs[i].func_name); 514 } 515 516 /* Test AES-GCM finalize API */ 517 const struct test_func gcm_finalize_128_test_funcs[] = { 518 { .gcm_finalize_func_ptr = isal_aes_gcm_enc_128_finalize, 519 "isal_aes_gcm_enc_128_finalize" }, 520 { .gcm_finalize_func_ptr = isal_aes_gcm_dec_128_finalize, 521 "isal_aes_gcm_dec_128_finalize" }, 522 }; 523 524 for (int i = 0; i < DIM(gcm_finalize_128_test_funcs); i++) { 525 fail |= test_aes_gcm_finalize_api( 526 gcm_finalize_128_test_funcs[i].gcm_finalize_func_ptr, 527 gcm_finalize_128_test_funcs[i].func_name, BITS_128); 528 } 529 530 const struct test_func gcm_finalize_256_test_funcs[] = { 531 { .gcm_finalize_func_ptr = isal_aes_gcm_enc_256_finalize, 532 "isal_aes_gcm_enc_256_finalize" }, 533 { .gcm_finalize_func_ptr = isal_aes_gcm_dec_256_finalize, 534 "isal_aes_gcm_dec_256_finalize" }, 535 }; 536 537 for (int i = 0; i < DIM(gcm_finalize_256_test_funcs); i++) { 538 fail |= test_aes_gcm_finalize_api( 539 gcm_finalize_256_test_funcs[i].gcm_finalize_func_ptr, 540 gcm_finalize_256_test_funcs[i].func_name, BITS_256); 541 } 542 543 /* Test AES-GCM pre API */ 544 const struct test_func gcm_pre_test_funcs[] = { 545 { .gcm_pre_func_ptr = isal_aes_gcm_pre_128, "isal_aes_gcm_pre_128" }, 546 { .gcm_pre_func_ptr = isal_aes_gcm_pre_256, "isal_aes_gcm_pre_256" }, 547 }; 548 549 for (int i = 0; i < DIM(gcm_pre_test_funcs); i++) { 550 fail |= test_aes_gcm_pre_api(gcm_pre_test_funcs[i].gcm_pre_func_ptr, 551 gcm_pre_test_funcs[i].func_name); 552 } 553 554 printf(fail ? "Fail\n" : "Pass\n"); 555 #else 556 printf("Not Executed\n"); 557 #endif 558 return fail; 559 } 560