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 int *, 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[CBC_ROUND_KEY_LEN] = { 0 }; 85 uint8_t enc_keys[CBC_MAX_KEYS_SIZE] = { 0 }; 86 uint8_t dec_keys[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[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[CBC_MAX_KEYS_SIZE] = { 0 }; 136 uint8_t key2[32]; 137 uint8_t exp_keys2[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[GCM_IV_LEN] = { 0 }; 201 uint8_t *aad = buf; 202 uint8_t *tag = buf; 203 204 // test null key data 205 CHECK_RETURN( 206 aes_gcm_func_ptr(NULL, &gctx, buf, buf, sizeof(buf), iv, aad, 16, tag, MAX_TAG_LEN), 207 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 208 209 // test null context 210 CHECK_RETURN( 211 aes_gcm_func_ptr(&gkey, NULL, buf, buf, sizeof(buf), iv, aad, 16, tag, 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 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, MAX_TAG_LEN), 221 ISAL_CRYPTO_ERR_NONE, name); 222 223 // test null src 224 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, sizeof(buf), iv, aad, 16, tag, 225 MAX_TAG_LEN), 226 ISAL_CRYPTO_ERR_NULL_SRC, name); 227 228 // test null src with zero len 229 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, 0, iv, aad, 16, tag, MAX_TAG_LEN), 230 ISAL_CRYPTO_ERR_NONE, name); 231 232 // test invalid len 233 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, GCM_MAX_LEN + 1, iv, aad, 16, tag, 234 MAX_TAG_LEN), 235 ISAL_CRYPTO_ERR_CIPH_LEN, name); 236 237 // test zero len 238 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, 0, iv, aad, 16, tag, MAX_TAG_LEN), 239 ISAL_CRYPTO_ERR_NONE, name); 240 241 // test null iv 242 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), NULL, aad, 16, tag, 243 MAX_TAG_LEN), 244 ISAL_CRYPTO_ERR_NULL_IV, name); 245 246 // test null aad 247 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, NULL, 16, tag, 248 MAX_TAG_LEN), 249 ISAL_CRYPTO_ERR_NULL_AAD, name); 250 251 // test null aad with zero len 252 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, NULL, 0, tag, 253 MAX_TAG_LEN), 254 ISAL_CRYPTO_ERR_NONE, name); 255 256 // test null tag 257 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, aad, 16, NULL, 258 MAX_TAG_LEN), 259 ISAL_CRYPTO_ERR_NULL_AUTH, name); 260 261 // test auth tag lens 262 for (int i = 5; i <= MAX_TAG_LEN + 1; i++) 263 if (i % 4 == 0) 264 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, aad, 265 16, tag, i), 266 ISAL_CRYPTO_ERR_NONE, name); 267 else 268 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, sizeof(buf), iv, aad, 269 16, tag, i), 270 ISAL_CRYPTO_ERR_AUTH_TAG_LEN, name); 271 return 0; 272 } 273 274 static int 275 test_aes_gcm_init_api(aes_gcm_init_func aes_gcm_func_ptr, const char *name) 276 { 277 struct gcm_key_data gkey; 278 struct gcm_context_data gctx; 279 uint8_t iv[GCM_IV_LEN] = { 0 }; 280 uint8_t aad[64] = { 0 }; 281 282 // test null key data 283 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, iv, aad, sizeof(aad)), 284 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 285 286 // test null context 287 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, iv, aad, sizeof(aad)), ISAL_CRYPTO_ERR_NULL_CTX, 288 name); 289 290 // test null iv 291 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, aad, sizeof(aad)), 292 ISAL_CRYPTO_ERR_NULL_IV, name); 293 294 // test null aad 295 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, iv, NULL, sizeof(aad)), 296 ISAL_CRYPTO_ERR_NULL_AAD, name); 297 298 // test null aad with zero len 299 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, iv, aad, 0), ISAL_CRYPTO_ERR_NONE, name); 300 301 return 0; 302 } 303 304 static int 305 test_aes_gcm_update_api(aes_gcm_update_func aes_gcm_func_ptr, const char *name) 306 { 307 struct gcm_key_data gkey; 308 struct gcm_context_data gctx; 309 uint8_t buf[256] = { 0 }; 310 311 // test null key data 312 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, buf, buf, sizeof(buf)), 313 ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 314 315 // test null context 316 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, buf, buf, sizeof(buf)), ISAL_CRYPTO_ERR_NULL_CTX, 317 name); 318 319 // test null dst 320 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, buf, sizeof(buf)), 321 ISAL_CRYPTO_ERR_NULL_DST, name); 322 323 // test null dst with zero len 324 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, buf, 0), ISAL_CRYPTO_ERR_NONE, name); 325 326 // test null src 327 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, sizeof(buf)), 328 ISAL_CRYPTO_ERR_NULL_SRC, name); 329 330 // test null src with zero len 331 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, NULL, 0), ISAL_CRYPTO_ERR_NONE, name); 332 333 // test invalid len 334 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, buf, buf, GCM_MAX_LEN + 1), 335 ISAL_CRYPTO_ERR_CIPH_LEN, name); 336 337 return 0; 338 } 339 340 static int 341 test_aes_gcm_finalize_api(aes_gcm_finalize_func aes_gcm_func_ptr, const char *name, 342 const gcm_key_size key_size) 343 { 344 struct gcm_key_data gkey = { 0 }; 345 struct gcm_context_data gctx = { 0 }; 346 uint8_t tag[MAX_TAG_LEN] = { 0 }; 347 uint8_t iv[GCM_IV_LEN] = { 0 }; 348 uint8_t aad[64] = { 0 }; 349 350 // init required for valid cases 351 if (key_size == BITS_128) 352 isal_aes_gcm_init_128(&gkey, &gctx, iv, aad, sizeof(aad)); 353 else 354 isal_aes_gcm_init_256(&gkey, &gctx, iv, aad, sizeof(aad)); 355 356 // test null key data 357 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gctx, tag, MAX_TAG_LEN), ISAL_CRYPTO_ERR_NULL_EXP_KEY, 358 name); 359 360 // test null context 361 CHECK_RETURN(aes_gcm_func_ptr(&gkey, NULL, tag, MAX_TAG_LEN), ISAL_CRYPTO_ERR_NULL_CTX, 362 name); 363 364 // test null tag 365 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, NULL, MAX_TAG_LEN), ISAL_CRYPTO_ERR_NULL_AUTH, 366 name); 367 368 // test auth tag lens 369 for (int i = 5; i <= MAX_TAG_LEN + 1; i++) 370 if (i % 4 == 0) 371 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, tag, i), ISAL_CRYPTO_ERR_NONE, 372 name); 373 else 374 CHECK_RETURN(aes_gcm_func_ptr(&gkey, &gctx, tag, i), 375 ISAL_CRYPTO_ERR_AUTH_TAG_LEN, name); 376 return 0; 377 } 378 379 static int 380 test_aes_gcm_pre_api(aes_gcm_pre_func aes_gcm_func_ptr, const char *name) 381 { 382 struct gcm_key_data gkey; 383 int key[8] = { 0 }; 384 385 // test null key 386 CHECK_RETURN(aes_gcm_func_ptr(NULL, &gkey), ISAL_CRYPTO_ERR_NULL_KEY, name); 387 388 // test null key data 389 CHECK_RETURN(aes_gcm_func_ptr(key, NULL), ISAL_CRYPTO_ERR_NULL_EXP_KEY, name); 390 391 // test valid params 392 CHECK_RETURN(aes_gcm_func_ptr(key, &gkey), ISAL_CRYPTO_ERR_NONE, name); 393 394 return 0; 395 } 396 397 #endif /* SAFE_PARAM */ 398 399 int 400 main(void) 401 { 402 int fail = 0; 403 #ifdef SAFE_PARAM 404 /* Test AES key expansion API */ 405 const struct test_func keyexp_test_funcs[] = { 406 { .keyexp_func_ptr = isal_aes_keyexp_128, "isal_aes_keyexp_128" }, 407 { .keyexp_func_ptr = isal_aes_keyexp_192, "isal_aes_keyexp_192" }, 408 { .keyexp_func_ptr = isal_aes_keyexp_256, "isal_aes_keyexp_256" }, 409 }; 410 411 for (int i = 0; i < DIM(keyexp_test_funcs); i++) { 412 fail |= test_aes_keyexp_api(keyexp_test_funcs[i].keyexp_func_ptr, 413 keyexp_test_funcs[i].func_name); 414 } 415 416 /* Test AES-CBC API */ 417 const struct test_func cbc_test_funcs[] = { 418 { .cbc_func_ptr = isal_aes_cbc_enc_128, "isal_aes_cbc_enc_128" }, 419 { .cbc_func_ptr = isal_aes_cbc_enc_192, "isal_aes_cbc_enc_192" }, 420 { .cbc_func_ptr = isal_aes_cbc_enc_256, "isal_aes_cbc_enc_256" }, 421 { .cbc_func_ptr = isal_aes_cbc_dec_128, "isal_aes_cbc_dec_128" }, 422 { .cbc_func_ptr = isal_aes_cbc_dec_192, "isal_aes_cbc_dec_192" }, 423 { .cbc_func_ptr = isal_aes_cbc_dec_256, "isal_aes_cbc_dec_256" }, 424 }; 425 426 for (int i = 0; i < DIM(cbc_test_funcs); i++) { 427 fail |= test_aes_cbc_api(cbc_test_funcs[i].cbc_func_ptr, 428 cbc_test_funcs[i].func_name); 429 } 430 431 /* Test AES-XTS API */ 432 const struct test_func xts_test_funcs[] = { 433 { .xts_func_ptr = isal_aes_xts_enc_128, "isal_aes_xts_enc_128" }, 434 { .xts_func_ptr = isal_aes_xts_enc_256, "isal_aes_xts_enc_256" }, 435 { .xts_func_ptr = isal_aes_xts_dec_128, "isal_aes_xts_dec_128" }, 436 { .xts_func_ptr = isal_aes_xts_dec_256, "isal_aes_xts_dec_256" }, 437 }; 438 439 for (int i = 0; i < DIM(xts_test_funcs); i++) { 440 fail |= test_aes_xts_api(xts_test_funcs[i].xts_func_ptr, 441 xts_test_funcs[i].func_name, 0); 442 } 443 /* Test AES-XTS expanded key API */ 444 const struct test_func xts_exp_test_funcs[] = { 445 { .xts_func_ptr = isal_aes_xts_enc_128_expanded_key, 446 "isal_aes_xts_enc_128_expanded_key" }, 447 { .xts_func_ptr = isal_aes_xts_enc_256_expanded_key, 448 "isal_aes_xts_enc_256_expanded_key" }, 449 { .xts_func_ptr = isal_aes_xts_dec_128_expanded_key, 450 "isal_aes_xts_dec_128_expanded_key" }, 451 { .xts_func_ptr = isal_aes_xts_dec_256_expanded_key, 452 "isal_aes_xts_dec_256_expanded_key" }, 453 }; 454 455 for (int i = 0; i < DIM(xts_exp_test_funcs); i++) { 456 fail |= test_aes_xts_api(xts_exp_test_funcs[i].xts_func_ptr, 457 xts_exp_test_funcs[i].func_name, 1); 458 } 459 460 /* Test AES-GCM enc / dec API */ 461 const struct test_func gcm_test_funcs[] = { 462 { .gcm_func_ptr = isal_aes_gcm_enc_128, "isal_aes_gcm_enc_128" }, 463 { .gcm_func_ptr = isal_aes_gcm_enc_256, "isal_aes_gcm_enc_256" }, 464 { .gcm_func_ptr = isal_aes_gcm_dec_128, "isal_aes_gcm_dec_128" }, 465 { .gcm_func_ptr = isal_aes_gcm_dec_256, "isal_aes_gcm_dec_256" }, 466 { .gcm_func_ptr = isal_aes_gcm_enc_128_nt, "isal_aes_gcm_enc_128_nt" }, 467 { .gcm_func_ptr = isal_aes_gcm_enc_256_nt, "isal_aes_gcm_enc_256_nt" }, 468 { .gcm_func_ptr = isal_aes_gcm_dec_128_nt, "isal_aes_gcm_dec_128_nt" }, 469 { .gcm_func_ptr = isal_aes_gcm_dec_256_nt, "isal_aes_gcm_dec_256_nt" }, 470 }; 471 472 for (int i = 0; i < DIM(gcm_test_funcs); i++) { 473 fail |= test_aes_gcm_api(gcm_test_funcs[i].gcm_func_ptr, 474 gcm_test_funcs[i].func_name); 475 } 476 477 /* Test AES-GCM init API */ 478 const struct test_func gcm_init_test_funcs[] = { 479 { .gcm_init_func_ptr = isal_aes_gcm_init_128, "isal_aes_gcm_init_128" }, 480 { .gcm_init_func_ptr = isal_aes_gcm_init_256, "isal_aes_gcm_init_256" }, 481 }; 482 483 for (int i = 0; i < DIM(gcm_init_test_funcs); i++) { 484 fail |= test_aes_gcm_init_api(gcm_init_test_funcs[i].gcm_init_func_ptr, 485 gcm_init_test_funcs[i].func_name); 486 } 487 488 /* Test AES-GCM update API */ 489 const struct test_func gcm_update_test_funcs[] = { 490 { .gcm_update_func_ptr = isal_aes_gcm_enc_128_update, 491 "isal_aes_gcm_enc_128_update" }, 492 { .gcm_update_func_ptr = isal_aes_gcm_enc_256_update, 493 "isal_aes_gcm_enc_256_update" }, 494 { .gcm_update_func_ptr = isal_aes_gcm_dec_128_update, 495 "isal_aes_gcm_dec_128_update" }, 496 { .gcm_update_func_ptr = isal_aes_gcm_dec_256_update, 497 "isal_aes_gcm_dec_256_update" }, 498 { .gcm_update_func_ptr = isal_aes_gcm_enc_128_update_nt, 499 "isal_aes_gcm_enc_128_update_nt" }, 500 { .gcm_update_func_ptr = isal_aes_gcm_enc_256_update_nt, 501 "isal_aes_gcm_enc_256_update_nt" }, 502 { .gcm_update_func_ptr = isal_aes_gcm_dec_128_update_nt, 503 "isal_aes_gcm_dec_128_update_nt" }, 504 { .gcm_update_func_ptr = isal_aes_gcm_dec_256_update_nt, 505 "isal_aes_gcm_dec_256_update_nt" }, 506 }; 507 508 for (int i = 0; i < DIM(gcm_update_test_funcs); i++) { 509 fail |= test_aes_gcm_update_api(gcm_update_test_funcs[i].gcm_update_func_ptr, 510 gcm_update_test_funcs[i].func_name); 511 } 512 513 /* Test AES-GCM finalize API */ 514 const struct test_func gcm_finalize_128_test_funcs[] = { 515 { .gcm_finalize_func_ptr = isal_aes_gcm_enc_128_finalize, 516 "isal_aes_gcm_enc_128_finalize" }, 517 { .gcm_finalize_func_ptr = isal_aes_gcm_dec_128_finalize, 518 "isal_aes_gcm_dec_128_finalize" }, 519 }; 520 521 for (int i = 0; i < DIM(gcm_finalize_128_test_funcs); i++) { 522 fail |= test_aes_gcm_finalize_api( 523 gcm_finalize_128_test_funcs[i].gcm_finalize_func_ptr, 524 gcm_finalize_128_test_funcs[i].func_name, BITS_128); 525 } 526 527 const struct test_func gcm_finalize_256_test_funcs[] = { 528 { .gcm_finalize_func_ptr = isal_aes_gcm_enc_256_finalize, 529 "isal_aes_gcm_enc_256_finalize" }, 530 { .gcm_finalize_func_ptr = isal_aes_gcm_dec_256_finalize, 531 "isal_aes_gcm_dec_256_finalize" }, 532 }; 533 534 for (int i = 0; i < DIM(gcm_finalize_256_test_funcs); i++) { 535 fail |= test_aes_gcm_finalize_api( 536 gcm_finalize_256_test_funcs[i].gcm_finalize_func_ptr, 537 gcm_finalize_256_test_funcs[i].func_name, BITS_256); 538 } 539 540 /* Test AES-GCM pre API */ 541 const struct test_func gcm_pre_test_funcs[] = { 542 { .gcm_pre_func_ptr = isal_aes_gcm_pre_128, "isal_aes_gcm_pre_128" }, 543 { .gcm_pre_func_ptr = isal_aes_gcm_pre_256, "isal_aes_gcm_pre_256" }, 544 }; 545 546 for (int i = 0; i < DIM(gcm_pre_test_funcs); i++) { 547 fail |= test_aes_gcm_pre_api(gcm_pre_test_funcs[i].gcm_pre_func_ptr, 548 gcm_pre_test_funcs[i].func_name); 549 } 550 551 printf(fail ? "Fail\n" : "Pass\n"); 552 #else 553 printf("Not Executed\n"); 554 #endif 555 return fail; 556 } 557