evp_int.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 hmac_meth;
  122. extern const EVP_MAC siphash_meth;
  123. /*
  124. * This function is internal for now, but can be made external when needed.
  125. * The documentation would read:
  126. *
  127. * EVP_add_mac() adds the MAC implementation C<mac> to the internal
  128. * object database.
  129. */
  130. int EVP_add_mac(const EVP_MAC *mac);
  131. struct evp_md_st {
  132. int type;
  133. int pkey_type;
  134. int md_size;
  135. unsigned long flags;
  136. int (*init) (EVP_MD_CTX *ctx);
  137. int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count);
  138. int (*final) (EVP_MD_CTX *ctx, unsigned char *md);
  139. int (*copy) (EVP_MD_CTX *to, const EVP_MD_CTX *from);
  140. int (*cleanup) (EVP_MD_CTX *ctx);
  141. int block_size;
  142. int ctx_size; /* how big does the ctx->md_data need to be */
  143. /* control function */
  144. int (*md_ctrl) (EVP_MD_CTX *ctx, int cmd, int p1, void *p2);
  145. } /* EVP_MD */ ;
  146. struct evp_cipher_st {
  147. int nid;
  148. int block_size;
  149. /* Default value for variable length ciphers */
  150. int key_len;
  151. int iv_len;
  152. /* Various flags */
  153. unsigned long flags;
  154. /* init key */
  155. int (*init) (EVP_CIPHER_CTX *ctx, const unsigned char *key,
  156. const unsigned char *iv, int enc);
  157. /* encrypt/decrypt data */
  158. int (*do_cipher) (EVP_CIPHER_CTX *ctx, unsigned char *out,
  159. const unsigned char *in, size_t inl);
  160. /* cleanup ctx */
  161. int (*cleanup) (EVP_CIPHER_CTX *);
  162. /* how big ctx->cipher_data needs to be */
  163. int ctx_size;
  164. /* Populate a ASN1_TYPE with parameters */
  165. int (*set_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
  166. /* Get parameters from a ASN1_TYPE */
  167. int (*get_asn1_parameters) (EVP_CIPHER_CTX *, ASN1_TYPE *);
  168. /* Miscellaneous operations */
  169. int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr);
  170. /* Application data */
  171. void *app_data;
  172. } /* EVP_CIPHER */ ;
  173. /* Macros to code block cipher wrappers */
  174. /* Wrapper functions for each cipher mode */
  175. #define EVP_C_DATA(kstruct, ctx) \
  176. ((kstruct *)EVP_CIPHER_CTX_get_cipher_data(ctx))
  177. #define BLOCK_CIPHER_ecb_loop() \
  178. size_t i, bl; \
  179. bl = EVP_CIPHER_CTX_cipher(ctx)->block_size; \
  180. if (inl < bl) return 1;\
  181. inl -= bl; \
  182. for (i=0; i <= inl; i+=bl)
  183. #define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
  184. static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  185. {\
  186. BLOCK_CIPHER_ecb_loop() \
  187. cprefix##_ecb_encrypt(in + i, out + i, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_encrypting(ctx)); \
  188. return 1;\
  189. }
  190. #define EVP_MAXCHUNK ((size_t)1<<(sizeof(long)*8-2))
  191. #define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
  192. static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  193. {\
  194. while(inl>=EVP_MAXCHUNK) {\
  195. int num = EVP_CIPHER_CTX_num(ctx);\
  196. cprefix##_ofb##cbits##_encrypt(in, out, (long)EVP_MAXCHUNK, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), &num); \
  197. EVP_CIPHER_CTX_set_num(ctx, num);\
  198. inl-=EVP_MAXCHUNK;\
  199. in +=EVP_MAXCHUNK;\
  200. out+=EVP_MAXCHUNK;\
  201. }\
  202. if (inl) {\
  203. int num = EVP_CIPHER_CTX_num(ctx);\
  204. cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), &num); \
  205. EVP_CIPHER_CTX_set_num(ctx, num);\
  206. }\
  207. return 1;\
  208. }
  209. #define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
  210. static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  211. {\
  212. while(inl>=EVP_MAXCHUNK) \
  213. {\
  214. 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));\
  215. inl-=EVP_MAXCHUNK;\
  216. in +=EVP_MAXCHUNK;\
  217. out+=EVP_MAXCHUNK;\
  218. }\
  219. if (inl)\
  220. cprefix##_cbc_encrypt(in, out, (long)inl, &EVP_C_DATA(kstruct,ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx), EVP_CIPHER_CTX_encrypting(ctx));\
  221. return 1;\
  222. }
  223. #define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
  224. static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) \
  225. {\
  226. size_t chunk = EVP_MAXCHUNK;\
  227. if (cbits == 1) chunk >>= 3;\
  228. if (inl < chunk) chunk = inl;\
  229. while (inl && inl >= chunk)\
  230. {\
  231. int num = EVP_CIPHER_CTX_num(ctx);\
  232. cprefix##_cfb##cbits##_encrypt(in, out, (long) \
  233. ((cbits == 1) \
  234. && !EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS) \
  235. ? chunk*8 : chunk), \
  236. &EVP_C_DATA(kstruct, ctx)->ksched, EVP_CIPHER_CTX_iv_noconst(ctx),\
  237. &num, EVP_CIPHER_CTX_encrypting(ctx));\
  238. EVP_CIPHER_CTX_set_num(ctx, num);\
  239. inl -= chunk;\
  240. in += chunk;\
  241. out += chunk;\
  242. if (inl < chunk) chunk = inl;\
  243. }\
  244. return 1;\
  245. }
  246. #define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
  247. BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
  248. BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
  249. BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
  250. BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
  251. #define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
  252. key_len, iv_len, flags, init_key, cleanup, \
  253. set_asn1, get_asn1, ctrl) \
  254. static const EVP_CIPHER cname##_##mode = { \
  255. nid##_##nmode, block_size, key_len, iv_len, \
  256. flags | EVP_CIPH_##MODE##_MODE, \
  257. init_key, \
  258. cname##_##mode##_cipher, \
  259. cleanup, \
  260. sizeof(kstruct), \
  261. set_asn1, get_asn1,\
  262. ctrl, \
  263. NULL \
  264. }; \
  265. const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
  266. #define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
  267. iv_len, flags, init_key, cleanup, set_asn1, \
  268. get_asn1, ctrl) \
  269. BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
  270. iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
  271. #define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, \
  272. iv_len, cbits, flags, init_key, cleanup, \
  273. set_asn1, get_asn1, ctrl) \
  274. BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
  275. key_len, iv_len, flags, init_key, cleanup, set_asn1, \
  276. get_asn1, ctrl)
  277. #define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, \
  278. iv_len, cbits, flags, init_key, cleanup, \
  279. set_asn1, get_asn1, ctrl) \
  280. BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, 1, \
  281. key_len, iv_len, flags, init_key, cleanup, set_asn1, \
  282. get_asn1, ctrl)
  283. #define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
  284. flags, init_key, cleanup, set_asn1, \
  285. get_asn1, ctrl) \
  286. BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
  287. 0, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
  288. #define BLOCK_CIPHER_defs(cname, kstruct, \
  289. nid, block_size, key_len, iv_len, cbits, flags, \
  290. init_key, cleanup, set_asn1, get_asn1, ctrl) \
  291. BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
  292. init_key, cleanup, set_asn1, get_asn1, ctrl) \
  293. BLOCK_CIPHER_def_cfb(cname, kstruct, nid, key_len, iv_len, cbits, \
  294. flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
  295. BLOCK_CIPHER_def_ofb(cname, kstruct, nid, key_len, iv_len, cbits, \
  296. flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
  297. BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, flags, \
  298. init_key, cleanup, set_asn1, get_asn1, ctrl)
  299. /*-
  300. #define BLOCK_CIPHER_defs(cname, kstruct, \
  301. nid, block_size, key_len, iv_len, flags,\
  302. init_key, cleanup, set_asn1, get_asn1, ctrl)\
  303. static const EVP_CIPHER cname##_cbc = {\
  304. nid##_cbc, block_size, key_len, iv_len, \
  305. flags | EVP_CIPH_CBC_MODE,\
  306. init_key,\
  307. cname##_cbc_cipher,\
  308. cleanup,\
  309. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  310. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  311. set_asn1, get_asn1,\
  312. ctrl, \
  313. NULL \
  314. };\
  315. const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
  316. static const EVP_CIPHER cname##_cfb = {\
  317. nid##_cfb64, 1, key_len, iv_len, \
  318. flags | EVP_CIPH_CFB_MODE,\
  319. init_key,\
  320. cname##_cfb_cipher,\
  321. cleanup,\
  322. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  323. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  324. set_asn1, get_asn1,\
  325. ctrl,\
  326. NULL \
  327. };\
  328. const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
  329. static const EVP_CIPHER cname##_ofb = {\
  330. nid##_ofb64, 1, key_len, iv_len, \
  331. flags | EVP_CIPH_OFB_MODE,\
  332. init_key,\
  333. cname##_ofb_cipher,\
  334. cleanup,\
  335. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  336. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  337. set_asn1, get_asn1,\
  338. ctrl,\
  339. NULL \
  340. };\
  341. const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
  342. static const EVP_CIPHER cname##_ecb = {\
  343. nid##_ecb, block_size, key_len, iv_len, \
  344. flags | EVP_CIPH_ECB_MODE,\
  345. init_key,\
  346. cname##_ecb_cipher,\
  347. cleanup,\
  348. sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
  349. sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
  350. set_asn1, get_asn1,\
  351. ctrl,\
  352. NULL \
  353. };\
  354. const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
  355. */
  356. #define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
  357. block_size, key_len, iv_len, cbits, \
  358. flags, init_key, \
  359. cleanup, set_asn1, get_asn1, ctrl) \
  360. BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
  361. BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
  362. cbits, flags, init_key, cleanup, set_asn1, \
  363. get_asn1, ctrl)
  364. #define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
  365. BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
  366. BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
  367. NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
  368. (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
  369. cipher##_init_key, NULL, NULL, NULL, NULL)
  370. # ifndef OPENSSL_NO_EC
  371. #define X25519_KEYLEN 32
  372. #define X448_KEYLEN 56
  373. #define ED448_KEYLEN 57
  374. #define MAX_KEYLEN ED448_KEYLEN
  375. typedef struct {
  376. unsigned char pubkey[MAX_KEYLEN];
  377. unsigned char *privkey;
  378. } ECX_KEY;
  379. #endif
  380. /*
  381. * Type needs to be a bit field Sub-type needs to be for variations on the
  382. * method, as in, can it do arbitrary encryption....
  383. */
  384. struct evp_pkey_st {
  385. int type;
  386. int save_type;
  387. CRYPTO_REF_COUNT references;
  388. const EVP_PKEY_ASN1_METHOD *ameth;
  389. ENGINE *engine;
  390. ENGINE *pmeth_engine; /* If not NULL public key ENGINE to use */
  391. union {
  392. void *ptr;
  393. # ifndef OPENSSL_NO_RSA
  394. struct rsa_st *rsa; /* RSA */
  395. # endif
  396. # ifndef OPENSSL_NO_DSA
  397. struct dsa_st *dsa; /* DSA */
  398. # endif
  399. # ifndef OPENSSL_NO_DH
  400. struct dh_st *dh; /* DH */
  401. # endif
  402. # ifndef OPENSSL_NO_EC
  403. struct ec_key_st *ec; /* ECC */
  404. ECX_KEY *ecx; /* X25519, X448, Ed25519, Ed448 */
  405. # endif
  406. } pkey;
  407. int save_parameters;
  408. STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
  409. CRYPTO_RWLOCK *lock;
  410. } /* EVP_PKEY */ ;
  411. void openssl_add_all_ciphers_int(void);
  412. void openssl_add_all_digests_int(void);
  413. void openssl_add_all_macs_int(void);
  414. void evp_cleanup_int(void);
  415. void evp_app_cleanup_int(void);
  416. /* Pulling defines out of C source files */
  417. #define EVP_RC4_KEY_SIZE 16
  418. #ifndef TLS1_1_VERSION
  419. # define TLS1_1_VERSION 0x0302
  420. #endif
  421. void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags);
  422. /* EVP_ENCODE_CTX flags */
  423. /* Don't generate new lines when encoding */
  424. #define EVP_ENCODE_CTX_NO_NEWLINES 1
  425. /* Use the SRP base64 alphabet instead of the standard one */
  426. #define EVP_ENCODE_CTX_USE_SRP_ALPHABET 2