evp_int.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*
  2. * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 <openssl/evp.h>
  10. #include "internal/refcount.h"
  11. /*
  12. * Don't free up md_ctx->pctx in EVP_MD_CTX_reset, use the reserved flag
  13. * values in evp.h
  14. */
  15. #define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400
  16. struct evp_pkey_ctx_st {
  17. /* Method associated with this operation */
  18. const EVP_PKEY_METHOD *pmeth;
  19. /* Engine that implements this method or NULL if builtin */
  20. ENGINE *engine;
  21. /* Key: may be NULL */
  22. EVP_PKEY *pkey;
  23. /* Peer key for key agreement, may be NULL */
  24. EVP_PKEY *peerkey;
  25. /* Actual operation */
  26. int operation;
  27. /* Algorithm specific data */
  28. void *data;
  29. /* Application specific data */
  30. void *app_data;
  31. /* Keygen callback */
  32. EVP_PKEY_gen_cb *pkey_gencb;
  33. /* implementation specific keygen data */
  34. int *keygen_info;
  35. int keygen_info_count;
  36. } /* EVP_PKEY_CTX */ ;
  37. #define EVP_PKEY_FLAG_DYNAMIC 1
  38. struct evp_pkey_method_st {
  39. int pkey_id;
  40. int flags;
  41. int (*init) (EVP_PKEY_CTX *ctx);
  42. int (*copy) (EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src);
  43. void (*cleanup) (EVP_PKEY_CTX *ctx);
  44. int (*paramgen_init) (EVP_PKEY_CTX *ctx);
  45. int (*paramgen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
  46. int (*keygen_init) (EVP_PKEY_CTX *ctx);
  47. int (*keygen) (EVP_PKEY_CTX *ctx, EVP_PKEY *pkey);
  48. int (*sign_init) (EVP_PKEY_CTX *ctx);
  49. int (*sign) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
  50. const unsigned char *tbs, size_t tbslen);
  51. int (*verify_init) (EVP_PKEY_CTX *ctx);
  52. int (*verify) (EVP_PKEY_CTX *ctx,
  53. const unsigned char *sig, size_t siglen,
  54. const unsigned char *tbs, size_t tbslen);
  55. int (*verify_recover_init) (EVP_PKEY_CTX *ctx);
  56. int (*verify_recover) (EVP_PKEY_CTX *ctx,
  57. unsigned char *rout, size_t *routlen,
  58. const unsigned char *sig, size_t siglen);
  59. int (*signctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
  60. int (*signctx) (EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
  61. EVP_MD_CTX *mctx);
  62. int (*verifyctx_init) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
  63. int (*verifyctx) (EVP_PKEY_CTX *ctx, const unsigned char *sig, int siglen,
  64. EVP_MD_CTX *mctx);
  65. int (*encrypt_init) (EVP_PKEY_CTX *ctx);
  66. int (*encrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
  67. const unsigned char *in, size_t inlen);
  68. int (*decrypt_init) (EVP_PKEY_CTX *ctx);
  69. int (*decrypt) (EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
  70. const unsigned char *in, size_t inlen);
  71. int (*derive_init) (EVP_PKEY_CTX *ctx);
  72. int (*derive) (EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
  73. int (*ctrl) (EVP_PKEY_CTX *ctx, int type, int p1, void *p2);
  74. int (*ctrl_str) (EVP_PKEY_CTX *ctx, const char *type, const char *value);
  75. int (*digestsign) (EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen,
  76. const unsigned char *tbs, size_t tbslen);
  77. int (*digestverify) (EVP_MD_CTX *ctx, const unsigned char *sig,
  78. size_t siglen, const unsigned char *tbs,
  79. size_t tbslen);
  80. int (*check) (EVP_PKEY *pkey);
  81. int (*public_check) (EVP_PKEY *pkey);
  82. int (*param_check) (EVP_PKEY *pkey);
  83. int (*digest_custom) (EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx);
  84. } /* EVP_PKEY_METHOD */ ;
  85. DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
  86. void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);
  87. extern const EVP_PKEY_METHOD cmac_pkey_meth;
  88. extern const EVP_PKEY_METHOD dh_pkey_meth;
  89. extern const EVP_PKEY_METHOD dhx_pkey_meth;
  90. extern const EVP_PKEY_METHOD dsa_pkey_meth;
  91. extern const EVP_PKEY_METHOD ec_pkey_meth;
  92. extern const EVP_PKEY_METHOD sm2_pkey_meth;
  93. extern const EVP_PKEY_METHOD ecx25519_pkey_meth;
  94. extern const EVP_PKEY_METHOD ecx448_pkey_meth;
  95. extern const EVP_PKEY_METHOD ed25519_pkey_meth;
  96. extern const EVP_PKEY_METHOD ed448_pkey_meth;
  97. extern const EVP_PKEY_METHOD hmac_pkey_meth;
  98. extern const EVP_PKEY_METHOD rsa_pkey_meth;
  99. extern const EVP_PKEY_METHOD rsa_pss_pkey_meth;
  100. extern const EVP_PKEY_METHOD scrypt_pkey_meth;
  101. extern const EVP_PKEY_METHOD tls1_prf_pkey_meth;
  102. extern const EVP_PKEY_METHOD hkdf_pkey_meth;
  103. extern const EVP_PKEY_METHOD poly1305_pkey_meth;
  104. extern const EVP_PKEY_METHOD siphash_pkey_meth;
  105. /* struct evp_mac_impl_st is defined by the implementation */
  106. typedef struct evp_mac_impl_st EVP_MAC_IMPL;
  107. struct evp_mac_st {
  108. int type;
  109. EVP_MAC_IMPL *(*new) (void);
  110. int (*copy) (EVP_MAC_IMPL *macdst, EVP_MAC_IMPL *macsrc);
  111. void (*free) (EVP_MAC_IMPL *macctx);
  112. size_t (*size) (EVP_MAC_IMPL *macctx);
  113. int (*init) (EVP_MAC_IMPL *macctx);
  114. int (*update) (EVP_MAC_IMPL *macctx, const unsigned char *data,
  115. size_t datalen);
  116. int (*final) (EVP_MAC_IMPL *macctx, unsigned char *out);
  117. int (*ctrl) (EVP_MAC_IMPL *macctx, int cmd, va_list args);
  118. int (*ctrl_str) (EVP_MAC_IMPL *macctx, const char *type, const char *value);
  119. };
  120. extern const EVP_MAC cmac_meth;
  121. extern const EVP_MAC gmac_meth;
  122. extern const EVP_MAC hmac_meth;
  123. extern const EVP_MAC siphash_meth;
  124. extern const EVP_MAC poly1305_meth;
  125. /*
  126. * This function is internal for now, but can be made external when needed.
  127. * The documentation would read:
  128. *
  129. * EVP_add_mac() adds the MAC implementation C<mac> to the internal
  130. * object database.
  131. */
  132. int EVP_add_mac(const EVP_MAC *mac);
  133. struct evp_md_st {
  134. int type;
  135. int pkey_type;
  136. int md_size;
  137. unsigned long flags;
  138. int (*init) (EVP_MD_CTX *ctx);
  139. int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
  140. int (*final) (EVP_MD_CTX *ctx, unsigned char *md);
  141. int (*copy) (EVP_MD_CTX *to, const EVP_MD_CTX *from);
  142. int (*cleanup) (EVP_MD_CTX *ctx);
  143. int block_size;
  144. int ctx_size; /* how big does the ctx->md_data need to be */
  145. /* control function */
  146. int (*md_ctrl) (EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
  147. } /* EVP_MD */ ;
  148. struct evp_cipher_st {
  149. int nid;
  150. int block_size;
  151. /* Default value for variable length ciphers */
  152. int key_len;
  153. int iv_len;
  154. /* Various flags */
  155. unsigned long flags;
  156. /* init key */
  157. int (*init) (EVP_CIPHER_CTX *ctx, const unsigned char *key,
  158. const unsigned char *iv, int enc);
  159. /* encrypt/decrypt data */
  160. int (*do_cipher) (EVP_CIPHER_CTX *ctx, unsigned char *out,
  161. const unsigned char *in, size_t inl);
  162. /* cleanup ctx */
  163. int (*cleanup) (EVP_CIPHER_CTX *);
  164. /* how big ctx->cipher_data needs to be */
  165. int ctx_size;
  166. /* Populate a ASN1_TYPE with parameters */
  167. int (*set_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
  168. /* Get parameters from a ASN1_TYPE */
  169. int (*get_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
  170. /* Miscellaneous operations */
  171. int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr);
  172. /* Application data */
  173. void *app_data;
  174. } /* EVP_CIPHER */ ;
  175. /* Macros to code block cipher wrappers */
  176. /* Wrapper functions for each cipher mode */
  177. #define EVP_C_DATA(kstruct, ctx) \
  178. ((kstruct *)EVP_CIPHER_CTX_get_cipher_data(ctx))
  179. #define BLOCK_CIPHER_ecb_loop() \
  180. size_t i, bl; \
  181. bl = EVP_CIPHER_CTX_cipher(ctx)->block_size; \
  182. if (inl < bl) return 1;\
  183. inl -= bl; \
  184. for (i=0; i <= inl; i+=bl)
  185. #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
  186. static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  187. {\
  188. BLOCK_CIPHER_ecb_loop() \
  189. cprefix##_ecb_encrypt(in + i, out + i, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_encrypting(ctx)); \
  190. return 1;\
  191. }
  192. #define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
  193. #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
  194. static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  195. {\
  196. while(inl>=EVP_MAXCHUNK) {\
  197. int num = EVP_CIPHER_CTX_num(ctx);\
  198. cprefix##_ofb##cbits##_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), &num); \
  199. EVP_CIPHER_CTX_set_num(ctx, num);\
  200. inl-=EVP_MAXCHUNK;\
  201. in +=EVP_MAXCHUNK;\
  202. out+=EVP_MAXCHUNK;\
  203. }\
  204. if (inl) {\
  205. int num = EVP_CIPHER_CTX_num(ctx);\
  206. cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), &num); \
  207. EVP_CIPHER_CTX_set_num(ctx, num);\
  208. }\
  209. return 1;\
  210. }
  211. #define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
  212. static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  213. {\
  214. while(inl>=EVP_MAXCHUNK) \
  215. {\
  216. cprefix##_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));\
  217. inl-=EVP_MAXCHUNK;\
  218. in +=EVP_MAXCHUNK;\
  219. out+=EVP_MAXCHUNK;\
  220. }\
  221. if (inl)\
  222. cprefix##_cbc_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));\
  223. return 1;\
  224. }
  225. #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
  226. static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  227. {\
  228. size_t chunk = EVP_MAXCHUNK;\
  229. if (cbits == 1) chunk >>= 3;\
  230. if (inl < chunk) chunk = inl;\
  231. while (inl && inl >= chunk)\
  232. {\
  233. int num = EVP_CIPHER_CTX_num(ctx);\
  234. cprefix##_cfb##cbits##_encrypt(in, out, (long) \
  235. ((cbits == 1) \
  236. && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) \
  237. ? chunk*8 : chunk), \
  238. &EVP_C_DATA(kstruct, ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx),\
  239. &num, EVP_CIPHER_CTX_encrypting(ctx));\
  240. EVP_CIPHER_CTX_set_num(ctx, num);\
  241. inl -= chunk;\
  242. in += chunk;\
  243. out += chunk;\
  244. if (inl < chunk) chunk = inl;\
  245. }\
  246. return 1;\
  247. }
  248. #define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
  249. BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
  250. BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
  251. BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
  252. BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
  253. #define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
  254. key_len, iv_len, flags, init_key, cleanup, \
  255. set_asn1, get_asn1, ctrl) \
  256. static const EVP_CIPHER cname##_##mode = { \
  257. nid##_##nmode, block_size, key_len, iv_len, \
  258. flags | EVP_CIPH_##MODE##_MODE, \
  259. init_key, \
  260. cname##_##mode##_cipher, \
  261. cleanup, \
  262. sizeof(kstruct), \
  263. set_asn1, get_asn1,\
  264. ctrl, \
  265. NULL \
  266. }; \
  267. const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
  268. #define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
  269. iv_len, flags, init_key, cleanup, set_asn1, \
  270. get_asn1, ctrl) \
  271. BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
  272. iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
  273. #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
  274. iv_len, cbits, flags, init_key, cleanup, \
  275. set_asn1, get_asn1, ctrl) \
  276. BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
  277. key_len, iv_len, flags, init_key, cleanup, set_asn1, \
  278. get_asn1, ctrl)
  279. #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
  280. iv_len, cbits, flags, init_key, cleanup, \
  281. set_asn1, get_asn1, ctrl) \
  282. BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
  283. key_len, iv_len, flags, init_key, cleanup, set_asn1, \
  284. get_asn1, ctrl)
  285. #define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
  286. flags, init_key, cleanup, set_asn1, \
  287. get_asn1, ctrl) \
  288. BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
  289. 0, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
  290. #define BLOCK_CIPHER_defs(cname, kstruct, \
  291. nid, block_size, key_len, iv_len, cbits, flags, \
  292. init_key, cleanup, set_asn1, get_asn1, ctrl) \
  293. BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
  294. init_key, cleanup, set_asn1, get_asn1, ctrl) \
  295. BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
  296. flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
  297. BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
  298. flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
  299. BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, flags, \
  300. init_key, cleanup, set_asn1, get_asn1, ctrl)
  301. /*-
  302. #define BLOCK_CIPHER_defs(cname, kstruct, \
  303. nid, block_size, key_len, iv_len, flags,\
  304. init_key, cleanup, set_asn1, get_asn1, ctrl)\
  305. static const EVP_CIPHER cname##_cbc = {\
  306. nid##_cbc, block_size, key_len, iv_len, \
  307. flags | EVP_CIPH_CBC_MODE,\
  308. init_key,\
  309. cname##_cbc_cipher,\
  310. cleanup,\
  311. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  312. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  313. set_asn1, get_asn1,\
  314. ctrl, \
  315. NULL \
  316. };\
  317. const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
  318. static const EVP_CIPHER cname##_cfb = {\
  319. nid##_cfb64, 1, key_len, iv_len, \
  320. flags | EVP_CIPH_CFB_MODE,\
  321. init_key,\
  322. cname##_cfb_cipher,\
  323. cleanup,\
  324. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  325. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  326. set_asn1, get_asn1,\
  327. ctrl,\
  328. NULL \
  329. };\
  330. const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
  331. static const EVP_CIPHER cname##_ofb = {\
  332. nid##_ofb64, 1, key_len, iv_len, \
  333. flags | EVP_CIPH_OFB_MODE,\
  334. init_key,\
  335. cname##_ofb_cipher,\
  336. cleanup,\
  337. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  338. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  339. set_asn1, get_asn1,\
  340. ctrl,\
  341. NULL \
  342. };\
  343. const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
  344. static const EVP_CIPHER cname##_ecb = {\
  345. nid##_ecb, block_size, key_len, iv_len, \
  346. flags | EVP_CIPH_ECB_MODE,\
  347. init_key,\
  348. cname##_ecb_cipher,\
  349. cleanup,\
  350. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  351. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  352. set_asn1, get_asn1,\
  353. ctrl,\
  354. NULL \
  355. };\
  356. const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
  357. */
  358. #define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
  359. block_size, key_len, iv_len, cbits, \
  360. flags, init_key, \
  361. cleanup, set_asn1, get_asn1, ctrl) \
  362. BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
  363. BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
  364. cbits, flags, init_key, cleanup, set_asn1, \
  365. get_asn1, ctrl)
  366. #define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
  367. BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
  368. BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
  369. NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
  370. (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
  371. cipher##_init_key, NULL, NULL, NULL, NULL)
  372. # ifndef OPENSSL_NO_EC
  373. #define X25519_KEYLEN 32
  374. #define X448_KEYLEN 56
  375. #define ED448_KEYLEN 57
  376. #define MAX_KEYLEN ED448_KEYLEN
  377. typedef struct {
  378. unsigned char pubkey[MAX_KEYLEN];
  379. unsigned char *privkey;
  380. } ECX_KEY;
  381. #endif
  382. /*
  383. * Type needs to be a bit field Sub-type needs to be for variations on the
  384. * method, as in, can it do arbitrary encryption....
  385. */
  386. struct evp_pkey_st {
  387. int type;
  388. int save_type;
  389. CRYPTO_REF_COUNT references;
  390. const EVP_PKEY_ASN1_METHOD *ameth;
  391. ENGINE *engine;
  392. ENGINE *pmeth_engine; /* If not NULL public key ENGINE to use */
  393. union {
  394. void *ptr;
  395. # ifndef OPENSSL_NO_RSA
  396. struct rsa_st *rsa; /* RSA */
  397. # endif
  398. # ifndef OPENSSL_NO_DSA
  399. struct dsa_st *dsa; /* DSA */
  400. # endif
  401. # ifndef OPENSSL_NO_DH
  402. struct dh_st *dh; /* DH */
  403. # endif
  404. # ifndef OPENSSL_NO_EC
  405. struct ec_key_st *ec; /* ECC */
  406. ECX_KEY *ecx; /* X25519, X448, Ed25519, Ed448 */
  407. # endif
  408. } pkey;
  409. int save_parameters;
  410. STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
  411. CRYPTO_RWLOCK *lock;
  412. } /* EVP_PKEY */ ;
  413. void openssl_add_all_ciphers_int(void);
  414. void openssl_add_all_digests_int(void);
  415. void openssl_add_all_macs_int(void);
  416. void evp_cleanup_int(void);
  417. void evp_app_cleanup_int(void);
  418. /* Pulling defines out of C source files */
  419. #define EVP_RC4_KEY_SIZE 16
  420. #ifndef TLS1_1_VERSION
  421. # define TLS1_1_VERSION 0x0302
  422. #endif
  423. void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags);
  424. /* EVP_ENCODE_CTX flags */
  425. /* Don't generate new lines when encoding */
  426. #define EVP_ENCODE_CTX_NO_NEWLINES 1
  427. /* Use the SRP base64 alphabet instead of the standard one */
  428. #define EVP_ENCODE_CTX_USE_SRP_ALPHABET 2