2
0

paramnames.pm 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #! /usr/bin/env perl
  2. # Copyright 2023 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. package OpenSSL::paramnames;
  9. use strict;
  10. use warnings;
  11. require Exporter;
  12. our @ISA = qw(Exporter);
  13. our @EXPORT_OK = qw(generate_public_macros
  14. generate_internal_macros
  15. produce_decoder);
  16. my $case_sensitive = 1;
  17. my %params = (
  18. # Well known parameter names that core passes to providers
  19. 'PROV_PARAM_CORE_VERSION' => "openssl-version",# utf8_ptr
  20. 'PROV_PARAM_CORE_PROV_NAME' => "provider-name", # utf8_ptr
  21. 'PROV_PARAM_CORE_MODULE_FILENAME' => "module-filename",# utf8_ptr
  22. # Well known parameter names that Providers can define
  23. 'PROV_PARAM_NAME' => "name", # utf8_ptr
  24. 'PROV_PARAM_VERSION' => "version", # utf8_ptr
  25. 'PROV_PARAM_BUILDINFO' => "buildinfo", # utf8_ptr
  26. 'PROV_PARAM_STATUS' => "status", # uint
  27. 'PROV_PARAM_SECURITY_CHECKS' => "security-checks", # uint
  28. 'PROV_PARAM_TLS1_PRF_EMS_CHECK' => "tls1-prf-ems-check", # uint
  29. 'PROV_PARAM_DRBG_TRUNC_DIGEST' => "drbg-no-trunc-md", # uint
  30. # Self test callback parameters
  31. 'PROV_PARAM_SELF_TEST_PHASE' => "st-phase",# utf8_string
  32. 'PROV_PARAM_SELF_TEST_TYPE' => "st-type", # utf8_string
  33. 'PROV_PARAM_SELF_TEST_DESC' => "st-desc", # utf8_string
  34. # Provider-native object abstractions
  35. #
  36. # These are used when a provider wants to pass object data or an object
  37. # reference back to libcrypto. This is only useful for provider functions
  38. # that take a callback to which an PARAM array with these parameters
  39. # can be passed.
  40. #
  41. # This set of parameter names is explained in detail in provider-object(7)
  42. # (doc/man7/provider-object.pod)
  43. 'OBJECT_PARAM_TYPE' => "type", # INTEGER
  44. 'OBJECT_PARAM_DATA_TYPE' => "data-type",# UTF8_STRING
  45. 'OBJECT_PARAM_DATA_STRUCTURE' => "data-structure",# UTF8_STRING
  46. 'OBJECT_PARAM_REFERENCE' => "reference",# OCTET_STRING
  47. 'OBJECT_PARAM_DATA' => "data",# OCTET_STRING or UTF8_STRING
  48. 'OBJECT_PARAM_DESC' => "desc", # UTF8_STRING
  49. # Algorithm parameters
  50. # If "engine",or "properties",are specified, they should always be paired
  51. # with the algorithm type.
  52. # Note these are common names that are shared by many types (such as kdf, mac,
  53. # and pkey) e.g: see MAC_PARAM_DIGEST below.
  54. 'ALG_PARAM_DIGEST' => "digest", # utf8_string
  55. 'ALG_PARAM_CIPHER' => "cipher", # utf8_string
  56. 'ALG_PARAM_ENGINE' => "engine", # utf8_string
  57. 'ALG_PARAM_MAC' => "mac", # utf8_string
  58. 'ALG_PARAM_PROPERTIES' => "properties", # utf8_string
  59. # cipher parameters
  60. 'CIPHER_PARAM_PADDING' => "padding", # uint
  61. 'CIPHER_PARAM_USE_BITS' => "use-bits", # uint
  62. 'CIPHER_PARAM_TLS_VERSION' => "tls-version", # uint
  63. 'CIPHER_PARAM_TLS_MAC' => "tls-mac", # octet_ptr
  64. 'CIPHER_PARAM_TLS_MAC_SIZE' => "tls-mac-size",# size_t
  65. 'CIPHER_PARAM_MODE' => "mode", # uint
  66. 'CIPHER_PARAM_BLOCK_SIZE' => "blocksize", # size_t
  67. 'CIPHER_PARAM_AEAD' => "aead", # int, 0 or 1
  68. 'CIPHER_PARAM_CUSTOM_IV' => "custom-iv", # int, 0 or 1
  69. 'CIPHER_PARAM_CTS' => "cts", # int, 0 or 1
  70. 'CIPHER_PARAM_TLS1_MULTIBLOCK' => "tls-multi", # int, 0 or 1
  71. 'CIPHER_PARAM_HAS_RAND_KEY' => "has-randkey", # int, 0 or 1
  72. 'CIPHER_PARAM_KEYLEN' => "keylen", # size_t
  73. 'CIPHER_PARAM_IVLEN' => "ivlen", # size_t
  74. 'CIPHER_PARAM_IV' => "iv", # octet_string OR octet_ptr
  75. 'CIPHER_PARAM_UPDATED_IV' => "updated-iv", # octet_string OR octet_ptr
  76. 'CIPHER_PARAM_NUM' => "num", # uint
  77. 'CIPHER_PARAM_ROUNDS' => "rounds", # uint
  78. 'CIPHER_PARAM_AEAD_TAG' => "tag", # octet_string
  79. 'CIPHER_PARAM_AEAD_TLS1_AAD' => "tlsaad", # octet_string
  80. 'CIPHER_PARAM_AEAD_TLS1_AAD_PAD' => "tlsaadpad", # size_t
  81. 'CIPHER_PARAM_AEAD_TLS1_IV_FIXED' => "tlsivfixed", # octet_string
  82. 'CIPHER_PARAM_AEAD_TLS1_GET_IV_GEN' => "tlsivgen", # octet_string
  83. 'CIPHER_PARAM_AEAD_TLS1_SET_IV_INV' => "tlsivinv", # octet_string
  84. 'CIPHER_PARAM_AEAD_IVLEN' => '*CIPHER_PARAM_IVLEN',
  85. 'CIPHER_PARAM_AEAD_TAGLEN' => "taglen", # size_t
  86. 'CIPHER_PARAM_AEAD_MAC_KEY' => "mackey", # octet_string
  87. 'CIPHER_PARAM_RANDOM_KEY' => "randkey", # octet_string
  88. 'CIPHER_PARAM_RC2_KEYBITS' => "keybits", # size_t
  89. 'CIPHER_PARAM_SPEED' => "speed", # uint
  90. 'CIPHER_PARAM_CTS_MODE' => "cts_mode", # utf8_string
  91. # For passing the AlgorithmIdentifier parameter in DER form
  92. 'CIPHER_PARAM_ALGORITHM_ID_PARAMS' => "alg_id_param",# octet_string
  93. 'CIPHER_PARAM_XTS_STANDARD' => "xts_standard",# utf8_string
  94. 'CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_SEND_FRAGMENT' => "tls1multi_maxsndfrag",# uint
  95. 'CIPHER_PARAM_TLS1_MULTIBLOCK_MAX_BUFSIZE' => "tls1multi_maxbufsz", # size_t
  96. 'CIPHER_PARAM_TLS1_MULTIBLOCK_INTERLEAVE' => "tls1multi_interleave",# uint
  97. 'CIPHER_PARAM_TLS1_MULTIBLOCK_AAD' => "tls1multi_aad", # octet_string
  98. 'CIPHER_PARAM_TLS1_MULTIBLOCK_AAD_PACKLEN' => "tls1multi_aadpacklen",# uint
  99. 'CIPHER_PARAM_TLS1_MULTIBLOCK_ENC' => "tls1multi_enc", # octet_string
  100. 'CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_IN' => "tls1multi_encin", # octet_string
  101. 'CIPHER_PARAM_TLS1_MULTIBLOCK_ENC_LEN' => "tls1multi_enclen", # size_t
  102. # digest parameters
  103. 'DIGEST_PARAM_XOFLEN' => "xoflen", # size_t
  104. 'DIGEST_PARAM_SSL3_MS' => "ssl3-ms", # octet string
  105. 'DIGEST_PARAM_PAD_TYPE' => "pad-type", # uint
  106. 'DIGEST_PARAM_MICALG' => "micalg", # utf8 string
  107. 'DIGEST_PARAM_BLOCK_SIZE' => "blocksize", # size_t
  108. 'DIGEST_PARAM_SIZE' => "size", # size_t
  109. 'DIGEST_PARAM_XOF' => "xof", # int, 0 or 1
  110. 'DIGEST_PARAM_ALGID_ABSENT' => "algid-absent", # int, 0 or 1
  111. # MAC parameters
  112. 'MAC_PARAM_KEY' => "key", # octet string
  113. 'MAC_PARAM_IV' => "iv", # octet string
  114. 'MAC_PARAM_CUSTOM' => "custom", # utf8 string
  115. 'MAC_PARAM_SALT' => "salt", # octet string
  116. 'MAC_PARAM_XOF' => "xof", # int, 0 or 1
  117. 'MAC_PARAM_DIGEST_NOINIT' => "digest-noinit", # int, 0 or 1
  118. 'MAC_PARAM_DIGEST_ONESHOT' => "digest-oneshot",# int, 0 or 1
  119. 'MAC_PARAM_C_ROUNDS' => "c-rounds", # unsigned int
  120. 'MAC_PARAM_D_ROUNDS' => "d-rounds", # unsigned int
  121. # If "engine",or "properties",are specified, they should always be paired
  122. # with "cipher",or "digest".
  123. 'MAC_PARAM_CIPHER' => '*ALG_PARAM_CIPHER', # utf8 string
  124. 'MAC_PARAM_DIGEST' => '*ALG_PARAM_DIGEST', # utf8 string
  125. 'MAC_PARAM_PROPERTIES' => '*ALG_PARAM_PROPERTIES', # utf8 string
  126. 'MAC_PARAM_SIZE' => "size", # size_t
  127. 'MAC_PARAM_BLOCK_SIZE' => "block-size", # size_t
  128. 'MAC_PARAM_TLS_DATA_SIZE' => "tls-data-size", # size_t
  129. # KDF / PRF parameters
  130. 'KDF_PARAM_SECRET' => "secret", # octet string
  131. 'KDF_PARAM_KEY' => "key", # octet string
  132. 'KDF_PARAM_SALT' => "salt", # octet string
  133. 'KDF_PARAM_PASSWORD' => "pass", # octet string
  134. 'KDF_PARAM_PREFIX' => "prefix", # octet string
  135. 'KDF_PARAM_LABEL' => "label", # octet string
  136. 'KDF_PARAM_DATA' => "data", # octet string
  137. 'KDF_PARAM_DIGEST' => '*ALG_PARAM_DIGEST', # utf8 string
  138. 'KDF_PARAM_CIPHER' => '*ALG_PARAM_CIPHER', # utf8 string
  139. 'KDF_PARAM_MAC' => '*ALG_PARAM_MAC', # utf8 string
  140. 'KDF_PARAM_MAC_SIZE' => "maclen", # size_t
  141. 'KDF_PARAM_PROPERTIES' => '*ALG_PARAM_PROPERTIES', # utf8 string
  142. 'KDF_PARAM_ITER' => "iter", # unsigned int
  143. 'KDF_PARAM_MODE' => "mode", # utf8 string or int
  144. 'KDF_PARAM_PKCS5' => "pkcs5", # int
  145. 'KDF_PARAM_UKM' => "ukm", # octet string
  146. 'KDF_PARAM_CEK_ALG' => "cekalg", # utf8 string
  147. 'KDF_PARAM_SCRYPT_N' => "n", # uint64_t
  148. 'KDF_PARAM_SCRYPT_R' => "r", # uint32_t
  149. 'KDF_PARAM_SCRYPT_P' => "p", # uint32_t
  150. 'KDF_PARAM_SCRYPT_MAXMEM' => "maxmem_bytes", # uint64_t
  151. 'KDF_PARAM_INFO' => "info", # octet string
  152. 'KDF_PARAM_SEED' => "seed", # octet string
  153. 'KDF_PARAM_SSHKDF_XCGHASH' => "xcghash", # octet string
  154. 'KDF_PARAM_SSHKDF_SESSION_ID' => "session_id", # octet string
  155. 'KDF_PARAM_SSHKDF_TYPE' => "type", # int
  156. 'KDF_PARAM_SIZE' => "size", # size_t
  157. 'KDF_PARAM_CONSTANT' => "constant", # octet string
  158. 'KDF_PARAM_PKCS12_ID' => "id", # int
  159. 'KDF_PARAM_KBKDF_USE_L' => "use-l", # int
  160. 'KDF_PARAM_KBKDF_USE_SEPARATOR' => "use-separator", # int
  161. 'KDF_PARAM_KBKDF_R' => "r", # int
  162. 'KDF_PARAM_X942_ACVPINFO' => "acvp-info",
  163. 'KDF_PARAM_X942_PARTYUINFO' => "partyu-info",
  164. 'KDF_PARAM_X942_PARTYVINFO' => "partyv-info",
  165. 'KDF_PARAM_X942_SUPP_PUBINFO' => "supp-pubinfo",
  166. 'KDF_PARAM_X942_SUPP_PRIVINFO' => "supp-privinfo",
  167. 'KDF_PARAM_X942_USE_KEYBITS' => "use-keybits",
  168. 'KDF_PARAM_HMACDRBG_ENTROPY' => "entropy",
  169. 'KDF_PARAM_HMACDRBG_NONCE' => "nonce",
  170. 'KDF_PARAM_THREADS' => "threads", # uint32_t
  171. 'KDF_PARAM_EARLY_CLEAN' => "early_clean", # uint32_t
  172. 'KDF_PARAM_ARGON2_AD' => "ad", # octet string
  173. 'KDF_PARAM_ARGON2_LANES' => "lanes", # uint32_t
  174. 'KDF_PARAM_ARGON2_MEMCOST' => "memcost", # uint32_t
  175. 'KDF_PARAM_ARGON2_VERSION' => "version", # uint32_t
  176. # Known RAND names
  177. 'RAND_PARAM_STATE' => "state",
  178. 'RAND_PARAM_STRENGTH' => "strength",
  179. 'RAND_PARAM_MAX_REQUEST' => "max_request",
  180. 'RAND_PARAM_TEST_ENTROPY' => "test_entropy",
  181. 'RAND_PARAM_TEST_NONCE' => "test_nonce",
  182. 'RAND_PARAM_GENERATE' => "generate",
  183. # RAND/DRBG names
  184. 'DRBG_PARAM_RESEED_REQUESTS' => "reseed_requests",
  185. 'DRBG_PARAM_RESEED_TIME_INTERVAL' => "reseed_time_interval",
  186. 'DRBG_PARAM_MIN_ENTROPYLEN' => "min_entropylen",
  187. 'DRBG_PARAM_MAX_ENTROPYLEN' => "max_entropylen",
  188. 'DRBG_PARAM_MIN_NONCELEN' => "min_noncelen",
  189. 'DRBG_PARAM_MAX_NONCELEN' => "max_noncelen",
  190. 'DRBG_PARAM_MAX_PERSLEN' => "max_perslen",
  191. 'DRBG_PARAM_MAX_ADINLEN' => "max_adinlen",
  192. 'DRBG_PARAM_RESEED_COUNTER' => "reseed_counter",
  193. 'DRBG_PARAM_RESEED_TIME' => "reseed_time",
  194. 'DRBG_PARAM_PROPERTIES' => '*ALG_PARAM_PROPERTIES',
  195. 'DRBG_PARAM_DIGEST' => '*ALG_PARAM_DIGEST',
  196. 'DRBG_PARAM_CIPHER' => '*ALG_PARAM_CIPHER',
  197. 'DRBG_PARAM_MAC' => '*ALG_PARAM_MAC',
  198. 'DRBG_PARAM_USE_DF' => "use_derivation_function",
  199. # DRBG call back parameters
  200. 'DRBG_PARAM_ENTROPY_REQUIRED' => "entropy_required",
  201. 'DRBG_PARAM_PREDICTION_RESISTANCE' => "prediction_resistance",
  202. 'DRBG_PARAM_MIN_LENGTH' => "minium_length",
  203. 'DRBG_PARAM_MAX_LENGTH' => "maxium_length",
  204. 'DRBG_PARAM_RANDOM_DATA' => "random_data",
  205. 'DRBG_PARAM_SIZE' => "size",
  206. # PKEY parameters
  207. # Common PKEY parameters
  208. 'PKEY_PARAM_BITS' => "bits",# integer
  209. 'PKEY_PARAM_MAX_SIZE' => "max-size",# integer
  210. 'PKEY_PARAM_SECURITY_BITS' => "security-bits",# integer
  211. 'PKEY_PARAM_DIGEST' => '*ALG_PARAM_DIGEST',
  212. 'PKEY_PARAM_CIPHER' => '*ALG_PARAM_CIPHER', # utf8 string
  213. 'PKEY_PARAM_ENGINE' => '*ALG_PARAM_ENGINE', # utf8 string
  214. 'PKEY_PARAM_PROPERTIES' => '*ALG_PARAM_PROPERTIES',
  215. 'PKEY_PARAM_DEFAULT_DIGEST' => "default-digest",# utf8 string
  216. 'PKEY_PARAM_MANDATORY_DIGEST' => "mandatory-digest",# utf8 string
  217. 'PKEY_PARAM_PAD_MODE' => "pad-mode",
  218. 'PKEY_PARAM_DIGEST_SIZE' => "digest-size",
  219. 'PKEY_PARAM_MASKGENFUNC' => "mgf",
  220. 'PKEY_PARAM_MGF1_DIGEST' => "mgf1-digest",
  221. 'PKEY_PARAM_MGF1_PROPERTIES' => "mgf1-properties",
  222. 'PKEY_PARAM_ENCODED_PUBLIC_KEY' => "encoded-pub-key",
  223. 'PKEY_PARAM_GROUP_NAME' => "group",
  224. 'PKEY_PARAM_DIST_ID' => "distid",
  225. 'PKEY_PARAM_PUB_KEY' => "pub",
  226. 'PKEY_PARAM_PRIV_KEY' => "priv",
  227. 'PKEY_PARAM_IMPLICIT_REJECTION' => "implicit-rejection",
  228. # Diffie-Hellman/DSA Parameters
  229. 'PKEY_PARAM_FFC_P' => "p",
  230. 'PKEY_PARAM_FFC_G' => "g",
  231. 'PKEY_PARAM_FFC_Q' => "q",
  232. 'PKEY_PARAM_FFC_GINDEX' => "gindex",
  233. 'PKEY_PARAM_FFC_PCOUNTER' => "pcounter",
  234. 'PKEY_PARAM_FFC_SEED' => "seed",
  235. 'PKEY_PARAM_FFC_COFACTOR' => "j",
  236. 'PKEY_PARAM_FFC_H' => "hindex",
  237. 'PKEY_PARAM_FFC_VALIDATE_PQ' => "validate-pq",
  238. 'PKEY_PARAM_FFC_VALIDATE_G' => "validate-g",
  239. 'PKEY_PARAM_FFC_VALIDATE_LEGACY' => "validate-legacy",
  240. # Diffie-Hellman params
  241. 'PKEY_PARAM_DH_GENERATOR' => "safeprime-generator",
  242. 'PKEY_PARAM_DH_PRIV_LEN' => "priv_len",
  243. # Elliptic Curve Domain Parameters
  244. 'PKEY_PARAM_EC_PUB_X' => "qx",
  245. 'PKEY_PARAM_EC_PUB_Y' => "qy",
  246. # Elliptic Curve Explicit Domain Parameters
  247. 'PKEY_PARAM_EC_FIELD_TYPE' => "field-type",
  248. 'PKEY_PARAM_EC_P' => "p",
  249. 'PKEY_PARAM_EC_A' => "a",
  250. 'PKEY_PARAM_EC_B' => "b",
  251. 'PKEY_PARAM_EC_GENERATOR' => "generator",
  252. 'PKEY_PARAM_EC_ORDER' => "order",
  253. 'PKEY_PARAM_EC_COFACTOR' => "cofactor",
  254. 'PKEY_PARAM_EC_SEED' => "seed",
  255. 'PKEY_PARAM_EC_CHAR2_M' => "m",
  256. 'PKEY_PARAM_EC_CHAR2_TYPE' => "basis-type",
  257. 'PKEY_PARAM_EC_CHAR2_TP_BASIS' => "tp",
  258. 'PKEY_PARAM_EC_CHAR2_PP_K1' => "k1",
  259. 'PKEY_PARAM_EC_CHAR2_PP_K2' => "k2",
  260. 'PKEY_PARAM_EC_CHAR2_PP_K3' => "k3",
  261. 'PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS' => "decoded-from-explicit",
  262. # Elliptic Curve Key Parameters
  263. 'PKEY_PARAM_USE_COFACTOR_FLAG' => "use-cofactor-flag",
  264. 'PKEY_PARAM_USE_COFACTOR_ECDH' => '*PKEY_PARAM_USE_COFACTOR_FLAG',
  265. # RSA Keys
  266. #
  267. # n, e, d are the usual public and private key components
  268. #
  269. # rsa-num is the number of factors, including p and q
  270. # rsa-factor is used for each factor: p, q, r_i (i = 3, ...)
  271. # rsa-exponent is used for each exponent: dP, dQ, d_i (i = 3, ...)
  272. # rsa-coefficient is used for each coefficient: qInv, t_i (i = 3, ...)
  273. #
  274. # The number of rsa-factor items must be equal to the number of rsa-exponent
  275. # items, and the number of rsa-coefficients must be one less.
  276. # (the base i for the coefficients is 2, not 1, at least as implied by
  277. # RFC 8017)
  278. 'PKEY_PARAM_RSA_N' => "n",
  279. 'PKEY_PARAM_RSA_E' => "e",
  280. 'PKEY_PARAM_RSA_D' => "d",
  281. 'PKEY_PARAM_RSA_FACTOR' => "rsa-factor",
  282. 'PKEY_PARAM_RSA_EXPONENT' => "rsa-exponent",
  283. 'PKEY_PARAM_RSA_COEFFICIENT' => "rsa-coefficient",
  284. 'PKEY_PARAM_RSA_FACTOR1' => "rsa-factor1",
  285. 'PKEY_PARAM_RSA_FACTOR2' => "rsa-factor2",
  286. 'PKEY_PARAM_RSA_FACTOR3' => "rsa-factor3",
  287. 'PKEY_PARAM_RSA_FACTOR4' => "rsa-factor4",
  288. 'PKEY_PARAM_RSA_FACTOR5' => "rsa-factor5",
  289. 'PKEY_PARAM_RSA_FACTOR6' => "rsa-factor6",
  290. 'PKEY_PARAM_RSA_FACTOR7' => "rsa-factor7",
  291. 'PKEY_PARAM_RSA_FACTOR8' => "rsa-factor8",
  292. 'PKEY_PARAM_RSA_FACTOR9' => "rsa-factor9",
  293. 'PKEY_PARAM_RSA_FACTOR10' => "rsa-factor10",
  294. 'PKEY_PARAM_RSA_EXPONENT1' => "rsa-exponent1",
  295. 'PKEY_PARAM_RSA_EXPONENT2' => "rsa-exponent2",
  296. 'PKEY_PARAM_RSA_EXPONENT3' => "rsa-exponent3",
  297. 'PKEY_PARAM_RSA_EXPONENT4' => "rsa-exponent4",
  298. 'PKEY_PARAM_RSA_EXPONENT5' => "rsa-exponent5",
  299. 'PKEY_PARAM_RSA_EXPONENT6' => "rsa-exponent6",
  300. 'PKEY_PARAM_RSA_EXPONENT7' => "rsa-exponent7",
  301. 'PKEY_PARAM_RSA_EXPONENT8' => "rsa-exponent8",
  302. 'PKEY_PARAM_RSA_EXPONENT9' => "rsa-exponent9",
  303. 'PKEY_PARAM_RSA_EXPONENT10' => "rsa-exponent10",
  304. 'PKEY_PARAM_RSA_COEFFICIENT1' => "rsa-coefficient1",
  305. 'PKEY_PARAM_RSA_COEFFICIENT2' => "rsa-coefficient2",
  306. 'PKEY_PARAM_RSA_COEFFICIENT3' => "rsa-coefficient3",
  307. 'PKEY_PARAM_RSA_COEFFICIENT4' => "rsa-coefficient4",
  308. 'PKEY_PARAM_RSA_COEFFICIENT5' => "rsa-coefficient5",
  309. 'PKEY_PARAM_RSA_COEFFICIENT6' => "rsa-coefficient6",
  310. 'PKEY_PARAM_RSA_COEFFICIENT7' => "rsa-coefficient7",
  311. 'PKEY_PARAM_RSA_COEFFICIENT8' => "rsa-coefficient8",
  312. 'PKEY_PARAM_RSA_COEFFICIENT9' => "rsa-coefficient9",
  313. # Key generation parameters
  314. 'PKEY_PARAM_RSA_BITS' => '*PKEY_PARAM_BITS',
  315. 'PKEY_PARAM_RSA_PRIMES' => "primes",
  316. 'PKEY_PARAM_RSA_DIGEST' => '*PKEY_PARAM_DIGEST',
  317. 'PKEY_PARAM_RSA_DIGEST_PROPS' => '*PKEY_PARAM_PROPERTIES',
  318. 'PKEY_PARAM_RSA_MASKGENFUNC' => '*PKEY_PARAM_MASKGENFUNC',
  319. 'PKEY_PARAM_RSA_MGF1_DIGEST' => '*PKEY_PARAM_MGF1_DIGEST',
  320. 'PKEY_PARAM_RSA_PSS_SALTLEN' => "saltlen",
  321. # EC, X25519 and X448 Key generation parameters
  322. 'PKEY_PARAM_DHKEM_IKM' => "dhkem-ikm",
  323. # Key generation parameters
  324. 'PKEY_PARAM_FFC_TYPE' => "type",
  325. 'PKEY_PARAM_FFC_PBITS' => "pbits",
  326. 'PKEY_PARAM_FFC_QBITS' => "qbits",
  327. 'PKEY_PARAM_FFC_DIGEST' => '*PKEY_PARAM_DIGEST',
  328. 'PKEY_PARAM_FFC_DIGEST_PROPS' => '*PKEY_PARAM_PROPERTIES',
  329. 'PKEY_PARAM_EC_ENCODING' => "encoding",# utf8_string
  330. 'PKEY_PARAM_EC_POINT_CONVERSION_FORMAT' => "point-format",
  331. 'PKEY_PARAM_EC_GROUP_CHECK_TYPE' => "group-check",
  332. 'PKEY_PARAM_EC_INCLUDE_PUBLIC' => "include-public",
  333. # Key Exchange parameters
  334. 'EXCHANGE_PARAM_PAD' => "pad",# uint
  335. 'EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE' => "ecdh-cofactor-mode",# int
  336. 'EXCHANGE_PARAM_KDF_TYPE' => "kdf-type",# utf8_string
  337. 'EXCHANGE_PARAM_KDF_DIGEST' => "kdf-digest",# utf8_string
  338. 'EXCHANGE_PARAM_KDF_DIGEST_PROPS' => "kdf-digest-props",# utf8_string
  339. 'EXCHANGE_PARAM_KDF_OUTLEN' => "kdf-outlen",# size_t
  340. # The following parameter is an octet_string on set and an octet_ptr on get
  341. 'EXCHANGE_PARAM_KDF_UKM' => "kdf-ukm",
  342. # Signature parameters
  343. 'SIGNATURE_PARAM_ALGORITHM_ID' => "algorithm-id",
  344. 'SIGNATURE_PARAM_PAD_MODE' => '*PKEY_PARAM_PAD_MODE',
  345. 'SIGNATURE_PARAM_DIGEST' => '*PKEY_PARAM_DIGEST',
  346. 'SIGNATURE_PARAM_PROPERTIES' => '*PKEY_PARAM_PROPERTIES',
  347. 'SIGNATURE_PARAM_PSS_SALTLEN' => "saltlen",
  348. 'SIGNATURE_PARAM_MGF1_DIGEST' => '*PKEY_PARAM_MGF1_DIGEST',
  349. 'SIGNATURE_PARAM_MGF1_PROPERTIES' => '*PKEY_PARAM_MGF1_PROPERTIES',
  350. 'SIGNATURE_PARAM_DIGEST_SIZE' => '*PKEY_PARAM_DIGEST_SIZE',
  351. 'SIGNATURE_PARAM_NONCE_TYPE' => "nonce-type",
  352. 'SIGNATURE_PARAM_INSTANCE' => "instance",
  353. 'SIGNATURE_PARAM_CONTEXT_STRING' => "context-string",
  354. # Asym cipher parameters
  355. 'ASYM_CIPHER_PARAM_DIGEST' => '*PKEY_PARAM_DIGEST',
  356. 'ASYM_CIPHER_PARAM_PROPERTIES' => '*PKEY_PARAM_PROPERTIES',
  357. 'ASYM_CIPHER_PARAM_ENGINE' => '*PKEY_PARAM_ENGINE',
  358. 'ASYM_CIPHER_PARAM_PAD_MODE' => '*PKEY_PARAM_PAD_MODE',
  359. 'ASYM_CIPHER_PARAM_MGF1_DIGEST' => '*PKEY_PARAM_MGF1_DIGEST',
  360. 'ASYM_CIPHER_PARAM_MGF1_DIGEST_PROPS' => '*PKEY_PARAM_MGF1_PROPERTIES',
  361. 'ASYM_CIPHER_PARAM_OAEP_DIGEST' => '*ALG_PARAM_DIGEST',
  362. 'ASYM_CIPHER_PARAM_OAEP_DIGEST_PROPS' => "digest-props",
  363. # The following parameter is an octet_string on set and an octet_ptr on get
  364. 'ASYM_CIPHER_PARAM_OAEP_LABEL' => "oaep-label",
  365. 'ASYM_CIPHER_PARAM_TLS_CLIENT_VERSION' => "tls-client-version",
  366. 'ASYM_CIPHER_PARAM_TLS_NEGOTIATED_VERSION' => "tls-negotiated-version",
  367. 'ASYM_CIPHER_PARAM_IMPLICIT_REJECTION' => "implicit-rejection",
  368. # Encoder / decoder parameters
  369. 'ENCODER_PARAM_CIPHER' => '*ALG_PARAM_CIPHER',
  370. 'ENCODER_PARAM_PROPERTIES' => '*ALG_PARAM_PROPERTIES',
  371. # Currently PVK only, but reusable for others as needed
  372. 'ENCODER_PARAM_ENCRYPT_LEVEL' => "encrypt-level",
  373. 'ENCODER_PARAM_SAVE_PARAMETERS' => "save-parameters",# integer
  374. 'DECODER_PARAM_PROPERTIES' => '*ALG_PARAM_PROPERTIES',
  375. # Passphrase callback parameters
  376. 'PASSPHRASE_PARAM_INFO' => "info",
  377. # Keygen callback parameters, from provider to libcrypto
  378. 'GEN_PARAM_POTENTIAL' => "potential",# integer
  379. 'GEN_PARAM_ITERATION' => "iteration",# integer
  380. # ACVP Test parameters : These should not be used normally
  381. 'PKEY_PARAM_RSA_TEST_XP1' => "xp1",
  382. 'PKEY_PARAM_RSA_TEST_XP2' => "xp2",
  383. 'PKEY_PARAM_RSA_TEST_XP' => "xp",
  384. 'PKEY_PARAM_RSA_TEST_XQ1' => "xq1",
  385. 'PKEY_PARAM_RSA_TEST_XQ2' => "xq2",
  386. 'PKEY_PARAM_RSA_TEST_XQ' => "xq",
  387. 'PKEY_PARAM_RSA_TEST_P1' => "p1",
  388. 'PKEY_PARAM_RSA_TEST_P2' => "p2",
  389. 'PKEY_PARAM_RSA_TEST_Q1' => "q1",
  390. 'PKEY_PARAM_RSA_TEST_Q2' => "q2",
  391. 'SIGNATURE_PARAM_KAT' => "kat",
  392. # KEM parameters
  393. 'KEM_PARAM_OPERATION' => "operation",
  394. 'KEM_PARAM_IKME' => "ikme",
  395. # Capabilities
  396. # TLS-GROUP Capability
  397. 'CAPABILITY_TLS_GROUP_NAME' => "tls-group-name",
  398. 'CAPABILITY_TLS_GROUP_NAME_INTERNAL' => "tls-group-name-internal",
  399. 'CAPABILITY_TLS_GROUP_ID' => "tls-group-id",
  400. 'CAPABILITY_TLS_GROUP_ALG' => "tls-group-alg",
  401. 'CAPABILITY_TLS_GROUP_SECURITY_BITS' => "tls-group-sec-bits",
  402. 'CAPABILITY_TLS_GROUP_IS_KEM' => "tls-group-is-kem",
  403. 'CAPABILITY_TLS_GROUP_MIN_TLS' => "tls-min-tls",
  404. 'CAPABILITY_TLS_GROUP_MAX_TLS' => "tls-max-tls",
  405. 'CAPABILITY_TLS_GROUP_MIN_DTLS' => "tls-min-dtls",
  406. 'CAPABILITY_TLS_GROUP_MAX_DTLS' => "tls-max-dtls",
  407. # TLS-SIGALG Capability
  408. 'CAPABILITY_TLS_SIGALG_IANA_NAME' => "tls-sigalg-iana-name",
  409. 'CAPABILITY_TLS_SIGALG_CODE_POINT' => "tls-sigalg-code-point",
  410. 'CAPABILITY_TLS_SIGALG_NAME' => "tls-sigalg-name",
  411. 'CAPABILITY_TLS_SIGALG_OID' => "tls-sigalg-oid",
  412. 'CAPABILITY_TLS_SIGALG_SIG_NAME' => "tls-sigalg-sig-name",
  413. 'CAPABILITY_TLS_SIGALG_SIG_OID' => "tls-sigalg-sig-oid",
  414. 'CAPABILITY_TLS_SIGALG_HASH_NAME' => "tls-sigalg-hash-name",
  415. 'CAPABILITY_TLS_SIGALG_HASH_OID' => "tls-sigalg-hash-oid",
  416. 'CAPABILITY_TLS_SIGALG_KEYTYPE' => "tls-sigalg-keytype",
  417. 'CAPABILITY_TLS_SIGALG_KEYTYPE_OID' => "tls-sigalg-keytype-oid",
  418. 'CAPABILITY_TLS_SIGALG_SECURITY_BITS' => "tls-sigalg-sec-bits",
  419. 'CAPABILITY_TLS_SIGALG_MIN_TLS' => "tls-min-tls",
  420. 'CAPABILITY_TLS_SIGALG_MAX_TLS' => "tls-max-tls",
  421. # storemgmt parameters
  422. # Used by storemgmt_ctx_set_params():
  423. #
  424. # - STORE_PARAM_EXPECT is an INTEGER, and the value is any of the
  425. # STORE_INFO numbers. This is used to set the expected type of
  426. # object loaded.
  427. #
  428. # - STORE_PARAM_SUBJECT, STORE_PARAM_ISSUER,
  429. # STORE_PARAM_SERIAL, STORE_PARAM_FINGERPRINT,
  430. # STORE_PARAM_DIGEST, STORE_PARAM_ALIAS
  431. # are used as search criteria.
  432. # (STORE_PARAM_DIGEST is used with STORE_PARAM_FINGERPRINT)
  433. 'STORE_PARAM_EXPECT' => "expect", # INTEGER
  434. 'STORE_PARAM_SUBJECT' => "subject", # DER blob => OCTET_STRING
  435. 'STORE_PARAM_ISSUER' => "name", # DER blob => OCTET_STRING
  436. 'STORE_PARAM_SERIAL' => "serial", # INTEGER
  437. 'STORE_PARAM_DIGEST' => "digest", # UTF8_STRING
  438. 'STORE_PARAM_FINGERPRINT' => "fingerprint", # OCTET_STRING
  439. 'STORE_PARAM_ALIAS' => "alias", # UTF8_STRING
  440. # You may want to pass properties for the provider implementation to use
  441. 'STORE_PARAM_PROPERTIES' => "properties", # utf8_string
  442. # DECODER input type if a decoder is used by the store
  443. 'STORE_PARAM_INPUT_TYPE' => "input-type", # UTF8_STRING
  444. # Libssl record layer
  445. 'LIBSSL_RECORD_LAYER_PARAM_OPTIONS' => "options",
  446. 'LIBSSL_RECORD_LAYER_PARAM_MODE' => "mode",
  447. 'LIBSSL_RECORD_LAYER_PARAM_READ_AHEAD' => "read_ahead",
  448. 'LIBSSL_RECORD_LAYER_READ_BUFFER_LEN' => "read_buffer_len",
  449. 'LIBSSL_RECORD_LAYER_PARAM_USE_ETM' => "use_etm",
  450. 'LIBSSL_RECORD_LAYER_PARAM_STREAM_MAC' => "stream_mac",
  451. 'LIBSSL_RECORD_LAYER_PARAM_TLSTREE' => "tlstree",
  452. 'LIBSSL_RECORD_LAYER_PARAM_MAX_FRAG_LEN' => "max_frag_len",
  453. 'LIBSSL_RECORD_LAYER_PARAM_MAX_EARLY_DATA' => "max_early_data",
  454. 'LIBSSL_RECORD_LAYER_PARAM_BLOCK_PADDING' => "block_padding",
  455. );
  456. # Generate string based macros for public consumption
  457. sub generate_public_macros {
  458. my @macros = ();
  459. foreach my $name (keys %params) {
  460. my $val = $params{$name};
  461. my $def = '# define OSSL_' . $name . ' ';
  462. if (substr($val, 0, 1) eq '*') {
  463. $def .= 'OSSL_' . substr($val, 1);
  464. } else {
  465. $def .= '"' . $val . '"';
  466. }
  467. push(@macros, $def)
  468. }
  469. return join("\n", sort @macros);
  470. }
  471. # Generate number based macros for internal use
  472. # The numbers are unique per string
  473. sub generate_internal_macros {
  474. my @macros = ();
  475. my $count = 0;
  476. my %reverse;
  477. # Determine the number for each unique string
  478. # Sort the names to improve the chance of cache coherency
  479. foreach my $name (sort keys %params) {
  480. my $val = $params{$name};
  481. if (substr($val, 0, 1) ne '*' and not defined $reverse{$val}) {
  482. $reverse{$val} = $count++;
  483. }
  484. }
  485. # Output the defines
  486. foreach my $name (keys %params) {
  487. my $val = $params{$name};
  488. my $def = '#define PIDX_' . $name . ' ';
  489. if (substr($val, 0, 1) eq '*') {
  490. $def .= 'PIDX_' . substr($val, 1);
  491. } else {
  492. $def .= $reverse{$val};
  493. }
  494. push(@macros, $def)
  495. }
  496. return "#define NUM_PIDX $count\n\n" . join("\n", sort @macros);
  497. }
  498. sub generate_trie {
  499. my %trie;
  500. my $nodes = 0;
  501. my $chars = 0;
  502. foreach my $name (keys %params) {
  503. my $val = $params{$name};
  504. if (substr($val, 0, 1) ne '*') {
  505. my $cursor = \%trie;
  506. $chars += length($val);
  507. for my $i (0 .. length($val) - 1) {
  508. my $c = substr($val, $i, 1);
  509. if (not $case_sensitive) {
  510. $c = '_' if $c eq '-';
  511. $c = lc $c;
  512. }
  513. if (not defined $$cursor{$c}) {
  514. $cursor->{$c} = {};
  515. $nodes++;
  516. }
  517. $cursor = $cursor->{$c};
  518. }
  519. $cursor->{'val'} = $name;
  520. }
  521. }
  522. #print "\n\n/* $nodes nodes for $chars letters*/\n\n";
  523. return %trie;
  524. }
  525. sub generate_code_from_trie {
  526. my $n = shift;
  527. my $trieref = shift;
  528. my $idt = " ";
  529. my $indent0 = $idt x ($n + 1);
  530. my $indent1 = $indent0 . $idt;
  531. my $strcmp = $case_sensitive ? 'strcmp' : 'strcasecmp';
  532. print "int ossl_param_find_pidx(const char *s)\n{\n" if $n == 0;
  533. if ($trieref->{'suffix'}) {
  534. my $suf = $trieref->{'suffix'};
  535. printf "%sif ($strcmp(\"$suf\", s + $n) == 0", $indent0;
  536. if (not $case_sensitive) {
  537. $suf =~ tr/_/-/;
  538. print " || $strcmp(\"$suf\", s + $n) == 0"
  539. if ($suf ne $trieref->{'suffix'});
  540. }
  541. printf ")\n%sreturn PIDX_%s;\n", $indent1, $trieref->{'name'};
  542. #printf "%sbreak;\n", $indent0;
  543. return;
  544. }
  545. printf "%sswitch(s\[%d\]) {\n", $indent0, $n;
  546. printf "%sdefault:\n", $indent0;
  547. for my $l (sort keys %$trieref) {
  548. if ($l eq 'val') {
  549. printf "%sbreak;\n", $indent1;
  550. printf "%scase '\\0':\n", $indent0;
  551. printf "%sreturn PIDX_%s;\n", $indent1, $trieref->{'val'};
  552. } else {
  553. printf "%sbreak;\n", $indent1;
  554. printf "%scase '%s':", $indent0, $l;
  555. if (not $case_sensitive) {
  556. print " case '-':" if ($l eq '_');
  557. printf " case '%s':", uc $l if ($l =~ /[a-z]/);
  558. }
  559. print "\n";
  560. generate_code_from_trie($n + 1, $trieref->{$l});
  561. }
  562. }
  563. printf "%s}\n", $indent0;
  564. print " return -1;\n}\n" if $n == 0;
  565. return "";
  566. }
  567. # Find long endings and cache what they resolve to
  568. sub locate_long_endings {
  569. my $trieref = shift;
  570. my @names = keys %$trieref;
  571. my $num = @names;
  572. return (1, '', $trieref->{$names[0]}) if ($num == 1 and $names[0] eq 'val');
  573. if ($num == 1) {
  574. my ($res, $suffix, $name) = locate_long_endings($trieref->{$names[0]});
  575. my $e = $names[0] . $suffix;
  576. if ($res) {
  577. $trieref->{'suffix'} = $e;
  578. $trieref->{'name'} = $name;
  579. }
  580. return $res, $e, $name;
  581. }
  582. for my $l (@names) {
  583. if ($l ne 'val') {
  584. my ($res, $suffix, $name) = locate_long_endings($trieref->{$l});
  585. }
  586. }
  587. return 0, '';
  588. }
  589. sub produce_decoder {
  590. my %t = generate_trie();
  591. my $s;
  592. locate_long_endings(\%t);
  593. open local *STDOUT, '>', \$s;
  594. generate_code_from_trie(0, \%t);
  595. return $s;
  596. }