已合并
fix: pqc algId migrate #497
c3dehui创建于 2025年8月26日
fix: pqc algId migrate #497
已合并
共 11 个文件变更+85-63
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "eal_pkey_local.h" | 22 | #include "eal_pkey_local.h" |
| 23 | #include "crypt_eal_pkey.h" | 23 | #include "crypt_eal_pkey.h" |
| 24 | #include "crypt_utils.h" | 24 | #include "crypt_utils.h" |
| 25 | +#include "crypt_algid.h" | ||
| 25 | #include "crypt_hybridkem_local.h" | 26 | #include "crypt_hybridkem_local.h" |
| 26 | #include "crypt_hybridkem.h" | 27 | #include "crypt_hybridkem.h" |
| 27 | #include "crypt_ecdh.h" | 28 | #include "crypt_ecdh.h" |
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "crypt_errno.h" | 19 | #include "crypt_errno.h" |
| 20 | #include "crypt_util_rand.h" | 20 | #include "crypt_util_rand.h" |
| 21 | #include "crypt_utils.h" | 21 | #include "crypt_utils.h" |
| 22 | +#include "crypt_algid.h" | ||
| 22 | #include "bsl_errno.h" | 23 | #include "bsl_errno.h" |
| 23 | #include "bsl_sal.h" | 24 | #include "bsl_sal.h" |
| 24 | #include "bsl_obj_internal.h" | 25 | #include "bsl_obj_internal.h" |
| @@ -17,6 +17,7 @@ | |||
| 17 | #ifdef HITLS_CRYPTO_MLKEM | 17 | #ifdef HITLS_CRYPTO_MLKEM |
| 18 | #include "securec.h" | 18 | #include "securec.h" |
| 19 | #include "crypt_errno.h" | 19 | #include "crypt_errno.h" |
| 20 | +#include "crypt_algid.h" | ||
| 20 | #include "bsl_sal.h" | 21 | #include "bsl_sal.h" |
| 21 | #include "bsl_err_internal.h" | 22 | #include "bsl_err_internal.h" |
| 22 | #include "eal_pkey_local.h" | 23 | #include "eal_pkey_local.h" |
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "bsl_obj_internal.h" | 22 | #include "bsl_obj_internal.h" |
| 23 | #include "bsl_asn1.h" | 23 | #include "bsl_asn1.h" |
| 24 | #include "crypt_errno.h" | 24 | #include "crypt_errno.h" |
| 25 | +#include "crypt_algid.h" | ||
| 25 | #include "crypt_util_rand.h" | 26 | #include "crypt_util_rand.h" |
| 26 | #include "eal_md_local.h" | 27 | #include "eal_md_local.h" |
| 27 | #include "crypt_slh_dsa.h" | 28 | #include "crypt_slh_dsa.h" |
| @@ -37,6 +38,7 @@ | |||
| 37 | #define ASN1_HEADER_LEN 2 | 38 | #define ASN1_HEADER_LEN 2 |
| 38 | #define SPLIT_CEIL(a, b) (((a) + (b) - 1) / (b)) | 39 | #define SPLIT_CEIL(a, b) (((a) + (b) - 1) / (b)) |
| 39 | #define SPLIT_BYTES(a) SPLIT_CEIL(a, BYTE_BITS) | 40 | #define SPLIT_BYTES(a) SPLIT_CEIL(a, BYTE_BITS) |
| 41 | +#define NUM_OF_CRYPT_SLH_DSA_ALGId 12 | ||
| 40 | 42 | ||
| 41 | typedef struct { | 43 | typedef struct { |
| 42 | BSL_Param *pubSeed; | 44 | BSL_Param *pubSeed; |
| @@ -51,16 +53,16 @@ typedef struct { | |||
| 51 | } SlhDsaPrvKeyParam; | 53 | } SlhDsaPrvKeyParam; |
| 52 | 54 | ||
| 53 | // reference to FIPS-205, table 2 | 55 | // reference to FIPS-205, table 2 |
| 54 | -static uint32_t g_slhDsaN[CRYPT_SLH_DSA_ALG_ID_MAX] = {16, 16, 16, 16, 24, 24, 24, 24, 32, 32, 32, 32}; | 56 | +static uint32_t g_slhDsaN[NUM_OF_CRYPT_SLH_DSA_ALGId] = {16, 16, 16, 16, 24, 24, 24, 24, 32, 32, 32, 32}; |
| 55 | -static uint32_t g_slhDsaH[CRYPT_SLH_DSA_ALG_ID_MAX] = {63, 63, 66, 66, 63, 63, 66, 66, 64, 64, 68, 68}; | 57 | +static uint32_t g_slhDsaH[NUM_OF_CRYPT_SLH_DSA_ALGId] = {63, 63, 66, 66, 63, 63, 66, 66, 64, 64, 68, 68}; |
| 56 | -static uint32_t g_slhDsaD[CRYPT_SLH_DSA_ALG_ID_MAX] = {7, 7, 22, 22, 7, 7, 22, 22, 8, 8, 17, 17}; | 58 | +static uint32_t g_slhDsaD[NUM_OF_CRYPT_SLH_DSA_ALGId] = {7, 7, 22, 22, 7, 7, 22, 22, 8, 8, 17, 17}; |
| 57 | -static uint32_t g_slhDsaHp[CRYPT_SLH_DSA_ALG_ID_MAX] = {9, 9, 3, 3, 9, 9, 3, 3, 8, 8, 4, 4}; // xmss height | 59 | +static uint32_t g_slhDsaHp[NUM_OF_CRYPT_SLH_DSA_ALGId] = {9, 9, 3, 3, 9, 9, 3, 3, 8, 8, 4, 4}; // xmss height |
| 58 | -static uint32_t g_slhDsaA[CRYPT_SLH_DSA_ALG_ID_MAX] = {12, 12, 6, 6, 14, 14, 8, 8, 14, 14, 9, 9}; | 60 | +static uint32_t g_slhDsaA[NUM_OF_CRYPT_SLH_DSA_ALGId] = {12, 12, 6, 6, 14, 14, 8, 8, 14, 14, 9, 9}; |
| 59 | -static uint32_t g_slhDsaK[CRYPT_SLH_DSA_ALG_ID_MAX] = {14, 14, 33, 33, 17, 17, 33, 33, 22, 22, 35, 35}; | 61 | +static uint32_t g_slhDsaK[NUM_OF_CRYPT_SLH_DSA_ALGId] = {14, 14, 33, 33, 17, 17, 33, 33, 22, 22, 35, 35}; |
| 60 | -static uint32_t g_slhDsaM[CRYPT_SLH_DSA_ALG_ID_MAX] = {30, 30, 34, 34, 39, 39, 42, 42, 47, 47, 49, 49}; | 62 | +static uint32_t g_slhDsaM[NUM_OF_CRYPT_SLH_DSA_ALGId] = {30, 30, 34, 34, 39, 39, 42, 42, 47, 47, 49, 49}; |
| 61 | -static uint32_t g_slhDsaPkBytes[CRYPT_SLH_DSA_ALG_ID_MAX] = {32, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 64}; | 63 | +static uint32_t g_slhDsaPkBytes[NUM_OF_CRYPT_SLH_DSA_ALGId] = {32, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 64}; |
| 62 | -static uint32_t g_slhDsaSigBytes[CRYPT_SLH_DSA_ALG_ID_MAX] = {7856, 7856, 17088, 17088, 16224, 16224, | 64 | +static uint32_t g_slhDsaSigBytes[NUM_OF_CRYPT_SLH_DSA_ALGId] = {7856, 7856, 17088, 17088, 16224, 16224, |
| 63 | - 35664, 35664, 29792, 29792, 49856, 49856}; | 65 | + 35664, 35664, 29792, 29792, 49856, 49856}; |
| 64 | static uint8_t g_secCategory[] = {1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 5}; | 66 | static uint8_t g_secCategory[] = {1, 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 5}; |
| 65 | 67 | ||
| 66 | // "UC" means uncompressed | 68 | // "UC" means uncompressed |
| @@ -256,7 +258,7 @@ CryptSlhDsaCtx *CRYPT_SLH_DSA_NewCtx(void) | |||
| 256 | BSL_ERR_PUSH_ERROR(CRYPT_MEM_ALLOC_FAIL); | 258 | BSL_ERR_PUSH_ERROR(CRYPT_MEM_ALLOC_FAIL); |
| 257 | return NULL; | 259 | return NULL; |
| 258 | } | 260 | } |
| 259 | - ctx->para.algId = CRYPT_SLH_DSA_ALG_ID_MAX; | 261 | + ctx->para.algId = 0; |
| 260 | ctx->isPrehash = false; | 262 | ctx->isPrehash = false; |
| 261 | ctx->isDeterministic = false; | 263 | ctx->isDeterministic = false; |
| 262 | return ctx; | 264 | return ctx; |
| @@ -284,6 +286,14 @@ void CRYPT_SLH_DSA_FreeCtx(CryptSlhDsaCtx *ctx) | |||
| 284 | BSL_SAL_Free(ctx); | 286 | BSL_SAL_Free(ctx); |
| 285 | } | 287 | } |
| 286 | 288 | ||
| 289 | +static bool CheckNotSlhDsaAlgId(int32_t algId) | ||
| 290 | +{ | ||
| 291 | + if (algId > CRYPT_SLH_DSA_SHAKE_256F || algId < CRYPT_SLH_DSA_SHA2_128S) { | ||
| 292 | + return true; | ||
| 293 | + } | ||
| 294 | + return false; | ||
| 295 | +} | ||
| 296 | + | ||
| 287 | int32_t CRYPT_SLH_DSA_Gen(CryptSlhDsaCtx *ctx) | 297 | int32_t CRYPT_SLH_DSA_Gen(CryptSlhDsaCtx *ctx) |
| 288 | { | 298 | { |
| 289 | int32_t ret; | 299 | int32_t ret; |
| @@ -291,7 +301,7 @@ int32_t CRYPT_SLH_DSA_Gen(CryptSlhDsaCtx *ctx) | |||
| 291 | BSL_ERR_PUSH_ERROR(CRYPT_NULL_INPUT); | 301 | BSL_ERR_PUSH_ERROR(CRYPT_NULL_INPUT); |
| 292 | return CRYPT_NULL_INPUT; | 302 | return CRYPT_NULL_INPUT; |
| 293 | } | 303 | } |
| 294 | - if (ctx->para.algId >= CRYPT_SLH_DSA_ALG_ID_MAX) { | 304 | + if (CheckNotSlhDsaAlgId(ctx->para.algId)) { |
| 295 | BSL_ERR_PUSH_ERROR(CRYPT_SLHDSA_ERR_INVALID_ALGID); | 305 | BSL_ERR_PUSH_ERROR(CRYPT_SLHDSA_ERR_INVALID_ALGID); |
| 296 | return CRYPT_SLHDSA_ERR_INVALID_ALGID; | 306 | return CRYPT_SLHDSA_ERR_INVALID_ALGID; |
| 297 | } | 307 | } |
| @@ -595,19 +605,20 @@ int32_t CRYPT_SLH_DSA_Verify(const CryptSlhDsaCtx *ctx, int32_t algId, const uin | |||
| 595 | return ret; | 605 | return ret; |
| 596 | } | 606 | } |
| 597 | 607 | ||
| 598 | -static void SlhDsaSetAlgId(CryptSlhDsaCtx *ctx, CRYPT_SLH_DSA_AlgId algId) | 608 | +static void SlhDsaSetAlgId(CryptSlhDsaCtx *ctx, CRYPT_PKEY_ParaId algId) |
| 599 | { | 609 | { |
| 600 | ctx->para.algId = algId; | 610 | ctx->para.algId = algId; |
| 601 | - ctx->para.n = g_slhDsaN[algId]; | 611 | + int32_t index = algId - CRYPT_SLH_DSA_SHA2_128S; |
| 602 | - ctx->para.h = g_slhDsaH[algId]; | 612 | + ctx->para.n = g_slhDsaN[index]; |
| 603 | - ctx->para.d = g_slhDsaD[algId]; | 613 | + ctx->para.h = g_slhDsaH[index]; |
| 604 | - ctx->para.hp = g_slhDsaHp[algId]; | 614 | + ctx->para.d = g_slhDsaD[index]; |
| 605 | - ctx->para.a = g_slhDsaA[algId]; | 615 | + ctx->para.hp = g_slhDsaHp[index]; |
| 606 | - ctx->para.k = g_slhDsaK[algId]; | 616 | + ctx->para.a = g_slhDsaA[index]; |
| 607 | - ctx->para.m = g_slhDsaM[algId]; | 617 | + ctx->para.k = g_slhDsaK[index]; |
| 608 | - ctx->para.pkBytes = g_slhDsaPkBytes[algId]; | 618 | + ctx->para.m = g_slhDsaM[index]; |
| 609 | - ctx->para.sigBytes = g_slhDsaSigBytes[algId]; | 619 | + ctx->para.pkBytes = g_slhDsaPkBytes[index]; |
| 610 | - ctx->para.secCategory = g_secCategory[algId]; | 620 | + ctx->para.sigBytes = g_slhDsaSigBytes[index]; |
| 621 | + ctx->para.secCategory = g_secCategory[index]; | ||
| 611 | SlhDsaInitHashFuncs(ctx); | 622 | SlhDsaInitHashFuncs(ctx); |
| 612 | if (ctx->para.isCompressed) { | 623 | if (ctx->para.isCompressed) { |
| 613 | ctx->adrsOps = g_adrsOps[1]; | 624 | ctx->adrsOps = g_adrsOps[1]; |
| @@ -624,12 +635,12 @@ int32_t CRYPT_SLH_DSA_Ctrl(CryptSlhDsaCtx *ctx, int32_t opt, void *val, uint32_t | |||
| 624 | } | 635 | } |
| 625 | switch (opt) { | 636 | switch (opt) { |
| 626 | case CRYPT_CTRL_SET_PARA_BY_ID: | 637 | case CRYPT_CTRL_SET_PARA_BY_ID: |
| 627 | - if (val == NULL || len != sizeof(CRYPT_SLH_DSA_AlgId)) { | 638 | + if (val == NULL || len != sizeof(CRYPT_PKEY_ParaId)) { |
| 628 | BSL_ERR_PUSH_ERROR(CRYPT_INVALID_ARG); | 639 | BSL_ERR_PUSH_ERROR(CRYPT_INVALID_ARG); |
| 629 | return CRYPT_INVALID_ARG; | 640 | return CRYPT_INVALID_ARG; |
| 630 | } | 641 | } |
| 631 | - CRYPT_SLH_DSA_AlgId algId = *(CRYPT_SLH_DSA_AlgId *)val; | 642 | + CRYPT_PKEY_ParaId algId = *(CRYPT_PKEY_ParaId *)val; |
| 632 | - if (algId >= CRYPT_SLH_DSA_ALG_ID_MAX) { | 643 | + if (CheckNotSlhDsaAlgId(algId)) { |
| 633 | BSL_ERR_PUSH_ERROR(CRYPT_SLHDSA_ERR_INVALID_ALGID); | 644 | BSL_ERR_PUSH_ERROR(CRYPT_SLHDSA_ERR_INVALID_ALGID); |
| 634 | return CRYPT_SLHDSA_ERR_INVALID_ALGID; | 645 | return CRYPT_SLHDSA_ERR_INVALID_ALGID; |
| 635 | } | 646 | } |
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "securec.h" | 19 | #include "securec.h" |
| 20 | #include "bsl_err_internal.h" | 20 | #include "bsl_err_internal.h" |
| 21 | #include "crypt_errno.h" | 21 | #include "crypt_errno.h" |
| 22 | +#include "crypt_algid.h" | ||
| 22 | #include "crypt_types.h" | 23 | #include "crypt_types.h" |
| 23 | #include "crypt_eal_md.h" | 24 | #include "crypt_eal_md.h" |
| 24 | #include "crypt_eal_mac.h" | 25 | #include "crypt_eal_mac.h" |
| @@ -215,7 +216,7 @@ static int32_t TlSha512(const CryptSlhDsaCtx *ctx, const SlhDsaAdrs *adrs, const | |||
| 215 | 216 | ||
| 216 | void SlhDsaInitHashFuncs(CryptSlhDsaCtx *ctx) | 217 | void SlhDsaInitHashFuncs(CryptSlhDsaCtx *ctx) |
| 217 | { | 218 | { |
| 218 | - CRYPT_SLH_DSA_AlgId algId = ctx->para.algId; | 219 | + CRYPT_PKEY_ParaId algId = ctx->para.algId; |
| 219 | SlhDsaHashFuncs *hashFuncs = &ctx->hashFuncs; | 220 | SlhDsaHashFuncs *hashFuncs = &ctx->hashFuncs; |
| 220 | if (algId == CRYPT_SLH_DSA_SHA2_128S || algId == CRYPT_SLH_DSA_SHA2_128F || algId == CRYPT_SLH_DSA_SHA2_192S || | 221 | if (algId == CRYPT_SLH_DSA_SHA2_128S || algId == CRYPT_SLH_DSA_SHA2_128F || algId == CRYPT_SLH_DSA_SHA2_192S || |
| 221 | algId == CRYPT_SLH_DSA_SHA2_192F || algId == CRYPT_SLH_DSA_SHA2_256S || algId == CRYPT_SLH_DSA_SHA2_256F) { | 222 | algId == CRYPT_SLH_DSA_SHA2_192F || algId == CRYPT_SLH_DSA_SHA2_256S || algId == CRYPT_SLH_DSA_SHA2_256F) { |
| @@ -112,7 +112,7 @@ typedef struct { | |||
| 112 | void BaseB(const uint8_t *x, uint32_t xLen, uint32_t b, uint32_t *out, uint32_t outLen); | 112 | void BaseB(const uint8_t *x, uint32_t xLen, uint32_t b, uint32_t *out, uint32_t outLen); |
| 113 | 113 | ||
| 114 | typedef struct { | 114 | typedef struct { |
| 115 | - CRYPT_SLH_DSA_AlgId algId; | 115 | + int algId; // CRYPT_PKEY_ParaId (SLH_DSA_AlgId or XMSS_AlgId) |
| 116 | bool isCompressed; | 116 | bool isCompressed; |
| 117 | uint32_t n; | 117 | uint32_t n; |
| 118 | uint32_t h; | 118 | uint32_t h; |
| @@ -166,7 +166,7 @@ typedef enum { | |||
| 166 | BSL_CID_PKCS = 119, /* identifies PKCS */ | 166 | BSL_CID_PKCS = 119, /* identifies PKCS */ |
| 167 | BSL_CID_PKCS5 = 120, /* identifies PKCS5 */ | 167 | BSL_CID_PKCS5 = 120, /* identifies PKCS5 */ |
| 168 | BSL_CID_PBKDF2 = 121, /* identifies PBKDF2 */ | 168 | BSL_CID_PBKDF2 = 121, /* identifies PBKDF2 */ |
| 169 | - BSL_CID_PBE_MD2WITHDESCBC = 122, | 169 | + BSL_CID_PBE_MD2WITHDESCBC = 122, |
| 170 | BSL_CID_PBE_MD2WITHRC2CBC = 123, | 170 | BSL_CID_PBE_MD2WITHRC2CBC = 123, |
| 171 | BSL_CID_PBE_MD5WITHDESCBC = 124, /* identifies PBE_MD5WITHDESCBC */ | 171 | BSL_CID_PBE_MD5WITHDESCBC = 124, /* identifies PBE_MD5WITHDESCBC */ |
| 172 | BSL_CID_PBE_MD5WITHRC2CBC = 125, | 172 | BSL_CID_PBE_MD5WITHRC2CBC = 125, |
| @@ -546,6 +546,26 @@ typedef enum { | |||
| 546 | BSL_CID_ECDH_NISTP521_MLKEM768 = 2116, | 546 | BSL_CID_ECDH_NISTP521_MLKEM768 = 2116, |
| 547 | BSL_CID_ECDH_NISTP521_MLKEM1024 = 2117, | 547 | BSL_CID_ECDH_NISTP521_MLKEM1024 = 2117, |
| 548 | 548 | ||
| 549 | + BSL_CID_ML_DSA_44 = 2120, | ||
| 550 | + BSL_CID_ML_DSA_65 = 2121, | ||
| 551 | + BSL_CID_ML_DSA_87 = 2122, | ||
| 552 | + BSL_CID_ML_KEM_512 = 2123, | ||
| 553 | + BSL_CID_ML_KEM_768 = 2124, | ||
| 554 | + BSL_CID_ML_KEM_1024 = 2125, | ||
| 555 | + | ||
| 556 | + BSL_CID_SLH_DSA_SHA2_128S = 2126, | ||
| 557 | + BSL_CID_SLH_DSA_SHAKE_128S = 2127, | ||
| 558 | + BSL_CID_SLH_DSA_SHA2_128F = 2128, | ||
| 559 | + BSL_CID_SLH_DSA_SHAKE_128F = 2129, | ||
| 560 | + BSL_CID_SLH_DSA_SHA2_192S = 2130, | ||
| 561 | + BSL_CID_SLH_DSA_SHAKE_192S = 2131, | ||
| 562 | + BSL_CID_SLH_DSA_SHA2_192F = 2132, | ||
| 563 | + BSL_CID_SLH_DSA_SHAKE_192F = 2133, | ||
| 564 | + BSL_CID_SLH_DSA_SHA2_256S = 2134, | ||
| 565 | + BSL_CID_SLH_DSA_SHAKE_256S = 2135, | ||
| 566 | + BSL_CID_SLH_DSA_SHA2_256F = 2136, | ||
| 567 | + BSL_CID_SLH_DSA_SHAKE_256F = 2137, | ||
| 568 | + | ||
| 549 | BSL_CID_SM9 = 5201, | 569 | BSL_CID_SM9 = 5201, |
| 550 | BSL_CID_ECC_SM9 = 5202, | 570 | BSL_CID_ECC_SM9 = 5202, |
| 551 | BSL_CID_PAILLIER = 5203, | 571 | BSL_CID_PAILLIER = 5203, |
| @@ -225,6 +225,24 @@ typedef enum { | |||
| 225 | CRYPT_HYBRID_ECDH_NISTP521_MLKEM512 = BSL_CID_ECDH_NISTP521_MLKEM512, | 225 | CRYPT_HYBRID_ECDH_NISTP521_MLKEM512 = BSL_CID_ECDH_NISTP521_MLKEM512, |
| 226 | CRYPT_HYBRID_ECDH_NISTP521_MLKEM768 = BSL_CID_ECDH_NISTP521_MLKEM768, | 226 | CRYPT_HYBRID_ECDH_NISTP521_MLKEM768 = BSL_CID_ECDH_NISTP521_MLKEM768, |
| 227 | CRYPT_HYBRID_ECDH_NISTP521_MLKEM1024 = BSL_CID_ECDH_NISTP521_MLKEM1024, | 227 | CRYPT_HYBRID_ECDH_NISTP521_MLKEM1024 = BSL_CID_ECDH_NISTP521_MLKEM1024, |
| 228 | + CRYPT_MLDSA_TYPE_MLDSA_44 = BSL_CID_ML_DSA_44, | ||
| 229 | + CRYPT_MLDSA_TYPE_MLDSA_65 = BSL_CID_ML_DSA_65, | ||
| 230 | + CRYPT_MLDSA_TYPE_MLDSA_87 = BSL_CID_ML_DSA_87, | ||
| 231 | + CRYPT_KEM_TYPE_MLKEM_512 = BSL_CID_ML_KEM_512, | ||
| 232 | + CRYPT_KEM_TYPE_MLKEM_768 = BSL_CID_ML_KEM_768, | ||
| 233 | + CRYPT_KEM_TYPE_MLKEM_1024 = BSL_CID_ML_KEM_1024, | ||
| 234 | + CRYPT_SLH_DSA_SHA2_128S = BSL_CID_SLH_DSA_SHA2_128S, | ||
| 235 | + CRYPT_SLH_DSA_SHAKE_128S = BSL_CID_SLH_DSA_SHAKE_128S, | ||
| 236 | + CRYPT_SLH_DSA_SHA2_128F = BSL_CID_SLH_DSA_SHA2_128F, | ||
| 237 | + CRYPT_SLH_DSA_SHAKE_128F = BSL_CID_SLH_DSA_SHAKE_128F, | ||
| 238 | + CRYPT_SLH_DSA_SHA2_192S = BSL_CID_SLH_DSA_SHA2_192S, | ||
| 239 | + CRYPT_SLH_DSA_SHAKE_192S = BSL_CID_SLH_DSA_SHAKE_192S, | ||
| 240 | + CRYPT_SLH_DSA_SHA2_192F = BSL_CID_SLH_DSA_SHA2_192F, | ||
| 241 | + CRYPT_SLH_DSA_SHAKE_192F = BSL_CID_SLH_DSA_SHAKE_192F, | ||
| 242 | + CRYPT_SLH_DSA_SHA2_256S = BSL_CID_SLH_DSA_SHA2_256S, | ||
| 243 | + CRYPT_SLH_DSA_SHAKE_256S = BSL_CID_SLH_DSA_SHAKE_256S, | ||
| 244 | + CRYPT_SLH_DSA_SHA2_256F = BSL_CID_SLH_DSA_SHA2_256F, | ||
| 245 | + CRYPT_SLH_DSA_SHAKE_256F = BSL_CID_SLH_DSA_SHAKE_256F, | ||
| 228 | CRYPT_PKEY_PARAID_MAX = BSL_CID_UNKNOWN | 246 | CRYPT_PKEY_PARAID_MAX = BSL_CID_UNKNOWN |
| 229 | } CRYPT_PKEY_ParaId; | 247 | } CRYPT_PKEY_ParaId; |
| 230 | 248 | ||
| @@ -856,39 +856,6 @@ typedef struct { | |||
| 856 | 856 | ||
| 857 | typedef struct EAL_LibCtx CRYPT_EAL_LibCtx; | 857 | typedef struct EAL_LibCtx CRYPT_EAL_LibCtx; |
| 858 | 858 | ||
| 859 | -/* Optional parameter set for MLDSA */ | ||
| 860 | -typedef enum { | ||
| 861 | - CRYPT_MLDSA_TYPE_MLDSA_44 = 0x01, // MLDSA-44 | ||
| 862 | - CRYPT_MLDSA_TYPE_MLDSA_65 = 0x02, // MLDSA-65 | ||
| 863 | - CRYPT_MLDSA_TYPE_MLDSA_87 = 0x03, // MLDSA-87 | ||
| 864 | - CRYPT_MLDSA_TYPE_INVALID = 0x7fffffff // invalid value | ||
| 865 | -} CRYPT_MLDSA_KeyType; | ||
| 866 | - | ||
| 867 | -/* Optional parameter set for MLKEM */ | ||
| 868 | -typedef enum { | ||
| 869 | - CRYPT_KEM_TYPE_MLKEM_512 = 0x01, // MLKEM512 | ||
| 870 | - CRYPT_KEM_TYPE_MLKEM_768 = 0x02, // MLKEM768 | ||
| 871 | - CRYPT_KEM_TYPE_MLKEM_1024 = 0x03, // MLKEM1024 | ||
| 872 | - CRYPT_KEM_TYPE_INVALID = 0x7fffffff // invalid value | ||
| 873 | -} CRYPT_MLKEM_KeyType; | ||
| 874 | - | ||
| 875 | -/* Optional parameter set for SLHDSA */ | ||
| 876 | -typedef enum { | ||
| 877 | - CRYPT_SLH_DSA_SHA2_128S, | ||
| 878 | - CRYPT_SLH_DSA_SHAKE_128S, | ||
| 879 | - CRYPT_SLH_DSA_SHA2_128F, | ||
| 880 | - CRYPT_SLH_DSA_SHAKE_128F, | ||
| 881 | - CRYPT_SLH_DSA_SHA2_192S, | ||
| 882 | - CRYPT_SLH_DSA_SHAKE_192S, | ||
| 883 | - CRYPT_SLH_DSA_SHA2_192F, | ||
| 884 | - CRYPT_SLH_DSA_SHAKE_192F, | ||
| 885 | - CRYPT_SLH_DSA_SHA2_256S, | ||
| 886 | - CRYPT_SLH_DSA_SHAKE_256S, | ||
| 887 | - CRYPT_SLH_DSA_SHA2_256F, | ||
| 888 | - CRYPT_SLH_DSA_SHAKE_256F, | ||
| 889 | - CRYPT_SLH_DSA_ALG_ID_MAX, | ||
| 890 | -} CRYPT_SLH_DSA_AlgId; | ||
| 891 | - | ||
| 892 | #ifdef __cplusplus | 859 | #ifdef __cplusplus |
| 893 | } | 860 | } |
| 894 | #endif // __cplusplus | 861 | #endif // __cplusplus |
| @@ -16,6 +16,7 @@ | |||
| 16 | /* BEGIN_HEADER */ | 16 | /* BEGIN_HEADER */ |
| 17 | #include "bsl_sal.h" | 17 | #include "bsl_sal.h" |
| 18 | #include "crypt_errno.h" | 18 | #include "crypt_errno.h" |
| 19 | +#include "crypt_algid.h" | ||
| 19 | #include "crypt_eal_pkey.h" | 20 | #include "crypt_eal_pkey.h" |
| 20 | #include "crypt_util_rand.h" | 21 | #include "crypt_util_rand.h" |
| 21 | #include "eal_pkey_local.h" | 22 | #include "eal_pkey_local.h" |
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "bsl_err.h" | 21 | #include "bsl_err.h" |
| 22 | #include "bsl_sal.h" | 22 | #include "bsl_sal.h" |
| 23 | #include "crypt_errno.h" | 23 | #include "crypt_errno.h" |
| 24 | +#include "crypt_algid.h" | ||
| 24 | #include "crypt_eal_pkey.h" | 25 | #include "crypt_eal_pkey.h" |
| 25 | #include "crypt_util_rand.h" | 26 | #include "crypt_util_rand.h" |
| 26 | #include "crypt_bn.h" | 27 | #include "crypt_bn.h" |
| @@ -111,7 +112,7 @@ void SDV_CRYPTO_SLH_DSA_GENKEY_TC001(int isProvider) | |||
| 111 | ASSERT_TRUE(pkey != NULL); | 112 | ASSERT_TRUE(pkey != NULL); |
| 112 | ASSERT_TRUE(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_PARA_BY_ID, NULL, 0) == CRYPT_INVALID_ARG); | 113 | ASSERT_TRUE(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_PARA_BY_ID, NULL, 0) == CRYPT_INVALID_ARG); |
| 113 | ASSERT_TRUE(CRYPT_EAL_PkeyGen(pkey) == CRYPT_SLHDSA_ERR_INVALID_ALGID); | 114 | ASSERT_TRUE(CRYPT_EAL_PkeyGen(pkey) == CRYPT_SLHDSA_ERR_INVALID_ALGID); |
| 114 | - CRYPT_SLH_DSA_AlgId algId = CRYPT_SLH_DSA_SHA2_128S; | 115 | + CRYPT_PKEY_ParaId algId = CRYPT_SLH_DSA_SHA2_128S; |
| 115 | ASSERT_TRUE(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_PARA_BY_ID, (void *)&algId, sizeof(algId)) == | 116 | ASSERT_TRUE(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_PARA_BY_ID, (void *)&algId, sizeof(algId)) == |
| 116 | CRYPT_SUCCESS); | 117 | CRYPT_SUCCESS); |
| 117 | ASSERT_TRUE(CRYPT_EAL_PkeyGen(pkey) == CRYPT_SUCCESS); | 118 | ASSERT_TRUE(CRYPT_EAL_PkeyGen(pkey) == CRYPT_SUCCESS); |