From: tb Date: Tue, 2 Jan 2024 21:12:25 +0000 (+0000) Subject: Move down EVP_CIPHER_CTX accessors expose EVP_CIPHER internals X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=35c9a4a5cf4a7bab4f15fec0dbaa617ec1372268;p=openbsd Move down EVP_CIPHER_CTX accessors expose EVP_CIPHER internals These confusingly named getters were added "for convenience" in 1.1. They fit best next to the EVP_CIPHER API. --- diff --git a/lib/libcrypto/evp/evp_cipher.c b/lib/libcrypto/evp/evp_cipher.c index 367cfb6e673..d8e802e94ba 100644 --- a/lib/libcrypto/evp/evp_cipher.c +++ b/lib/libcrypto/evp/evp_cipher.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_cipher.c,v 1.10 2024/01/02 20:48:40 tb Exp $ */ +/* $OpenBSD: evp_cipher.c,v 1.11 2024/01/02 21:12:25 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -740,12 +740,6 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) return 1; } -int -EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) -{ - return ctx->cipher->block_size; -} - const EVP_CIPHER * EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx) { @@ -758,12 +752,6 @@ EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx) return ctx->encrypt; } -unsigned long -EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) -{ - return ctx->cipher->flags; -} - void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx) { @@ -793,25 +781,6 @@ EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data) return old_cipher_data; } -int -EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) -{ - int iv_length = 0; - - if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_IV_LENGTH) == 0) - return ctx->cipher->iv_len; - - /* - * XXX - sanity would suggest to pass the size of the pointer along, - * but unfortunately we have to match the other crowd. - */ - if (EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0, - &iv_length) != 1) - return -1; - - return iv_length; -} - unsigned char * EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx) { @@ -824,12 +793,6 @@ EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) return ctx->key_len; } -int -EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) -{ - return ctx->cipher->nid; -} - int EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv, size_t len) { @@ -886,6 +849,47 @@ EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags) return (ctx->flags & flags); } +/* + * EVP_CIPHER_CTX getters that reach into the cipher attachted to the contex. + */ + +int +EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx) +{ + return ctx->cipher->nid; +} + +int +EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx) +{ + return ctx->cipher->block_size; +} + +int +EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) +{ + int iv_length = 0; + + if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_IV_LENGTH) == 0) + return ctx->cipher->iv_len; + + /* + * XXX - sanity would suggest to pass the size of the pointer along, + * but unfortunately we have to match the other crowd. + */ + if (EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0, + &iv_length) != 1) + return -1; + + return iv_length; +} + +unsigned long +EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx) +{ + return ctx->cipher->flags; +} + /* * Used by CMS and its predecessors. Only GOST and RC2 have a custom method. */