|
52 | 52 | * always fires whenever either is defined; the legacy spelling |
53 | 53 | * remains as an alias kept around for unmigrated consumer code. |
54 | 54 | * |
55 | | - * 2. Macro / static-inline aliases for the legacy type and function |
56 | | - * names (dilithium_key, wc_dilithium_params, wc_dilithium_*, |
57 | | - * wc_Dilithium_*) so application code written against the |
58 | | - * pre-standardization API keeps compiling. Suppressed by defining |
59 | | - * WOLFSSL_NO_DILITHIUM_LEGACY_NAMES. |
| 55 | + * 2. Macro aliases for the legacy type and function names (dilithium_key, |
| 56 | + * wc_dilithium_params, wc_dilithium_*, wc_Dilithium_*) so application code |
| 57 | + * written against the pre-standardization API keeps compiling. Suppressed |
| 58 | + * by defining WOLFSSL_NO_DILITHIUM_LEGACY_NAMES. |
60 | 59 | * |
61 | 60 | * New code must include <wolfssl/wolfcrypt/wc_mldsa.h> directly and use |
62 | 61 | * the wc_MlDsaKey / wc_MlDsaKey_* / WOLFSSL_MLDSA_* names. */ |
|
381 | 380 |
|
382 | 381 | /* Legacy default-args / arg-reorder wrappers. The legacy form takes the key |
383 | 382 | * pointer last (or near last); the FIPS 204 / ML-KEM convention used by the |
384 | | - * canonical wc_MlDsaKey_* names puts the key first. The wrappers below are |
385 | | - * static inline functions (rather than function-like macros) so that |
386 | | - * (a) `&wc_dilithium_init`-style address-of expressions remain valid in |
387 | | - * source (they yield the inline wrapper's address - note this is a |
388 | | - * translation-unit-local symbol, not the previously-exported library |
389 | | - * symbol) and (b) each wrapper preserves the legacy signature byte-for-byte. |
390 | | - * Each wrapper is gated to match its canonical target's gating so |
391 | | - * unused-on-this-build wrappers don't reference undeclared symbols. */ |
392 | | - |
393 | | -#ifdef __GNUC__ |
394 | | - /* Suppress -Wunused-function for translation units that don't call every |
395 | | - * legacy wrapper. */ |
396 | | - #define WOLFSSL_DILITHIUM_LEGACY_INLINE static __inline__ \ |
397 | | - __attribute__((unused, always_inline)) |
398 | | -#else |
399 | | - #define WOLFSSL_DILITHIUM_LEGACY_INLINE static WC_INLINE |
400 | | -#endif |
401 | | - |
402 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
403 | | -int wc_dilithium_init(wc_MlDsaKey* key) { |
404 | | - return wc_MlDsaKey_Init(key, NULL, INVALID_DEVID); |
405 | | -} |
| 383 | + * canonical wc_MlDsaKey_* names puts the key first. */ |
406 | 384 |
|
| 385 | +#define wc_dilithium_init(key) \ |
| 386 | + wc_MlDsaKey_Init(key, NULL, INVALID_DEVID) |
407 | 387 | #ifdef WOLFSSL_MLDSA_PUBLIC_KEY |
408 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
409 | | -int wc_dilithium_import_public(const byte* in, word32 inLen, wc_MlDsaKey* key) { |
410 | | - return wc_MlDsaKey_ImportPubRaw(key, in, inLen); |
411 | | -} |
| 388 | + #define wc_dilithium_import_public(in, inLen, key) wc_MlDsaKey_ImportPubRaw(key, in, inLen) |
412 | 389 | #endif |
413 | | - |
414 | 390 | #ifdef WOLFSSL_MLDSA_PRIVATE_KEY |
415 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
416 | | -int wc_dilithium_import_private(const byte* priv, word32 privSz, wc_MlDsaKey* key) { |
417 | | - return wc_MlDsaKey_ImportPrivRaw(key, priv, privSz); |
418 | | -} |
419 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
420 | | -int wc_dilithium_import_private_only(const byte* in, word32 inLen, wc_MlDsaKey* key) { |
421 | | - return wc_MlDsaKey_ImportPrivRaw(key, in, inLen); |
422 | | -} |
423 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
424 | | -int wc_dilithium_import_key(const byte* priv, word32 privSz, const byte* pub, |
425 | | - word32 pubSz, wc_MlDsaKey* key) { |
426 | | - return wc_MlDsaKey_ImportKey(key, priv, privSz, pub, pubSz); |
427 | | -} |
| 391 | + #define wc_dilithium_import_private(priv, privSz, key) \ |
| 392 | + wc_MlDsaKey_ImportPrivRaw(key, priv, privSz) |
| 393 | + #define wc_dilithium_import_private_only(in, inLen, key) \ |
| 394 | + wc_MlDsaKey_ImportPrivRaw(key, in, inLen) |
| 395 | + #define wc_dilithium_import_key(priv, privSz, pub, pubSz, key) \ |
| 396 | + wc_MlDsaKey_ImportKey(key, priv, privSz, pub, pubSz) |
428 | 397 | #endif /* WOLFSSL_MLDSA_PRIVATE_KEY */ |
429 | | - |
430 | 398 | #ifndef WOLFSSL_MLDSA_VERIFY_ONLY |
431 | | -#ifdef WOLFSSL_MLDSA_NO_CTX |
432 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
433 | | -int wc_dilithium_sign_msg(const byte* msg, word32 msgLen, byte* sig, |
434 | | - word32* sigLen, wc_MlDsaKey* key, WC_RNG* rng) { |
435 | | - return wc_MlDsaKey_Sign(key, sig, sigLen, msg, msgLen, rng); |
436 | | -} |
437 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
438 | | -int wc_dilithium_sign_msg_with_seed(const byte* msg, word32 msgLen, byte* sig, |
439 | | - word32* sigLen, wc_MlDsaKey* key, |
440 | | - const byte* seed) { |
441 | | - return wc_MlDsaKey_SignWithSeed(key, sig, sigLen, msg, msgLen, seed); |
442 | | -} |
443 | | -#endif /* WOLFSSL_MLDSA_NO_CTX */ |
444 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
445 | | -int wc_dilithium_sign_ctx_msg(const byte* ctx, byte ctxLen, const byte* msg, |
446 | | - word32 msgLen, byte* sig, word32* sigLen, |
447 | | - wc_MlDsaKey* key, WC_RNG* rng) { |
448 | | - return wc_MlDsaKey_SignCtx(key, ctx, ctxLen, sig, sigLen, msg, msgLen, rng); |
449 | | -} |
450 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
451 | | -int wc_dilithium_sign_ctx_hash(const byte* ctx, byte ctxLen, int hashAlg, |
452 | | - const byte* hash, word32 hashLen, byte* sig, |
453 | | - word32* sigLen, wc_MlDsaKey* key, WC_RNG* rng) { |
454 | | - return wc_MlDsaKey_SignCtxHash(key, ctx, ctxLen, sig, sigLen, hash, |
455 | | - hashLen, hashAlg, rng); |
456 | | -} |
457 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
458 | | -int wc_dilithium_sign_ctx_msg_with_seed(const byte* ctx, byte ctxLen, |
459 | | - const byte* msg, word32 msgLen, |
460 | | - byte* sig, word32* sigLen, |
461 | | - wc_MlDsaKey* key, const byte* seed) { |
462 | | - return wc_MlDsaKey_SignCtxWithSeed(key, ctx, ctxLen, sig, sigLen, msg, |
463 | | - msgLen, seed); |
464 | | -} |
465 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
466 | | -int wc_dilithium_sign_ctx_hash_with_seed(const byte* ctx, byte ctxLen, |
467 | | - int hashAlg, const byte* hash, |
468 | | - word32 hashLen, byte* sig, |
469 | | - word32* sigLen, wc_MlDsaKey* key, |
470 | | - const byte* seed) { |
471 | | - return wc_MlDsaKey_SignCtxHashWithSeed(key, ctx, ctxLen, sig, sigLen, |
472 | | - hash, hashLen, hashAlg, seed); |
473 | | -} |
474 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
475 | | -int wc_dilithium_sign_mu_with_seed(const byte* mu, word32 muLen, byte* sig, |
476 | | - word32* sigLen, wc_MlDsaKey* key, |
477 | | - const byte* seed) { |
478 | | - return wc_MlDsaKey_SignMuWithSeed(key, sig, sigLen, mu, muLen, seed); |
479 | | -} |
| 399 | + #ifdef WOLFSSL_MLDSA_NO_CTX |
| 400 | + #define wc_dilithium_sign_msg(msg, msgLen, sig, sigLen, key, rng) \ |
| 401 | + wc_MlDsaKey_Sign(key, sig, sigLen, msg, msgLen, rng) |
| 402 | + #define wc_dilithium_sign_msg_with_seed(msg, msgLen, sig, sigLen, key, seed) \ |
| 403 | + wc_MlDsaKey_SignWithSeed(key, sig, sigLen, msg, msgLen, seed) |
| 404 | + #endif /* WOLFSSL_MLDSA_NO_CTX */ |
| 405 | + #define wc_dilithium_sign_ctx_msg(ctx, ctxLen, msg, msgLen, sig, sigLen, key, rng) \ |
| 406 | + wc_MlDsaKey_SignCtx(key, ctx, ctxLen, sig, sigLen, msg, msgLen, rng) |
| 407 | + #define wc_dilithium_sign_ctx_hash(ctx, ctxLen, hashAlg, hash, hashLen, sig, sigLen, key, rng) \ |
| 408 | + wc_MlDsaKey_SignCtxHash(key, ctx, ctxLen, sig, sigLen, hash, hashLen, hashAlg, rng) |
| 409 | + #define wc_dilithium_sign_ctx_msg_with_seed(ctx, ctxLen, msg, msgLen, sig, sigLen, key, seed) \ |
| 410 | + wc_MlDsaKey_SignCtxWithSeed(key, ctx, ctxLen, sig, sigLen, msg, msgLen, seed) |
| 411 | + #define wc_dilithium_sign_ctx_hash_with_seed(ctx, ctxLen, hashAlg, hash, hashLen, sig, sigLen, key, seed) \ |
| 412 | + wc_MlDsaKey_SignCtxHashWithSeed(key, ctx, ctxLen, sig, sigLen, hash, hashLen, hashAlg, seed) |
| 413 | + #define wc_dilithium_sign_mu_with_seed(mu, muLen, sig, sigLen, key, seed) \ |
| 414 | + wc_MlDsaKey_SignMuWithSeed(key, sig, sigLen, mu, muLen, seed) |
480 | 415 | #endif /* !WOLFSSL_MLDSA_VERIFY_ONLY */ |
481 | | - |
482 | 416 | #ifdef WOLFSSL_MLDSA_NO_CTX |
483 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
484 | | -int wc_dilithium_verify_msg(const byte* sig, word32 sigLen, const byte* msg, |
485 | | - word32 msgLen, int* res, wc_MlDsaKey* key) { |
486 | | - return wc_MlDsaKey_Verify(key, sig, sigLen, msg, msgLen, res); |
487 | | -} |
| 417 | + #define wc_dilithium_verify_msg(sig, sigLen, msg, msgLen, res, key) \ |
| 418 | + wc_MlDsaKey_Verify(key, sig, sigLen, msg, msgLen, res) |
488 | 419 | #endif /* WOLFSSL_MLDSA_NO_CTX */ |
489 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
490 | | -int wc_dilithium_verify_ctx_msg(const byte* sig, word32 sigLen, const byte* ctx, |
491 | | - byte ctxLen, const byte* msg, word32 msgLen, |
492 | | - int* res, wc_MlDsaKey* key) { |
493 | | - return wc_MlDsaKey_VerifyCtx(key, sig, sigLen, ctx, ctxLen, msg, msgLen, |
494 | | - res); |
495 | | -} |
496 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
497 | | -int wc_dilithium_verify_ctx_hash(const byte* sig, word32 sigLen, const byte* ctx, |
498 | | - byte ctxLen, int hashAlg, const byte* hash, |
499 | | - word32 hashLen, int* res, wc_MlDsaKey* key) { |
500 | | - return wc_MlDsaKey_VerifyCtxHash(key, sig, sigLen, ctx, ctxLen, hash, |
501 | | - hashLen, hashAlg, res); |
502 | | -} |
503 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
504 | | -int wc_dilithium_verify_mu(const byte* sig, word32 sigLen, const byte* mu, |
505 | | - word32 muLen, int* res, wc_MlDsaKey* key) { |
506 | | - return wc_MlDsaKey_VerifyMu(key, sig, sigLen, mu, muLen, res); |
507 | | -} |
508 | | - |
| 420 | +#define wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, ctxLen, msg, msgLen, res, key) \ |
| 421 | + wc_MlDsaKey_VerifyCtx(key, sig, sigLen, ctx, ctxLen, msg, msgLen, res) |
| 422 | +#define wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, ctxLen, hashAlg, hash, hashLen, res, key) \ |
| 423 | + wc_MlDsaKey_VerifyCtxHash(key, sig, sigLen, ctx, ctxLen, hash, hashLen, hashAlg, res) |
| 424 | +#define wc_dilithium_verify_mu(sig, sigLen, mu, muLen, res, key) \ |
| 425 | + wc_MlDsaKey_VerifyMu(key, sig, sigLen, mu, muLen, res) |
509 | 426 | #ifndef WOLFSSL_MLDSA_NO_ASN1 |
510 | | -#ifdef WOLFSSL_MLDSA_PRIVATE_KEY |
511 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
512 | | -int wc_Dilithium_PrivateKeyDecode(const byte* input, word32* inOutIdx, |
513 | | - wc_MlDsaKey* key, word32 inSz) { |
514 | | - return wc_MlDsaKey_PrivateKeyDecode(key, input, inSz, inOutIdx); |
515 | | -} |
516 | | -#endif |
517 | | -#ifdef WOLFSSL_MLDSA_PUBLIC_KEY |
518 | | -WOLFSSL_DILITHIUM_LEGACY_INLINE |
519 | | -int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx, |
520 | | - wc_MlDsaKey* key, word32 inSz) { |
521 | | - return wc_MlDsaKey_PublicKeyDecode(key, input, inSz, inOutIdx); |
522 | | -} |
523 | | -#endif |
| 427 | + #ifdef WOLFSSL_MLDSA_PRIVATE_KEY |
| 428 | + #define wc_Dilithium_PrivateKeyDecode(input, inOutIdx, key, inSz) \ |
| 429 | + wc_MlDsaKey_PrivateKeyDecode(key, input, inSz, inOutIdx) |
| 430 | + #endif |
| 431 | + #ifdef WOLFSSL_MLDSA_PUBLIC_KEY |
| 432 | + #define wc_Dilithium_PublicKeyDecode(input, inOutIdx, key, inSz) \ |
| 433 | + wc_MlDsaKey_PublicKeyDecode(key, input, inSz, inOutIdx) |
| 434 | + #endif |
524 | 435 | #endif /* !WOLFSSL_MLDSA_NO_ASN1 */ |
525 | 436 |
|
526 | 437 | /* Internal-helper aliases. These cover symbols that are *not* part of the |
|
0 commit comments