ml_dsa_params.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stddef.h>
  10. #include <string.h>
  11. #include <openssl/evp.h>
  12. #include "ml_dsa_local.h"
  13. /* See FIPS 204 Section 4 Table 1 & Table 2 */
  14. #define ML_DSA_44_TAU 39
  15. #define ML_DSA_44_LAMBDA 128
  16. #define ML_DSA_44_K 4
  17. #define ML_DSA_44_L 4
  18. #define ML_DSA_44_ETA ML_DSA_ETA_2
  19. #define ML_DSA_44_BETA 78
  20. #define ML_DSA_44_OMEGA 80
  21. #define ML_DSA_44_SECURITY_CATEGORY 2
  22. /* See FIPS 204 Section 4 Table 1 & Table 2 */
  23. #define ML_DSA_65_TAU 49
  24. #define ML_DSA_65_LAMBDA 192
  25. #define ML_DSA_65_K 6
  26. #define ML_DSA_65_L 5
  27. #define ML_DSA_65_ETA ML_DSA_ETA_4
  28. #define ML_DSA_65_BETA 196
  29. #define ML_DSA_65_OMEGA 55
  30. #define ML_DSA_65_SECURITY_CATEGORY 3
  31. /* See FIPS 204 Section 4 Table 1 & Table 2 */
  32. #define ML_DSA_87_TAU 60
  33. #define ML_DSA_87_LAMBDA 256
  34. #define ML_DSA_87_K 8
  35. #define ML_DSA_87_L 7
  36. #define ML_DSA_87_ETA ML_DSA_ETA_2
  37. #define ML_DSA_87_BETA 120
  38. #define ML_DSA_87_OMEGA 75
  39. #define ML_DSA_87_SECURITY_CATEGORY 5
  40. static const ML_DSA_PARAMS ml_dsa_params[] = {
  41. { "ML-DSA-44",
  42. EVP_PKEY_ML_DSA_44,
  43. ML_DSA_44_TAU,
  44. ML_DSA_44_LAMBDA,
  45. ML_DSA_GAMMA1_TWO_POWER_17,
  46. ML_DSA_GAMMA2_Q_MINUS1_DIV88,
  47. ML_DSA_44_K,
  48. ML_DSA_44_L,
  49. ML_DSA_44_ETA,
  50. ML_DSA_44_BETA,
  51. ML_DSA_44_OMEGA,
  52. ML_DSA_44_SECURITY_CATEGORY,
  53. ML_DSA_44_PRIV_LEN,
  54. ML_DSA_44_PUB_LEN,
  55. ML_DSA_44_SIG_LEN
  56. },
  57. { "ML-DSA-65",
  58. EVP_PKEY_ML_DSA_65,
  59. ML_DSA_65_TAU,
  60. ML_DSA_65_LAMBDA,
  61. ML_DSA_GAMMA1_TWO_POWER_19,
  62. ML_DSA_GAMMA2_Q_MINUS1_DIV32,
  63. ML_DSA_65_K,
  64. ML_DSA_65_L,
  65. ML_DSA_65_ETA,
  66. ML_DSA_65_BETA,
  67. ML_DSA_65_OMEGA,
  68. ML_DSA_65_SECURITY_CATEGORY,
  69. ML_DSA_65_PRIV_LEN,
  70. ML_DSA_65_PUB_LEN,
  71. ML_DSA_65_SIG_LEN
  72. },
  73. { "ML-DSA-87",
  74. EVP_PKEY_ML_DSA_87,
  75. ML_DSA_87_TAU,
  76. ML_DSA_87_LAMBDA,
  77. ML_DSA_GAMMA1_TWO_POWER_19,
  78. ML_DSA_GAMMA2_Q_MINUS1_DIV32,
  79. ML_DSA_87_K,
  80. ML_DSA_87_L,
  81. ML_DSA_87_ETA,
  82. ML_DSA_87_BETA,
  83. ML_DSA_87_OMEGA,
  84. ML_DSA_87_SECURITY_CATEGORY,
  85. ML_DSA_87_PRIV_LEN,
  86. ML_DSA_87_PUB_LEN,
  87. ML_DSA_87_SIG_LEN
  88. },
  89. {NULL},
  90. };
  91. /**
  92. * @brief A getter to convert an algorithm name into a ML_DSA_PARAMS object
  93. */
  94. const ML_DSA_PARAMS *ossl_ml_dsa_params_get(int evp_type)
  95. {
  96. const ML_DSA_PARAMS *p;
  97. for (p = ml_dsa_params; p->alg != NULL; ++p) {
  98. if (p->evp_type == evp_type)
  99. return p;
  100. }
  101. return NULL;
  102. }