testcrypt-func.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. * List of functions exported by the 'testcrypt' system to provide a
  3. * Python API for running unit tests and auxiliary programs.
  4. *
  5. * Each function definition in this file has the form
  6. *
  7. * FUNC(return-type, function-name, ...)
  8. *
  9. * where '...' in turn a variadic list of argument specifications of
  10. * the form
  11. *
  12. * ARG(argument-type, argument-name)
  13. *
  14. * An empty argument list must be marked by including a
  15. * pseudo-argument VOID:
  16. *
  17. * FUNC(return-type, function-name, VOID)
  18. *
  19. * Type names are always single identifiers, and they have some
  20. * standard prefixes:
  21. *
  22. * 'val_' means that the type refers to something dynamically
  23. * allocated, so that it has a persistent identity, needs to be freed
  24. * when finished with (though this is done automatically by the
  25. * testcrypt.py system via Python's reference counting), and may also
  26. * be mutable. The argument type in C will be a pointer; in Python the
  27. * corresponding argument will be an instance of a 'Value' object
  28. * defined in testcrypt.py.
  29. *
  30. * 'opt_val_' is a modification of 'val_' to indicate that the pointer
  31. * may be NULL. In Python this is translated by accepting (or
  32. * returning) None as an alternative to a Value.
  33. *
  34. * 'out_' on an argument type indicates an additional output
  35. * parameter. The argument type in C has an extra layer of
  36. * indirection, e.g. an 'out_val_mpint' is an 'mpint **' instead of an
  37. * 'mpint *', identifying a pointer variable where the returned
  38. * pointer value will be written. In the Python API, these arguments
  39. * do not appear in the argument list of the Python function; instead
  40. * they cause the return value to become a tuple, with additional
  41. * types appended. For example, a declaration like
  42. *
  43. * FUNC(val_foo, example, ARG(out_val_bar, bar), ARG(val_baz, baz))
  44. *
  45. * would identify a function in C with the following prototype, which
  46. * returns a 'foo *' directly and a 'bar *' by writing it through the
  47. * provided 'bar **' pointer argument:
  48. *
  49. * foo *example(bar **extra_output, baz *input);
  50. *
  51. * and in Python this would become a function taking one argument of
  52. * type 'baz' and returning a tuple of the form (foo, bar).
  53. *
  54. * 'out_' and 'opt_' can go together, if a function returns a second
  55. * output value but it may in some cases be NULL.
  56. *
  57. * 'consumed_' on an argument type indicates that the C function
  58. * receiving that argument frees it as a side effect.
  59. *
  60. * Any argument type which does not start 'val_' is plain old data
  61. * with no dynamic allocation requirements. Ordinary C integers are
  62. * sometimes handled this way (e.g. 'uint'). Other plain-data types
  63. * are represented in Python as a string that must be one of a
  64. * recognised set of keywords; in C these variously translate into
  65. * enumeration types (e.g. argon2flavour, rsaorder) or pointers to
  66. * const vtables of one kind or another (e.g. keyalg, hashalg,
  67. * primegenpolicy).
  68. *
  69. * If a function definition begins with FUNC_WRAPPED rather than FUNC,
  70. * it means that the underlying C function has a suffix "_wrapper",
  71. * e.g. ssh_cipher_setiv_wrapper(). Those wrappers are defined in
  72. * testcrypt.c itself, and change the API or semantics in a way that
  73. * makes the function more Python-friendly.
  74. */
  75. /*
  76. * mpint.h functions.
  77. */
  78. FUNC(val_mpint, mp_new, ARG(uint, maxbits))
  79. FUNC(void, mp_clear, ARG(val_mpint, x))
  80. FUNC(val_mpint, mp_from_bytes_le, ARG(val_string_ptrlen, bytes))
  81. FUNC(val_mpint, mp_from_bytes_be, ARG(val_string_ptrlen, bytes))
  82. FUNC(val_mpint, mp_from_integer, ARG(uint, n))
  83. FUNC(val_mpint, mp_from_decimal_pl, ARG(val_string_ptrlen, decimal))
  84. FUNC(val_mpint, mp_from_decimal, ARG(val_string_asciz, decimal))
  85. FUNC(val_mpint, mp_from_hex_pl, ARG(val_string_ptrlen, hex))
  86. FUNC(val_mpint, mp_from_hex, ARG(val_string_asciz, hex))
  87. FUNC(val_mpint, mp_copy, ARG(val_mpint, x))
  88. FUNC(val_mpint, mp_power_2, ARG(uint, power))
  89. FUNC(uint, mp_get_byte, ARG(val_mpint, x), ARG(uint, byte))
  90. FUNC(uint, mp_get_bit, ARG(val_mpint, x), ARG(uint, bit))
  91. FUNC(void, mp_set_bit, ARG(val_mpint, x), ARG(uint, bit), ARG(uint, val))
  92. FUNC(uint, mp_max_bytes, ARG(val_mpint, x))
  93. FUNC(uint, mp_max_bits, ARG(val_mpint, x))
  94. FUNC(uint, mp_get_nbits, ARG(val_mpint, x))
  95. FUNC(val_string_asciz, mp_get_decimal, ARG(val_mpint, x))
  96. FUNC(val_string_asciz, mp_get_hex, ARG(val_mpint, x))
  97. FUNC(val_string_asciz, mp_get_hex_uppercase, ARG(val_mpint, x))
  98. FUNC(uint, mp_cmp_hs, ARG(val_mpint, a), ARG(val_mpint, b))
  99. FUNC(uint, mp_cmp_eq, ARG(val_mpint, a), ARG(val_mpint, b))
  100. FUNC(uint, mp_hs_integer, ARG(val_mpint, x), ARG(uint, n))
  101. FUNC(uint, mp_eq_integer, ARG(val_mpint, x), ARG(uint, n))
  102. FUNC(void, mp_min_into, ARG(val_mpint, dest), ARG(val_mpint, x),
  103. ARG(val_mpint, y))
  104. FUNC(void, mp_max_into, ARG(val_mpint, dest), ARG(val_mpint, x),
  105. ARG(val_mpint, y))
  106. FUNC(val_mpint, mp_min, ARG(val_mpint, x), ARG(val_mpint, y))
  107. FUNC(val_mpint, mp_max, ARG(val_mpint, x), ARG(val_mpint, y))
  108. FUNC(void, mp_copy_into, ARG(val_mpint, dest), ARG(val_mpint, src))
  109. FUNC(void, mp_select_into, ARG(val_mpint, dest), ARG(val_mpint, src0),
  110. ARG(val_mpint, src1), ARG(uint, choose_src1))
  111. FUNC(void, mp_add_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  112. ARG(val_mpint, b))
  113. FUNC(void, mp_sub_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  114. ARG(val_mpint, b))
  115. FUNC(void, mp_mul_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  116. ARG(val_mpint, b))
  117. FUNC(val_mpint, mp_add, ARG(val_mpint, x), ARG(val_mpint, y))
  118. FUNC(val_mpint, mp_sub, ARG(val_mpint, x), ARG(val_mpint, y))
  119. FUNC(val_mpint, mp_mul, ARG(val_mpint, x), ARG(val_mpint, y))
  120. FUNC(void, mp_and_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  121. ARG(val_mpint, b))
  122. FUNC(void, mp_or_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  123. ARG(val_mpint, b))
  124. FUNC(void, mp_xor_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  125. ARG(val_mpint, b))
  126. FUNC(void, mp_bic_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  127. ARG(val_mpint, b))
  128. FUNC(void, mp_copy_integer_into, ARG(val_mpint, dest), ARG(uint, n))
  129. FUNC(void, mp_add_integer_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  130. ARG(uint, n))
  131. FUNC(void, mp_sub_integer_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  132. ARG(uint, n))
  133. FUNC(void, mp_mul_integer_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  134. ARG(uint, n))
  135. FUNC(void, mp_cond_add_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  136. ARG(val_mpint, b), ARG(uint, yes))
  137. FUNC(void, mp_cond_sub_into, ARG(val_mpint, dest), ARG(val_mpint, a),
  138. ARG(val_mpint, b), ARG(uint, yes))
  139. FUNC(void, mp_cond_swap, ARG(val_mpint, x0), ARG(val_mpint, x1),
  140. ARG(uint, swap))
  141. FUNC(void, mp_cond_clear, ARG(val_mpint, x), ARG(uint, clear))
  142. FUNC(void, mp_divmod_into, ARG(val_mpint, n), ARG(val_mpint, d),
  143. ARG(opt_val_mpint, q), ARG(opt_val_mpint, r))
  144. FUNC(val_mpint, mp_div, ARG(val_mpint, n), ARG(val_mpint, d))
  145. FUNC(val_mpint, mp_mod, ARG(val_mpint, x), ARG(val_mpint, modulus))
  146. FUNC(val_mpint, mp_nthroot, ARG(val_mpint, y), ARG(uint, n),
  147. ARG(opt_val_mpint, remainder))
  148. FUNC(void, mp_reduce_mod_2to, ARG(val_mpint, x), ARG(uint, p))
  149. FUNC(val_mpint, mp_invert_mod_2to, ARG(val_mpint, x), ARG(uint, p))
  150. FUNC(val_mpint, mp_invert, ARG(val_mpint, x), ARG(val_mpint, modulus))
  151. FUNC(void, mp_gcd_into, ARG(val_mpint, a), ARG(val_mpint, b),
  152. ARG(opt_val_mpint, gcd_out), ARG(opt_val_mpint, A_out),
  153. ARG(opt_val_mpint, B_out))
  154. FUNC(val_mpint, mp_gcd, ARG(val_mpint, a), ARG(val_mpint, b))
  155. FUNC(uint, mp_coprime, ARG(val_mpint, a), ARG(val_mpint, b))
  156. FUNC(val_modsqrt, modsqrt_new, ARG(val_mpint, p),
  157. ARG(val_mpint, any_nonsquare_mod_p))
  158. /* The modsqrt functions' 'success' pointer becomes a second return value */
  159. FUNC(val_mpint, mp_modsqrt, ARG(val_modsqrt, sc), ARG(val_mpint, x),
  160. ARG(out_uint, success))
  161. FUNC(val_monty, monty_new, ARG(val_mpint, modulus))
  162. FUNC_WRAPPED(val_mpint, monty_modulus, ARG(val_monty, mc))
  163. FUNC_WRAPPED(val_mpint, monty_identity, ARG(val_monty, mc))
  164. FUNC(void, monty_import_into, ARG(val_monty, mc), ARG(val_mpint, dest),
  165. ARG(val_mpint, x))
  166. FUNC(val_mpint, monty_import, ARG(val_monty, mc), ARG(val_mpint, x))
  167. FUNC(void, monty_export_into, ARG(val_monty, mc), ARG(val_mpint, dest),
  168. ARG(val_mpint, x))
  169. FUNC(val_mpint, monty_export, ARG(val_monty, mc), ARG(val_mpint, x))
  170. FUNC(void, monty_mul_into, ARG(val_monty, mc), ARG(val_mpint, dest),
  171. ARG(val_mpint, x), ARG(val_mpint, y))
  172. FUNC(val_mpint, monty_add, ARG(val_monty, mc), ARG(val_mpint, x),
  173. ARG(val_mpint, y))
  174. FUNC(val_mpint, monty_sub, ARG(val_monty, mc), ARG(val_mpint, x),
  175. ARG(val_mpint, y))
  176. FUNC(val_mpint, monty_mul, ARG(val_monty, mc), ARG(val_mpint, x),
  177. ARG(val_mpint, y))
  178. FUNC(val_mpint, monty_pow, ARG(val_monty, mc), ARG(val_mpint, base),
  179. ARG(val_mpint, exponent))
  180. FUNC(val_mpint, monty_invert, ARG(val_monty, mc), ARG(val_mpint, x))
  181. FUNC(val_mpint, monty_modsqrt, ARG(val_modsqrt, sc), ARG(val_mpint, mx),
  182. ARG(out_uint, success))
  183. FUNC(val_mpint, mp_modpow, ARG(val_mpint, base), ARG(val_mpint, exponent),
  184. ARG(val_mpint, modulus))
  185. FUNC(val_mpint, mp_modmul, ARG(val_mpint, x), ARG(val_mpint, y),
  186. ARG(val_mpint, modulus))
  187. FUNC(val_mpint, mp_modadd, ARG(val_mpint, x), ARG(val_mpint, y),
  188. ARG(val_mpint, modulus))
  189. FUNC(val_mpint, mp_modsub, ARG(val_mpint, x), ARG(val_mpint, y),
  190. ARG(val_mpint, modulus))
  191. FUNC(void, mp_lshift_safe_into, ARG(val_mpint, dest), ARG(val_mpint, x),
  192. ARG(uint, shift))
  193. FUNC(void, mp_rshift_safe_into, ARG(val_mpint, dest), ARG(val_mpint, x),
  194. ARG(uint, shift))
  195. FUNC(val_mpint, mp_rshift_safe, ARG(val_mpint, x), ARG(uint, shift))
  196. FUNC(void, mp_lshift_fixed_into, ARG(val_mpint, dest), ARG(val_mpint, x),
  197. ARG(uint, shift))
  198. FUNC(void, mp_rshift_fixed_into, ARG(val_mpint, dest), ARG(val_mpint, x),
  199. ARG(uint, shift))
  200. FUNC(val_mpint, mp_rshift_fixed, ARG(val_mpint, x), ARG(uint, shift))
  201. FUNC(val_mpint, mp_random_bits, ARG(uint, bits))
  202. FUNC(val_mpint, mp_random_in_range, ARG(val_mpint, lo), ARG(val_mpint, hi))
  203. /*
  204. * ecc.h functions.
  205. */
  206. FUNC(val_wcurve, ecc_weierstrass_curve, ARG(val_mpint, p), ARG(val_mpint, a),
  207. ARG(val_mpint, b), ARG(opt_val_mpint, nonsquare_mod_p))
  208. FUNC(val_wpoint, ecc_weierstrass_point_new_identity, ARG(val_wcurve, curve))
  209. FUNC(val_wpoint, ecc_weierstrass_point_new, ARG(val_wcurve, curve),
  210. ARG(val_mpint, x), ARG(val_mpint, y))
  211. FUNC(val_wpoint, ecc_weierstrass_point_new_from_x, ARG(val_wcurve, curve),
  212. ARG(val_mpint, x), ARG(uint, desired_y_parity))
  213. FUNC(val_wpoint, ecc_weierstrass_point_copy, ARG(val_wpoint, orig))
  214. FUNC(uint, ecc_weierstrass_point_valid, ARG(val_wpoint, P))
  215. FUNC(val_wpoint, ecc_weierstrass_add_general, ARG(val_wpoint, P),
  216. ARG(val_wpoint, Q))
  217. FUNC(val_wpoint, ecc_weierstrass_add, ARG(val_wpoint, P), ARG(val_wpoint, Q))
  218. FUNC(val_wpoint, ecc_weierstrass_double, ARG(val_wpoint, P))
  219. FUNC(val_wpoint, ecc_weierstrass_multiply, ARG(val_wpoint, B),
  220. ARG(val_mpint, n))
  221. FUNC(uint, ecc_weierstrass_is_identity, ARG(val_wpoint, P))
  222. /* The output pointers in get_affine all become extra output values */
  223. FUNC(void, ecc_weierstrass_get_affine, ARG(val_wpoint, P),
  224. ARG(out_val_mpint, x), ARG(out_val_mpint, y))
  225. FUNC(val_mcurve, ecc_montgomery_curve, ARG(val_mpint, p), ARG(val_mpint, a),
  226. ARG(val_mpint, b))
  227. FUNC(val_mpoint, ecc_montgomery_point_new, ARG(val_mcurve, curve),
  228. ARG(val_mpint, x))
  229. FUNC(val_mpoint, ecc_montgomery_point_copy, ARG(val_mpoint, orig))
  230. FUNC(val_mpoint, ecc_montgomery_diff_add, ARG(val_mpoint, P),
  231. ARG(val_mpoint, Q), ARG(val_mpoint, PminusQ))
  232. FUNC(val_mpoint, ecc_montgomery_double, ARG(val_mpoint, P))
  233. FUNC(val_mpoint, ecc_montgomery_multiply, ARG(val_mpoint, B), ARG(val_mpint, n))
  234. FUNC(void, ecc_montgomery_get_affine, ARG(val_mpoint, P), ARG(out_val_mpint, x))
  235. FUNC(boolean, ecc_montgomery_is_identity, ARG(val_mpoint, P))
  236. FUNC(val_ecurve, ecc_edwards_curve, ARG(val_mpint, p), ARG(val_mpint, d),
  237. ARG(val_mpint, a), ARG(opt_val_mpint, nonsquare_mod_p))
  238. FUNC(val_epoint, ecc_edwards_point_new, ARG(val_ecurve, curve),
  239. ARG(val_mpint, x), ARG(val_mpint, y))
  240. FUNC(val_epoint, ecc_edwards_point_new_from_y, ARG(val_ecurve, curve),
  241. ARG(val_mpint, y), ARG(uint, desired_x_parity))
  242. FUNC(val_epoint, ecc_edwards_point_copy, ARG(val_epoint, orig))
  243. FUNC(val_epoint, ecc_edwards_add, ARG(val_epoint, P), ARG(val_epoint, Q))
  244. FUNC(val_epoint, ecc_edwards_multiply, ARG(val_epoint, B), ARG(val_mpint, n))
  245. FUNC(uint, ecc_edwards_eq, ARG(val_epoint, P), ARG(val_epoint, Q))
  246. FUNC(void, ecc_edwards_get_affine, ARG(val_epoint, P), ARG(out_val_mpint, x),
  247. ARG(out_val_mpint, y))
  248. /*
  249. * The ssh_hash abstraction. Note the 'consumed', indicating that
  250. * ssh_hash_final puts its input ssh_hash beyond use.
  251. *
  252. * ssh_hash_update is an invention of testcrypt, handled in the real C
  253. * API by the hash object also functioning as a BinarySink.
  254. */
  255. FUNC(opt_val_hash, ssh_hash_new, ARG(hashalg, alg))
  256. FUNC(void, ssh_hash_reset, ARG(val_hash, h))
  257. FUNC(val_hash, ssh_hash_copy, ARG(val_hash, orig))
  258. FUNC_WRAPPED(val_string, ssh_hash_digest, ARG(val_hash, h))
  259. FUNC_WRAPPED(val_string, ssh_hash_final, ARG(consumed_val_hash, h))
  260. FUNC(void, ssh_hash_update, ARG(val_hash, h), ARG(val_string_ptrlen, data))
  261. FUNC(opt_val_hash, blake2b_new_general, ARG(uint, hashlen))
  262. /*
  263. * The ssh2_mac abstraction. Note the optional ssh_cipher parameter
  264. * to ssh2_mac_new. Also, again, I've invented an ssh2_mac_update so
  265. * you can put data into the MAC.
  266. */
  267. FUNC(opt_val_mac, ssh2_mac_new, ARG(macalg, alg), ARG(opt_val_cipher, cipher))
  268. FUNC(void, ssh2_mac_setkey, ARG(val_mac, m), ARG(val_string_ptrlen, key))
  269. FUNC(void, ssh2_mac_start, ARG(val_mac, m))
  270. FUNC(void, ssh2_mac_update, ARG(val_mac, m), ARG(val_string_ptrlen, data))
  271. FUNC(void, ssh2_mac_next_message, ARG(val_mac, m))
  272. FUNC_WRAPPED(val_string, ssh2_mac_genresult, ARG(val_mac, m))
  273. FUNC(val_string_asciz_const, ssh2_mac_text_name, ARG(val_mac, m))
  274. FUNC(void, aesgcm_set_prefix_lengths,
  275. ARG(val_mac, m), ARG(uint, skip), ARG(uint, aad))
  276. /*
  277. * The ssh_key abstraction. All the uses of BinarySink and
  278. * BinarySource in parameters are replaced with ordinary strings for
  279. * the testing API: new_priv_openssh just takes a string input, and
  280. * all the functions that output key and signature blobs do it by
  281. * returning a string.
  282. */
  283. FUNC(val_key, ssh_key_new_pub, ARG(keyalg, alg), ARG(val_string_ptrlen, pub))
  284. FUNC(opt_val_key, ssh_key_new_priv, ARG(keyalg, alg),
  285. ARG(val_string_ptrlen, pub), ARG(val_string_ptrlen, priv))
  286. FUNC(opt_val_key, ssh_key_new_priv_openssh, ARG(keyalg, alg),
  287. ARG(val_string_binarysource, src))
  288. FUNC(opt_val_string_asciz, ssh_key_invalid, ARG(val_key, key), ARG(uint, flags))
  289. FUNC(void, ssh_key_sign, ARG(val_key, key), ARG(val_string_ptrlen, data),
  290. ARG(uint, flags), ARG(out_val_string_binarysink, sig))
  291. FUNC(boolean, ssh_key_verify, ARG(val_key, key), ARG(val_string_ptrlen, sig),
  292. ARG(val_string_ptrlen, data))
  293. FUNC(void, ssh_key_public_blob, ARG(val_key, key),
  294. ARG(out_val_string_binarysink, blob))
  295. FUNC(void, ssh_key_private_blob, ARG(val_key, key),
  296. ARG(out_val_string_binarysink, blob))
  297. FUNC(void, ssh_key_openssh_blob, ARG(val_key, key),
  298. ARG(out_val_string_binarysink, blob))
  299. FUNC(val_string_asciz, ssh_key_cache_str, ARG(val_key, key))
  300. FUNC(val_keycomponents, ssh_key_components, ARG(val_key, key))
  301. FUNC(uint, ssh_key_public_bits, ARG(keyalg, self), ARG(val_string_ptrlen, blob))
  302. FUNC_WRAPPED(val_key, ssh_key_base_key, ARG(val_key, key))
  303. FUNC_WRAPPED(void, ssh_key_ca_public_blob, ARG(val_key, key),
  304. ARG(out_val_string_binarysink, blob))
  305. FUNC_WRAPPED(void, ssh_key_cert_id_string, ARG(val_key, key),
  306. ARG(out_val_string_binarysink, blob))
  307. FUNC_WRAPPED(boolean, ssh_key_check_cert, ARG(val_key, key),
  308. ARG(boolean, host), ARG(val_string_ptrlen, principal),
  309. ARG(uint, time), ARG(val_string_ptrlen, options),
  310. ARG(out_val_string_binarysink, error))
  311. /*
  312. * Accessors to retrieve the innards of a 'key_components'.
  313. */
  314. FUNC(uint, key_components_count, ARG(val_keycomponents, kc))
  315. FUNC(opt_val_string_asciz_const, key_components_nth_name,
  316. ARG(val_keycomponents, kc), ARG(uint, n))
  317. FUNC(opt_val_string, key_components_nth_str,
  318. ARG(val_keycomponents, kc), ARG(uint, n))
  319. FUNC(opt_val_mpint, key_components_nth_mp, ARG(val_keycomponents, kc),
  320. ARG(uint, n))
  321. /*
  322. * DSA nonce generation.
  323. */
  324. FUNC(opt_val_mpint, rfc6979, ARG(hashalg, hash), ARG(val_mpint, modulus),
  325. ARG(val_mpint, private_key), ARG(val_string_ptrlen, message))
  326. /*
  327. * The ssh_cipher abstraction. The in-place encrypt and decrypt
  328. * functions are wrapped to replace them with versions that take one
  329. * string and return a separate string.
  330. */
  331. FUNC(opt_val_cipher, ssh_cipher_new, ARG(cipheralg, alg))
  332. FUNC_WRAPPED(void, ssh_cipher_setiv, ARG(val_cipher, c),
  333. ARG(val_string_ptrlen, iv))
  334. FUNC_WRAPPED(void, ssh_cipher_setkey, ARG(val_cipher, c),
  335. ARG(val_string_ptrlen, key))
  336. FUNC_WRAPPED(val_string, ssh_cipher_encrypt, ARG(val_cipher, c),
  337. ARG(val_string_ptrlen, blk))
  338. FUNC_WRAPPED(val_string, ssh_cipher_decrypt, ARG(val_cipher, c),
  339. ARG(val_string_ptrlen, blk))
  340. FUNC_WRAPPED(val_string, ssh_cipher_encrypt_length, ARG(val_cipher, c),
  341. ARG(val_string_ptrlen, blk), ARG(uint, seq))
  342. FUNC_WRAPPED(val_string, ssh_cipher_decrypt_length, ARG(val_cipher, c),
  343. ARG(val_string_ptrlen, blk), ARG(uint, seq))
  344. FUNC(void, ssh_cipher_next_message, ARG(val_cipher, c))
  345. /*
  346. * Integer Diffie-Hellman.
  347. */
  348. FUNC(val_dh, dh_setup_group, ARG(dh_group, group))
  349. FUNC(val_dh, dh_setup_gex, ARG(val_mpint, p), ARG(val_mpint, g))
  350. FUNC(uint, dh_modulus_bit_size, ARG(val_dh, ctx))
  351. FUNC(val_mpint, dh_create_e, ARG(val_dh, ctx))
  352. FUNC_WRAPPED(boolean, dh_validate_f, ARG(val_dh, ctx), ARG(val_mpint, f))
  353. FUNC(val_mpint, dh_find_K, ARG(val_dh, ctx), ARG(val_mpint, f))
  354. /*
  355. * Elliptic-curve Diffie-Hellman.
  356. */
  357. FUNC(val_ecdh, ecdh_key_new, ARG(ecdh_alg, alg), ARG(boolean, is_server))
  358. FUNC(void, ecdh_key_getpublic, ARG(val_ecdh, key),
  359. ARG(out_val_string_binarysink, pub))
  360. FUNC_WRAPPED(opt_val_string, ecdh_key_getkey, ARG(val_ecdh, key),
  361. ARG(val_string_ptrlen, pub))
  362. /*
  363. * NTRU and its subroutines.
  364. */
  365. FUNC_WRAPPED(int16_list, ntru_ring_multiply, ARG(int16_list, a),
  366. ARG(int16_list, b), ARG(uint, p), ARG(uint, q))
  367. FUNC_WRAPPED(opt_int16_list, ntru_ring_invert, ARG(int16_list, r),
  368. ARG(uint, p), ARG(uint, q))
  369. FUNC_WRAPPED(int16_list, ntru_mod3, ARG(int16_list, r),
  370. ARG(uint, p), ARG(uint, q))
  371. FUNC_WRAPPED(int16_list, ntru_round3, ARG(int16_list, r),
  372. ARG(uint, p), ARG(uint, q))
  373. FUNC_WRAPPED(int16_list, ntru_bias, ARG(int16_list, r),
  374. ARG(uint, bias), ARG(uint, p), ARG(uint, q))
  375. FUNC_WRAPPED(int16_list, ntru_scale, ARG(int16_list, r),
  376. ARG(uint, scale), ARG(uint, p), ARG(uint, q))
  377. FUNC_WRAPPED(val_ntruencodeschedule, ntru_encode_schedule, ARG(int16_list, ms))
  378. FUNC(uint, ntru_encode_schedule_length, ARG(val_ntruencodeschedule, sched))
  379. FUNC_WRAPPED(void, ntru_encode, ARG(val_ntruencodeschedule, sched),
  380. ARG(int16_list, rs), ARG(out_val_string_binarysink, data))
  381. FUNC_WRAPPED(opt_int16_list, ntru_decode, ARG(val_ntruencodeschedule, sched),
  382. ARG(val_string_ptrlen, data))
  383. FUNC_WRAPPED(int16_list, ntru_gen_short, ARG(uint, p), ARG(uint, w))
  384. FUNC(val_ntrukeypair, ntru_keygen, ARG(uint, p), ARG(uint, q), ARG(uint, w))
  385. FUNC_WRAPPED(int16_list, ntru_pubkey, ARG(val_ntrukeypair, keypair))
  386. FUNC_WRAPPED(int16_list, ntru_encrypt, ARG(int16_list, plaintext),
  387. ARG(int16_list, pubkey), ARG(uint, p), ARG(uint, q))
  388. FUNC_WRAPPED(int16_list, ntru_decrypt, ARG(int16_list, ciphertext),
  389. ARG(val_ntrukeypair, keypair))
  390. /*
  391. * RSA key exchange, and also the BinarySource get function
  392. * get_ssh1_rsa_priv_agent, which is a convenient way to make an
  393. * RSAKey for RSA kex testing purposes.
  394. */
  395. FUNC(val_rsakex, ssh_rsakex_newkey, ARG(val_string_ptrlen, data))
  396. FUNC(uint, ssh_rsakex_klen, ARG(val_rsakex, key))
  397. FUNC(val_string, ssh_rsakex_encrypt, ARG(val_rsakex, key), ARG(hashalg, h),
  398. ARG(val_string_ptrlen, plaintext))
  399. FUNC(opt_val_mpint, ssh_rsakex_decrypt, ARG(val_rsakex, key), ARG(hashalg, h),
  400. ARG(val_string_ptrlen, ciphertext))
  401. FUNC(val_rsakex, get_rsa_ssh1_priv_agent, ARG(val_string_binarysource, src))
  402. /*
  403. * Bare RSA keys as used in SSH-1. The construction API functions
  404. * write into an existing RSAKey object, so I've invented an 'rsa_new'
  405. * function to make one in the first place.
  406. */
  407. FUNC(val_rsa, rsa_new, VOID)
  408. FUNC(void, get_rsa_ssh1_pub, ARG(val_string_binarysource, src),
  409. ARG(val_rsa, key), ARG(rsaorder, order))
  410. FUNC(void, get_rsa_ssh1_priv, ARG(val_string_binarysource, src),
  411. ARG(val_rsa, key))
  412. FUNC_WRAPPED(opt_val_string, rsa_ssh1_encrypt, ARG(val_string_ptrlen, data),
  413. ARG(val_rsa, key))
  414. FUNC(val_mpint, rsa_ssh1_decrypt, ARG(val_mpint, input), ARG(val_rsa, key))
  415. FUNC_WRAPPED(val_string, rsa_ssh1_decrypt_pkcs1, ARG(val_mpint, input),
  416. ARG(val_rsa, key))
  417. FUNC(val_string_asciz, rsastr_fmt, ARG(val_rsa, key))
  418. FUNC(val_string_asciz, rsa_ssh1_fingerprint, ARG(val_rsa, key))
  419. FUNC(void, rsa_ssh1_public_blob, ARG(out_val_string_binarysink, blob),
  420. ARG(val_rsa, key), ARG(rsaorder, order))
  421. FUNC(int, rsa_ssh1_public_blob_len, ARG(val_string_ptrlen, data))
  422. FUNC(void, rsa_ssh1_private_blob_agent, ARG(out_val_string_binarysink, blob),
  423. ARG(val_rsa, key))
  424. /*
  425. * The PRNG type. Similarly to hashes and MACs, I've invented an extra
  426. * function prng_seed_update for putting seed data into the PRNG's
  427. * exposed BinarySink.
  428. */
  429. FUNC(val_prng, prng_new, ARG(hashalg, hashalg))
  430. FUNC(void, prng_seed_begin, ARG(val_prng, pr))
  431. FUNC(void, prng_seed_update, ARG(val_prng, pr), ARG(val_string_ptrlen, data))
  432. FUNC(void, prng_seed_finish, ARG(val_prng, pr))
  433. FUNC_WRAPPED(val_string, prng_read, ARG(val_prng, pr), ARG(uint, size))
  434. FUNC(void, prng_add_entropy, ARG(val_prng, pr), ARG(uint, source_id),
  435. ARG(val_string_ptrlen, data))
  436. /*
  437. * Key load/save functions, or rather, the BinarySource / strbuf API
  438. * that sits just inside the file I/O versions.
  439. */
  440. FUNC(boolean, ppk_encrypted_s, ARG(val_string_binarysource, src),
  441. ARG(out_opt_val_string_asciz, comment))
  442. FUNC(boolean, rsa1_encrypted_s, ARG(val_string_binarysource, src),
  443. ARG(out_opt_val_string_asciz, comment))
  444. FUNC(boolean, ppk_loadpub_s, ARG(val_string_binarysource, src),
  445. ARG(out_opt_val_string_asciz, algorithm),
  446. ARG(out_val_string_binarysink, blob),
  447. ARG(out_opt_val_string_asciz, comment),
  448. ARG(out_opt_val_string_asciz_const, error))
  449. FUNC(int, rsa1_loadpub_s, ARG(val_string_binarysource, src),
  450. ARG(out_val_string_binarysink, blob),
  451. ARG(out_opt_val_string_asciz, comment),
  452. ARG(out_opt_val_string_asciz_const, error))
  453. FUNC_WRAPPED(opt_val_key, ppk_load_s, ARG(val_string_binarysource, src),
  454. ARG(out_opt_val_string_asciz, comment),
  455. ARG(opt_val_string_asciz, passphrase),
  456. ARG(out_opt_val_string_asciz_const, error))
  457. FUNC_WRAPPED(int, rsa1_load_s, ARG(val_string_binarysource, src),
  458. ARG(val_rsa, key), ARG(out_opt_val_string_asciz, comment),
  459. ARG(opt_val_string_asciz, passphrase),
  460. ARG(out_opt_val_string_asciz_const, error))
  461. FUNC_WRAPPED(val_string, ppk_save_sb, ARG(val_key, key),
  462. ARG(opt_val_string_asciz, comment),
  463. ARG(opt_val_string_asciz, passphrase), ARG(uint, fmt_version),
  464. ARG(argon2flavour, flavour), ARG(uint, mem), ARG(uint, passes),
  465. ARG(uint, parallel))
  466. FUNC_WRAPPED(val_string, rsa1_save_sb, ARG(val_rsa, key),
  467. ARG(opt_val_string_asciz, comment),
  468. ARG(opt_val_string_asciz, passphrase))
  469. FUNC(val_string_asciz, ssh2_fingerprint_blob, ARG(val_string_ptrlen, blob),
  470. ARG(fptype, fptype))
  471. /*
  472. * Password hashing.
  473. */
  474. FUNC_WRAPPED(val_string, argon2, ARG(argon2flavour, flavour), ARG(uint, mem),
  475. ARG(uint, passes), ARG(uint, parallel), ARG(uint, taglen),
  476. ARG(val_string_ptrlen, P), ARG(val_string_ptrlen, S),
  477. ARG(val_string_ptrlen, K), ARG(val_string_ptrlen, X))
  478. FUNC(val_string, argon2_long_hash, ARG(uint, length),
  479. ARG(val_string_ptrlen, data))
  480. FUNC_WRAPPED(val_string, openssh_bcrypt, ARG(val_string_ptrlen, passphrase),
  481. ARG(val_string_ptrlen, salt), ARG(uint, rounds),
  482. ARG(uint, outbytes))
  483. /*
  484. * Key generation functions.
  485. */
  486. FUNC_WRAPPED(val_key, rsa_generate, ARG(uint, bits), ARG(boolean, strong),
  487. ARG(val_pgc, pgc))
  488. FUNC_WRAPPED(val_key, dsa_generate, ARG(uint, bits), ARG(val_pgc, pgc))
  489. FUNC_WRAPPED(opt_val_key, ecdsa_generate, ARG(uint, bits))
  490. FUNC_WRAPPED(opt_val_key, eddsa_generate, ARG(uint, bits))
  491. FUNC(val_rsa, rsa1_generate, ARG(uint, bits), ARG(boolean, strong),
  492. ARG(val_pgc, pgc))
  493. FUNC(val_pgc, primegen_new_context, ARG(primegenpolicy, policy))
  494. FUNC_WRAPPED(opt_val_mpint, primegen_generate, ARG(val_pgc, ctx),
  495. ARG(consumed_val_pcs, pcs))
  496. FUNC(val_string, primegen_mpu_certificate, ARG(val_pgc, ctx), ARG(val_mpint, p))
  497. FUNC(val_pcs, pcs_new, ARG(uint, bits))
  498. FUNC(val_pcs, pcs_new_with_firstbits, ARG(uint, bits), ARG(uint, first),
  499. ARG(uint, nfirst))
  500. FUNC(void, pcs_require_residue, ARG(val_pcs, s), ARG(val_mpint, mod),
  501. ARG(val_mpint, res))
  502. FUNC(void, pcs_require_residue_1, ARG(val_pcs, s), ARG(val_mpint, mod))
  503. FUNC(void, pcs_require_residue_1_mod_prime, ARG(val_pcs, s),
  504. ARG(val_mpint, mod))
  505. FUNC(void, pcs_avoid_residue_small, ARG(val_pcs, s), ARG(uint, mod),
  506. ARG(uint, res))
  507. FUNC(void, pcs_try_sophie_germain, ARG(val_pcs, s))
  508. FUNC(void, pcs_set_oneshot, ARG(val_pcs, s))
  509. FUNC(void, pcs_ready, ARG(val_pcs, s))
  510. FUNC(void, pcs_inspect, ARG(val_pcs, pcs), ARG(out_val_mpint, limit_out),
  511. ARG(out_val_mpint, factor_out), ARG(out_val_mpint, addend_out))
  512. FUNC(val_mpint, pcs_generate, ARG(val_pcs, s))
  513. FUNC(val_pockle, pockle_new, VOID)
  514. FUNC(uint, pockle_mark, ARG(val_pockle, pockle))
  515. FUNC(void, pockle_release, ARG(val_pockle, pockle), ARG(uint, mark))
  516. FUNC(pocklestatus, pockle_add_small_prime, ARG(val_pockle, pockle),
  517. ARG(val_mpint, p))
  518. FUNC_WRAPPED(pocklestatus, pockle_add_prime, ARG(val_pockle, pockle),
  519. ARG(val_mpint, p), ARG(mpint_list, factors),
  520. ARG(val_mpint, witness))
  521. FUNC(val_string, pockle_mpu, ARG(val_pockle, pockle), ARG(val_mpint, p))
  522. FUNC(val_millerrabin, miller_rabin_new, ARG(val_mpint, p))
  523. FUNC(mr_result, miller_rabin_test, ARG(val_millerrabin, mr), ARG(val_mpint, w))
  524. /*
  525. * Miscellaneous.
  526. */
  527. FUNC(val_wpoint, ecdsa_public, ARG(val_mpint, private_key), ARG(keyalg, alg))
  528. FUNC(val_epoint, eddsa_public, ARG(val_mpint, private_key), ARG(keyalg, alg))
  529. FUNC_WRAPPED(val_string, des_encrypt_xdmauth, ARG(val_string_ptrlen, key),
  530. ARG(val_string_ptrlen, blk))
  531. FUNC_WRAPPED(val_string, des_decrypt_xdmauth, ARG(val_string_ptrlen, key),
  532. ARG(val_string_ptrlen, blk))
  533. FUNC_WRAPPED(val_string, des3_encrypt_pubkey, ARG(val_string_ptrlen, key),
  534. ARG(val_string_ptrlen, blk))
  535. FUNC_WRAPPED(val_string, des3_decrypt_pubkey, ARG(val_string_ptrlen, key),
  536. ARG(val_string_ptrlen, blk))
  537. FUNC_WRAPPED(val_string, des3_encrypt_pubkey_ossh, ARG(val_string_ptrlen, key),
  538. ARG(val_string_ptrlen, iv), ARG(val_string_ptrlen, blk))
  539. FUNC_WRAPPED(val_string, des3_decrypt_pubkey_ossh, ARG(val_string_ptrlen, key),
  540. ARG(val_string_ptrlen, iv), ARG(val_string_ptrlen, blk))
  541. FUNC_WRAPPED(val_string, aes256_encrypt_pubkey, ARG(val_string_ptrlen, key),
  542. ARG(val_string_ptrlen, iv), ARG(val_string_ptrlen, blk))
  543. FUNC_WRAPPED(val_string, aes256_decrypt_pubkey, ARG(val_string_ptrlen, key),
  544. ARG(val_string_ptrlen, iv), ARG(val_string_ptrlen, blk))
  545. FUNC(uint, crc32_rfc1662, ARG(val_string_ptrlen, data))
  546. FUNC(uint, crc32_ssh1, ARG(val_string_ptrlen, data))
  547. FUNC(uint, crc32_update, ARG(uint, crc_input), ARG(val_string_ptrlen, data))
  548. FUNC(boolean, crcda_detect, ARG(val_string_ptrlen, packet),
  549. ARG(val_string_ptrlen, iv))
  550. FUNC(val_string, get_implementations_commasep, ARG(val_string_ptrlen, alg))
  551. FUNC(void, http_digest_response, ARG(out_val_string_binarysink, response),
  552. ARG(val_string_ptrlen, username), ARG(val_string_ptrlen, password),
  553. ARG(val_string_ptrlen, realm), ARG(val_string_ptrlen, method),
  554. ARG(val_string_ptrlen, uri), ARG(val_string_ptrlen, qop),
  555. ARG(val_string_ptrlen, nonce), ARG(val_string_ptrlen, opaque),
  556. ARG(uint, nonce_count), ARG(httpdigesthash, hash),
  557. ARG(boolean, hash_username))
  558. /*
  559. * These functions aren't part of PuTTY's own API, but are additions
  560. * by testcrypt itself for administrative purposes.
  561. */
  562. FUNC(void, random_queue, ARG(val_string_ptrlen, data))
  563. FUNC(uint, random_queue_len, VOID)
  564. FUNC(void, random_make_prng, ARG(hashalg, hashalg),
  565. ARG(val_string_ptrlen, seed))
  566. FUNC(void, random_clear, VOID)