X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Finclude%2Finternal%2Fevp_int.h;h=af273f2bf3e940fb8493665e7f7c48666748bab1;hp=ab8ce00e47f06ac044a496e842d37f91a031c881;hb=4cae07fef3b24bee1646f6085c52175ef3755d5b;hpb=8c8cf0d96240663749897b44898b3964fa3363e0 diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index ab8ce00e47..af273f2bf3 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -18,6 +18,11 @@ #define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400 struct evp_pkey_ctx_st { + EVP_KEYEXCH *exchange; + void *exchprovctx; + + /* Legacy fields below */ + /* Method associated with this operation */ const EVP_PKEY_METHOD *pmeth; /* Engine that implements this method or NULL if builtin */ @@ -118,7 +123,7 @@ typedef struct evp_mac_impl_st EVP_MAC_IMPL; struct evp_mac_st { int type; EVP_MAC_IMPL *(*new) (void); - int (*copy) (EVP_MAC_IMPL *macdst, EVP_MAC_IMPL *macsrc); + EVP_MAC_IMPL *(*dup) (const EVP_MAC_IMPL *macsrc); void (*free) (EVP_MAC_IMPL *macctx); size_t (*size) (EVP_MAC_IMPL *macctx); int (*init) (EVP_MAC_IMPL *macctx); @@ -151,10 +156,11 @@ const EVP_MD *evp_keccak_kmac256(void); * object database. */ int EVP_add_mac(const EVP_MAC *mac); +int EVP_add_kdf(const EVP_KDF *kdf); /* struct evp_kdf_impl_st is defined by the implementation */ typedef struct evp_kdf_impl_st EVP_KDF_IMPL; -typedef struct { +struct evp_kdf_st { int type; EVP_KDF_IMPL *(*new) (void); void (*free) (EVP_KDF_IMPL *impl); @@ -163,14 +169,16 @@ typedef struct { int (*ctrl_str) (EVP_KDF_IMPL *impl, const char *type, const char *value); size_t (*size) (EVP_KDF_IMPL *impl); int (*derive) (EVP_KDF_IMPL *impl, unsigned char *key, size_t keylen); -} EVP_KDF_METHOD; +}; -extern const EVP_KDF_METHOD pbkdf2_kdf_meth; -extern const EVP_KDF_METHOD scrypt_kdf_meth; -extern const EVP_KDF_METHOD tls1_prf_kdf_meth; -extern const EVP_KDF_METHOD hkdf_kdf_meth; -extern const EVP_KDF_METHOD sshkdf_kdf_meth; -extern const EVP_KDF_METHOD ss_kdf_meth; +extern const EVP_KDF pbkdf2_kdf_meth; +extern const EVP_KDF scrypt_kdf_meth; +extern const EVP_KDF tls1_prf_kdf_meth; +extern const EVP_KDF hkdf_kdf_meth; +extern const EVP_KDF sshkdf_kdf_meth; +extern const EVP_KDF ss_kdf_meth; +extern const EVP_KDF x963_kdf_meth; +extern const EVP_KDF x942_kdf_meth; struct evp_md_st { /* nid */ @@ -204,15 +212,22 @@ struct evp_md_st { OSSL_OP_digest_freectx_fn *freectx; OSSL_OP_digest_dupctx_fn *dupctx; OSSL_OP_digest_size_fn *size; + OSSL_OP_digest_block_size_fn *dblock_size; + OSSL_OP_digest_set_params_fn *set_params; + OSSL_OP_digest_get_params_fn *get_params; } /* EVP_MD */ ; struct evp_cipher_st { int nid; + int block_size; /* Default value for variable length ciphers */ int key_len; int iv_len; + + /* Legacy structure members */ + /* TODO(3.0): Remove these */ /* Various flags */ unsigned long flags; /* init key */ @@ -233,6 +248,23 @@ struct evp_cipher_st { int (*ctrl) (EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Application data */ void *app_data; + + /* New structure members */ + /* TODO(3.0): Remove above comment when legacy has gone */ + OSSL_PROVIDER *prov; + CRYPTO_REF_COUNT refcnt; + CRYPTO_RWLOCK *lock; + OSSL_OP_cipher_newctx_fn *newctx; + OSSL_OP_cipher_encrypt_init_fn *einit; + OSSL_OP_cipher_decrypt_init_fn *dinit; + OSSL_OP_cipher_update_fn *cupdate; + OSSL_OP_cipher_final_fn *cfinal; + OSSL_OP_cipher_cipher_fn *ccipher; + OSSL_OP_cipher_freectx_fn *freectx; + OSSL_OP_cipher_dupctx_fn *dupctx; + OSSL_OP_cipher_get_params_fn *get_params; + OSSL_OP_cipher_ctx_get_params_fn *ctx_get_params; + OSSL_OP_cipher_ctx_set_params_fn *ctx_set_params; } /* EVP_CIPHER */ ; /* Macros to code block cipher wrappers */ @@ -472,9 +504,9 @@ typedef struct { * method, as in, can it do arbitrary encryption.... */ struct evp_pkey_st { + /* == Legacy attributes == */ int type; int save_type; - CRYPTO_REF_COUNT references; const EVP_PKEY_ASN1_METHOD *ameth; ENGINE *engine; ENGINE *pmeth_engine; /* If not NULL public key ENGINE to use */ @@ -494,18 +526,44 @@ struct evp_pkey_st { ECX_KEY *ecx; /* X25519, X448, Ed25519, Ed448 */ # endif } pkey; - int save_parameters; - STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ + + /* == Common attributes == */ + CRYPTO_REF_COUNT references; CRYPTO_RWLOCK *lock; + STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ + int save_parameters; + + /* == Provider attributes == */ + /* + * To support transparent export/import between providers that + * support the methods for it, and still not having to do the + * export/import every time a key is used, we maintain a cache + * of imported key, indexed by provider address. + * pkeys[0] is *always* the "original" key. + */ + struct { + EVP_KEYMGMT *keymgmt; + void *provkey; + } pkeys[10]; + /* + * If there is a legacy key assigned to this structure, we keep + * a copy of that key's dirty count. + */ + size_t dirty_cnt_copy; } /* EVP_PKEY */ ; void openssl_add_all_ciphers_int(void); void openssl_add_all_digests_int(void); void openssl_add_all_macs_int(void); +void openssl_add_all_kdfs_int(void); void evp_cleanup_int(void); void evp_app_cleanup_int(void); +/* KEYMGMT helper functions */ +void *evp_keymgmt_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt); +void evp_keymgmt_clear_pkey_cache(EVP_PKEY *pk); + /* Pulling defines out of C source files */ #define EVP_RC4_KEY_SIZE 16