diff options
Diffstat (limited to 'providers/implementations/ciphers/cipher_rc2.c')
-rw-r--r-- | providers/implementations/ciphers/cipher_rc2.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/providers/implementations/ciphers/cipher_rc2.c b/providers/implementations/ciphers/cipher_rc2.c index d78b044247..f8a18462af 100644 --- a/providers/implementations/ciphers/cipher_rc2.c +++ b/providers/implementations/ciphers/cipher_rc2.c @@ -25,10 +25,13 @@ #define RC2_128_MAGIC 0x3a #define RC2_FLAGS PROV_CIPHER_FLAG_VARIABLE_LENGTH +static OSSL_FUNC_cipher_encrypt_init_fn rc2_einit; +static OSSL_FUNC_cipher_decrypt_init_fn rc2_dinit; static OSSL_FUNC_cipher_freectx_fn rc2_freectx; static OSSL_FUNC_cipher_dupctx_fn rc2_dupctx; static OSSL_FUNC_cipher_gettable_ctx_params_fn rc2_gettable_ctx_params; static OSSL_FUNC_cipher_settable_ctx_params_fn rc2_settable_ctx_params; +static OSSL_FUNC_cipher_set_ctx_params_fn rc2_set_ctx_params; static void rc2_freectx(void *vctx) { @@ -84,6 +87,24 @@ static int rc2_magic_to_keybits(int magic) return 0; } +static int rc2_einit(void *ctx, const unsigned char *key, size_t keylen, + const unsigned char *iv, size_t ivlen, + const OSSL_PARAM params[]) +{ + if (!ossl_cipher_generic_einit(ctx, key, keylen, iv, ivlen, NULL)) + return 0; + return rc2_set_ctx_params(ctx, params); +} + +static int rc2_dinit(void *ctx, const unsigned char *key, size_t keylen, + const unsigned char *iv, size_t ivlen, + const OSSL_PARAM params[]) +{ + if (!ossl_cipher_generic_dinit(ctx, key, keylen, iv, ivlen, NULL)) + return 0; + return rc2_set_ctx_params(ctx, params); +} + static int rc2_get_ctx_params(void *vctx, OSSL_PARAM params[]) { PROV_RC2_CTX *ctx = (PROV_RC2_CTX *)vctx; @@ -138,11 +159,14 @@ static int rc2_get_ctx_params(void *vctx, OSSL_PARAM params[]) return 1; } -static int rc2_set_ctx_params(void *vctx, OSSL_PARAM params[]) +static int rc2_set_ctx_params(void *vctx, const OSSL_PARAM params[]) { PROV_RC2_CTX *ctx = (PROV_RC2_CTX *)vctx; const OSSL_PARAM *p; + if (params == NULL) + return 1; + if (!ossl_cipher_var_keylen_set_ctx_params(vctx, params)) return 0; p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_RC2_KEYBITS); @@ -152,7 +176,7 @@ static int rc2_set_ctx_params(void *vctx, OSSL_PARAM params[]) return 0; } } - p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_ALG_ID); + p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_ALG_ID); if (p != NULL) { ASN1_TYPE *type = NULL; long num = 0; @@ -222,8 +246,8 @@ const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \ (void (*)(void)) alg##_##kbits##_##lcmode##_newctx }, \ { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) alg##_freectx }, \ { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) alg##_dupctx }, \ - { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_cipher_generic_einit }, \ - { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_cipher_generic_dinit }, \ + { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))rc2_einit }, \ + { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))rc2_dinit }, \ { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))ossl_cipher_generic_##typ##_update },\ { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))ossl_cipher_generic_##typ##_final }, \ { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher }, \ |