|
1 | 1 | /* wolfssl_stsafe_full_test.c |
2 | 2 | * |
3 | 3 | * Comprehensive wolfSSL integration tests with STSAFE-A120 |
4 | | - * Tests: RNG, ECC KeyGen, ECDSA Sign/Verify, ECDH, Benchmarks |
| 4 | + * Tests: RNG, ECC KeyGen, ECDSA Sign/Verify, ECDH, Benchmarks, Brainpool curves |
5 | 5 | * |
6 | 6 | * Copyright (C) 2006-2026 wolfSSL Inc. |
7 | 7 | * |
@@ -353,6 +353,200 @@ static int test_ecdh_p256(void) |
353 | 353 | return 0; |
354 | 354 | } |
355 | 355 |
|
| 356 | +/*----------------------------------------------------------------------------- |
| 357 | + * Test: ECDSA Brainpool P-256 Benchmark |
| 358 | + *---------------------------------------------------------------------------*/ |
| 359 | +#if defined(HAVE_ECC_BRAINPOOL) && defined(STSE_CONF_ECC_BRAINPOOL_P_256) |
| 360 | +static int test_ecdsa_brainpool_p256_benchmark(void) |
| 361 | +{ |
| 362 | + ecc_key key; |
| 363 | + WC_RNG rng; |
| 364 | + int ret; |
| 365 | + byte digest[32]; |
| 366 | + byte sig[128]; |
| 367 | + word32 sigLen; |
| 368 | + int verified = 0; |
| 369 | + int iterations = 10; |
| 370 | + double start, end, elapsed; |
| 371 | + int i; |
| 372 | + |
| 373 | + printf("\nTest: ECDSA Brainpool P-256 Benchmark (STSAFE-A120)\n"); |
| 374 | + |
| 375 | + ret = wc_InitRng(&rng); |
| 376 | + if (ret != 0) { |
| 377 | + printf(" Error: wc_InitRng failed: %d\n", ret); |
| 378 | + TEST_FAIL("ECDSA Brainpool P-256 benchmark RNG init"); |
| 379 | + return -1; |
| 380 | + } |
| 381 | + |
| 382 | + memset(digest, 0xAB, sizeof(digest)); |
| 383 | + |
| 384 | + ret = wc_ecc_init_ex(&key, NULL, g_devId); |
| 385 | + if (ret != 0) { |
| 386 | + printf(" Error: wc_ecc_init_ex failed: %d\n", ret); |
| 387 | + wc_FreeRng(&rng); |
| 388 | + TEST_FAIL("ECDSA Brainpool P-256 benchmark key init"); |
| 389 | + return -1; |
| 390 | + } |
| 391 | + |
| 392 | + /* Benchmark key generation */ |
| 393 | + start = get_time_us(); |
| 394 | + ret = wc_ecc_make_key_ex(&rng, 32, &key, ECC_BRAINPOOLP256R1); |
| 395 | + end = get_time_us(); |
| 396 | + elapsed = (end - start) / 1000.0; |
| 397 | + |
| 398 | + if (ret != 0) { |
| 399 | + printf(" Error: wc_ecc_make_key_ex failed: %d\n", ret); |
| 400 | + wc_ecc_free(&key); |
| 401 | + wc_FreeRng(&rng); |
| 402 | + TEST_FAIL("ECDSA Brainpool P-256 keygen"); |
| 403 | + return -1; |
| 404 | + } |
| 405 | + printf(" Key generation: %.2f ms\n", elapsed); |
| 406 | + |
| 407 | + /* Benchmark signing */ |
| 408 | + start = get_time_us(); |
| 409 | + for (i = 0; i < iterations; i++) { |
| 410 | + sigLen = sizeof(sig); |
| 411 | + ret = wc_ecc_sign_hash(digest, sizeof(digest), sig, &sigLen, &rng, &key); |
| 412 | + if (ret != 0) break; |
| 413 | + } |
| 414 | + end = get_time_us(); |
| 415 | + elapsed = (end - start) / 1000.0; |
| 416 | + |
| 417 | + if (ret != 0) { |
| 418 | + printf(" Error: wc_ecc_sign_hash failed: %d\n", ret); |
| 419 | + wc_ecc_free(&key); |
| 420 | + wc_FreeRng(&rng); |
| 421 | + TEST_FAIL("ECDSA Brainpool P-256 sign"); |
| 422 | + return -1; |
| 423 | + } |
| 424 | + printf(" Signing: %d ops in %.2f ms (%.2f ops/sec)\n", |
| 425 | + iterations, elapsed, iterations / (elapsed / 1000.0)); |
| 426 | + |
| 427 | + /* Benchmark verification */ |
| 428 | + start = get_time_us(); |
| 429 | + for (i = 0; i < iterations; i++) { |
| 430 | + ret = wc_ecc_verify_hash(sig, sigLen, digest, sizeof(digest), &verified, &key); |
| 431 | + if (ret != 0 || verified != 1) break; |
| 432 | + } |
| 433 | + end = get_time_us(); |
| 434 | + elapsed = (end - start) / 1000.0; |
| 435 | + |
| 436 | + if (ret != 0 || verified != 1) { |
| 437 | + printf(" Error: wc_ecc_verify_hash failed: %d, verified=%d\n", ret, verified); |
| 438 | + wc_ecc_free(&key); |
| 439 | + wc_FreeRng(&rng); |
| 440 | + TEST_FAIL("ECDSA Brainpool P-256 verify"); |
| 441 | + return -1; |
| 442 | + } |
| 443 | + printf(" Verification: %d ops in %.2f ms (%.2f ops/sec)\n", |
| 444 | + iterations, elapsed, iterations / (elapsed / 1000.0)); |
| 445 | + |
| 446 | + wc_ecc_free(&key); |
| 447 | + wc_FreeRng(&rng); |
| 448 | + TEST_PASS("ECDSA Brainpool P-256 benchmark"); |
| 449 | + return 0; |
| 450 | +} |
| 451 | +#endif /* HAVE_ECC_BRAINPOOL && STSE_CONF_ECC_BRAINPOOL_P_256 */ |
| 452 | + |
| 453 | +/*----------------------------------------------------------------------------- |
| 454 | + * Test: ECDSA Brainpool P-384 Benchmark |
| 455 | + *---------------------------------------------------------------------------*/ |
| 456 | +#if defined(HAVE_ECC_BRAINPOOL) && defined(STSE_CONF_ECC_BRAINPOOL_P_384) |
| 457 | +static int test_ecdsa_brainpool_p384_benchmark(void) |
| 458 | +{ |
| 459 | + ecc_key key; |
| 460 | + WC_RNG rng; |
| 461 | + int ret; |
| 462 | + byte digest[48]; |
| 463 | + byte sig[128]; |
| 464 | + word32 sigLen; |
| 465 | + int verified = 0; |
| 466 | + int iterations = 10; |
| 467 | + double start, end, elapsed; |
| 468 | + int i; |
| 469 | + |
| 470 | + printf("\nTest: ECDSA Brainpool P-384 Benchmark (STSAFE-A120)\n"); |
| 471 | + |
| 472 | + ret = wc_InitRng(&rng); |
| 473 | + if (ret != 0) { |
| 474 | + printf(" Error: wc_InitRng failed: %d\n", ret); |
| 475 | + TEST_FAIL("ECDSA Brainpool P-384 benchmark RNG init"); |
| 476 | + return -1; |
| 477 | + } |
| 478 | + |
| 479 | + memset(digest, 0xCD, sizeof(digest)); |
| 480 | + |
| 481 | + ret = wc_ecc_init_ex(&key, NULL, g_devId); |
| 482 | + if (ret != 0) { |
| 483 | + printf(" Error: wc_ecc_init_ex failed: %d\n", ret); |
| 484 | + wc_FreeRng(&rng); |
| 485 | + TEST_FAIL("ECDSA Brainpool P-384 benchmark key init"); |
| 486 | + return -1; |
| 487 | + } |
| 488 | + |
| 489 | + /* Benchmark key generation */ |
| 490 | + start = get_time_us(); |
| 491 | + ret = wc_ecc_make_key_ex(&rng, 48, &key, ECC_BRAINPOOLP384R1); |
| 492 | + end = get_time_us(); |
| 493 | + elapsed = (end - start) / 1000.0; |
| 494 | + |
| 495 | + if (ret != 0) { |
| 496 | + printf(" Error: wc_ecc_make_key_ex failed: %d\n", ret); |
| 497 | + wc_ecc_free(&key); |
| 498 | + wc_FreeRng(&rng); |
| 499 | + TEST_FAIL("ECDSA Brainpool P-384 keygen"); |
| 500 | + return -1; |
| 501 | + } |
| 502 | + printf(" Key generation: %.2f ms\n", elapsed); |
| 503 | + |
| 504 | + /* Benchmark signing */ |
| 505 | + start = get_time_us(); |
| 506 | + for (i = 0; i < iterations; i++) { |
| 507 | + sigLen = sizeof(sig); |
| 508 | + ret = wc_ecc_sign_hash(digest, sizeof(digest), sig, &sigLen, &rng, &key); |
| 509 | + if (ret != 0) break; |
| 510 | + } |
| 511 | + end = get_time_us(); |
| 512 | + elapsed = (end - start) / 1000.0; |
| 513 | + |
| 514 | + if (ret != 0) { |
| 515 | + printf(" Error: wc_ecc_sign_hash failed: %d\n", ret); |
| 516 | + wc_ecc_free(&key); |
| 517 | + wc_FreeRng(&rng); |
| 518 | + TEST_FAIL("ECDSA Brainpool P-384 sign"); |
| 519 | + return -1; |
| 520 | + } |
| 521 | + printf(" Signing: %d ops in %.2f ms (%.2f ops/sec)\n", |
| 522 | + iterations, elapsed, iterations / (elapsed / 1000.0)); |
| 523 | + |
| 524 | + /* Benchmark verification */ |
| 525 | + start = get_time_us(); |
| 526 | + for (i = 0; i < iterations; i++) { |
| 527 | + ret = wc_ecc_verify_hash(sig, sigLen, digest, sizeof(digest), &verified, &key); |
| 528 | + if (ret != 0 || verified != 1) break; |
| 529 | + } |
| 530 | + end = get_time_us(); |
| 531 | + elapsed = (end - start) / 1000.0; |
| 532 | + |
| 533 | + if (ret != 0 || verified != 1) { |
| 534 | + printf(" Error: wc_ecc_verify_hash failed: %d, verified=%d\n", ret, verified); |
| 535 | + wc_ecc_free(&key); |
| 536 | + wc_FreeRng(&rng); |
| 537 | + TEST_FAIL("ECDSA Brainpool P-384 verify"); |
| 538 | + return -1; |
| 539 | + } |
| 540 | + printf(" Verification: %d ops in %.2f ms (%.2f ops/sec)\n", |
| 541 | + iterations, elapsed, iterations / (elapsed / 1000.0)); |
| 542 | + |
| 543 | + wc_ecc_free(&key); |
| 544 | + wc_FreeRng(&rng); |
| 545 | + TEST_PASS("ECDSA Brainpool P-384 benchmark"); |
| 546 | + return 0; |
| 547 | +} |
| 548 | +#endif /* HAVE_ECC_BRAINPOOL && STSE_CONF_ECC_BRAINPOOL_P_384 */ |
| 549 | + |
356 | 550 | /*----------------------------------------------------------------------------- |
357 | 551 | * Test: Multiple Key Slots |
358 | 552 | *---------------------------------------------------------------------------*/ |
@@ -479,6 +673,12 @@ int main(void) |
479 | 673 | /* Run tests */ |
480 | 674 | test_rng_benchmark(); |
481 | 675 | test_ecdsa_p256_benchmark(); |
| 676 | +#if defined(HAVE_ECC_BRAINPOOL) && defined(STSE_CONF_ECC_BRAINPOOL_P_256) |
| 677 | + test_ecdsa_brainpool_p256_benchmark(); |
| 678 | +#endif |
| 679 | +#if defined(HAVE_ECC_BRAINPOOL) && defined(STSE_CONF_ECC_BRAINPOOL_P_384) |
| 680 | + test_ecdsa_brainpool_p384_benchmark(); |
| 681 | +#endif |
482 | 682 |
|
483 | 683 | /* ECDH test - now uses ECDHE ephemeral keys */ |
484 | 684 | test_ecdh_p256(); |
|
0 commit comments