2019-09-25 08:46:39 +08:00
|
|
|
/*
|
2020-04-23 20:55:52 +08:00
|
|
|
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2019-09-25 08:46:39 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Dispatch functions for RC4 ciphers */
|
|
|
|
|
2020-01-14 07:38:09 +08:00
|
|
|
/*
|
|
|
|
* RC4 low level APIs are deprecated for public use, but still ok for internal
|
|
|
|
* use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2019-09-25 08:46:39 +08:00
|
|
|
#include "cipher_rc4.h"
|
2019-10-04 21:20:48 +08:00
|
|
|
#include "prov/implementations.h"
|
2020-09-08 10:56:34 +08:00
|
|
|
#include "prov/providercommon.h"
|
2019-09-25 08:46:39 +08:00
|
|
|
|
|
|
|
/* TODO (3.0) Figure out what flags are required */
|
|
|
|
#define RC4_FLAGS EVP_CIPH_FLAG_DEFAULT_ASN1
|
|
|
|
|
2020-06-21 07:19:16 +08:00
|
|
|
static OSSL_FUNC_cipher_freectx_fn rc4_freectx;
|
|
|
|
static OSSL_FUNC_cipher_dupctx_fn rc4_dupctx;
|
2019-09-25 08:46:39 +08:00
|
|
|
|
|
|
|
static void rc4_freectx(void *vctx)
|
|
|
|
{
|
|
|
|
PROV_RC4_CTX *ctx = (PROV_RC4_CTX *)vctx;
|
|
|
|
|
2020-06-23 23:47:31 +08:00
|
|
|
cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
|
2019-09-25 08:46:39 +08:00
|
|
|
OPENSSL_clear_free(ctx, sizeof(*ctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *rc4_dupctx(void *ctx)
|
|
|
|
{
|
|
|
|
PROV_RC4_CTX *in = (PROV_RC4_CTX *)ctx;
|
2020-09-08 10:56:34 +08:00
|
|
|
PROV_RC4_CTX *ret;
|
2019-09-25 08:46:39 +08:00
|
|
|
|
2020-09-08 10:56:34 +08:00
|
|
|
if (!ossl_prov_is_running())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = OPENSSL_malloc(sizeof(*ret));
|
2019-09-25 08:46:39 +08:00
|
|
|
if (ret == NULL) {
|
|
|
|
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*ret = *in;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IMPLEMENT_cipher(alg, UCALG, flags, kbits, blkbits, ivbits, typ) \
|
2020-06-21 07:19:16 +08:00
|
|
|
static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_get_params; \
|
2019-09-25 08:46:39 +08:00
|
|
|
static int alg##_##kbits##_get_params(OSSL_PARAM params[]) \
|
|
|
|
{ \
|
|
|
|
return cipher_generic_get_params(params, 0, flags, \
|
|
|
|
kbits, blkbits, ivbits); \
|
|
|
|
} \
|
2020-06-21 07:19:16 +08:00
|
|
|
static OSSL_FUNC_cipher_newctx_fn alg##_##kbits##_newctx; \
|
2019-09-25 08:46:39 +08:00
|
|
|
static void * alg##_##kbits##_newctx(void *provctx) \
|
|
|
|
{ \
|
2020-09-08 10:56:34 +08:00
|
|
|
PROV_##UCALG##_CTX *ctx; \
|
|
|
|
if (!ossl_prov_is_running()) \
|
|
|
|
return NULL; \
|
|
|
|
ctx = OPENSSL_zalloc(sizeof(*ctx)); \
|
2019-09-25 08:46:39 +08:00
|
|
|
if (ctx != NULL) { \
|
|
|
|
cipher_generic_initkey(ctx, kbits, blkbits, ivbits, 0, flags, \
|
2020-09-28 10:47:04 +08:00
|
|
|
ossl_prov_cipher_hw_##alg(kbits), NULL); \
|
2019-09-25 08:46:39 +08:00
|
|
|
} \
|
|
|
|
return ctx; \
|
|
|
|
} \
|
2020-09-28 10:28:29 +08:00
|
|
|
const OSSL_DISPATCH ossl_##alg##kbits##_functions[] = { \
|
2019-09-25 08:46:39 +08:00
|
|
|
{ OSSL_FUNC_CIPHER_NEWCTX, \
|
|
|
|
(void (*)(void)) alg##_##kbits##_newctx }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_FREECTX, (void (*)(void)) alg##_freectx }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void)) alg##_dupctx }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))cipher_generic_einit }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))cipher_generic_dinit }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))cipher_generic_##typ##_update },\
|
|
|
|
{ OSSL_FUNC_CIPHER_FINAL, (void (*)(void))cipher_generic_##typ##_final }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_GET_PARAMS, \
|
|
|
|
(void (*)(void)) alg##_##kbits##_get_params }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
|
|
|
|
(void (*)(void))cipher_generic_get_ctx_params }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
|
2019-11-15 00:05:19 +08:00
|
|
|
(void (*)(void))cipher_var_keylen_set_ctx_params }, \
|
2019-09-25 08:46:39 +08:00
|
|
|
{ OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
|
|
|
|
(void (*)(void))cipher_generic_gettable_params }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
|
|
|
|
(void (*)(void))cipher_generic_gettable_ctx_params }, \
|
|
|
|
{ OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
|
2019-11-15 00:05:19 +08:00
|
|
|
(void (*)(void))cipher_var_keylen_settable_ctx_params }, \
|
2019-09-25 08:46:39 +08:00
|
|
|
{ 0, NULL } \
|
|
|
|
};
|
|
|
|
|
2020-09-28 10:28:29 +08:00
|
|
|
/* ossl_rc440_functions */
|
2019-10-05 09:42:32 +08:00
|
|
|
IMPLEMENT_cipher(rc4, RC4, EVP_CIPH_VARIABLE_LENGTH, 40, 8, 0, stream)
|
2020-09-28 10:28:29 +08:00
|
|
|
/* ossl_rc4128_functions */
|
2019-10-05 09:42:32 +08:00
|
|
|
IMPLEMENT_cipher(rc4, RC4, EVP_CIPH_VARIABLE_LENGTH, 128, 8, 0, stream)
|