]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_rc4.c
Make the naming scheme for dispatched functions more consistent
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_rc4.c
CommitLineData
bafde183 1/*
33388b44 2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
bafde183
SL
3 *
4 * Licensed under the Apache License 2.0 (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/* Dispatch functions for RC4 ciphers */
11
a8fca728
P
12/*
13 * RC4 low level APIs are deprecated for public use, but still ok for internal
14 * use.
15 */
16#include "internal/deprecated.h"
17
bafde183 18#include "cipher_rc4.h"
af3e7e1b 19#include "prov/implementations.h"
bafde183
SL
20
21/* TODO (3.0) Figure out what flags are required */
22#define RC4_FLAGS EVP_CIPH_FLAG_DEFAULT_ASN1
23
363b1e5d
DMSP
24static OSSL_FUNC_cipher_freectx_fn rc4_freectx;
25static OSSL_FUNC_cipher_dupctx_fn rc4_dupctx;
bafde183
SL
26
27static void rc4_freectx(void *vctx)
28{
29 PROV_RC4_CTX *ctx = (PROV_RC4_CTX *)vctx;
30
31 OPENSSL_clear_free(ctx, sizeof(*ctx));
32}
33
34static void *rc4_dupctx(void *ctx)
35{
36 PROV_RC4_CTX *in = (PROV_RC4_CTX *)ctx;
37 PROV_RC4_CTX *ret = OPENSSL_malloc(sizeof(*ret));
38
39 if (ret == NULL) {
40 ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
41 return NULL;
42 }
43 *ret = *in;
44
45 return ret;
46}
47
48#define IMPLEMENT_cipher(alg, UCALG, flags, kbits, blkbits, ivbits, typ) \
363b1e5d 49static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_get_params; \
bafde183
SL
50static int alg##_##kbits##_get_params(OSSL_PARAM params[]) \
51{ \
52 return cipher_generic_get_params(params, 0, flags, \
53 kbits, blkbits, ivbits); \
54} \
363b1e5d 55static OSSL_FUNC_cipher_newctx_fn alg##_##kbits##_newctx; \
bafde183
SL
56static void * alg##_##kbits##_newctx(void *provctx) \
57{ \
58 PROV_##UCALG##_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); \
59 if (ctx != NULL) { \
60 cipher_generic_initkey(ctx, kbits, blkbits, ivbits, 0, flags, \
61 PROV_CIPHER_HW_##alg(kbits), NULL); \
62 } \
63 return ctx; \
64} \
65const OSSL_DISPATCH alg##kbits##_functions[] = { \
66 { OSSL_FUNC_CIPHER_NEWCTX, \
67 (void (*)(void)) alg##_##kbits##_newctx }, \
68 { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) alg##_freectx }, \
69 { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) alg##_dupctx }, \
70 { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))cipher_generic_einit }, \
71 { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))cipher_generic_dinit }, \
72 { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))cipher_generic_##typ##_update },\
73 { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))cipher_generic_##typ##_final }, \
74 { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher }, \
75 { OSSL_FUNC_CIPHER_GET_PARAMS, \
76 (void (*)(void)) alg##_##kbits##_get_params }, \
77 { OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
78 (void (*)(void))cipher_generic_get_ctx_params }, \
79 { OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
d23adad1 80 (void (*)(void))cipher_var_keylen_set_ctx_params }, \
bafde183
SL
81 { OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
82 (void (*)(void))cipher_generic_gettable_params }, \
83 { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
84 (void (*)(void))cipher_generic_gettable_ctx_params }, \
85 { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
d23adad1 86 (void (*)(void))cipher_var_keylen_settable_ctx_params }, \
bafde183
SL
87 { 0, NULL } \
88};
89
90/* rc440_functions */
74997e7e 91IMPLEMENT_cipher(rc4, RC4, EVP_CIPH_VARIABLE_LENGTH, 40, 8, 0, stream)
bafde183 92/* rc4128_functions */
74997e7e 93IMPLEMENT_cipher(rc4, RC4, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 0, stream)