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