mirror of
https://github.com/openssl/openssl.git
synced 2024-12-15 06:01:37 +08:00
7cc355c2e4
Added Algorithm names AES-128-CBC-CTS, AES-192-CBC-CTS and AES-256-CBC-CTS. CS1, CS2 and CS3 variants are supported. Only single shot updates are supported. The cipher returns the mode EVP_CIPH_CBC_MODE (Internally it shares the aes_cbc cipher code). This would allow existing code that uses AES_CBC to switch to the CTS variant without breaking code that tests for this mode. Because it shares the aes_cbc code the cts128.c functions could not be used directly. The cipher returns the flag EVP_CIPH_FLAG_CTS. EVP_CIPH_FLAG_FIPS & EVP_CIPH_FLAG_NON_FIPS_ALLOW have been deprecated. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/12094)
109 lines
5.2 KiB
C++
109 lines
5.2 KiB
C++
/*
|
|
* Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
|
|
*
|
|
* 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 AES CBC CTS ciphers */
|
|
|
|
#include "cipher_aes_cts.h"
|
|
#include "prov/providercommonerr.h"
|
|
|
|
static OSSL_FUNC_cipher_get_ctx_params_fn aes_cbc_cts_get_ctx_params;
|
|
static OSSL_FUNC_cipher_set_ctx_params_fn aes_cbc_cts_set_ctx_params;
|
|
static OSSL_FUNC_cipher_gettable_ctx_params_fn aes_cbc_cts_gettable_ctx_params;
|
|
static OSSL_FUNC_cipher_settable_ctx_params_fn aes_cbc_cts_settable_ctx_params;
|
|
|
|
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(aes_cbc_cts)
|
|
OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0),
|
|
CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(aes_cbc_cts)
|
|
|
|
static int aes_cbc_cts_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
|
{
|
|
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
|
OSSL_PARAM *p;
|
|
|
|
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CTS_MODE);
|
|
if (p != NULL) {
|
|
const char *name = aes_cbc_cts_mode_id2name(ctx->cts_mode);
|
|
|
|
if (name == NULL || !OSSL_PARAM_set_utf8_string(p, name)) {
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
}
|
|
return cipher_generic_get_ctx_params(vctx, params);
|
|
}
|
|
|
|
CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(aes_cbc_cts)
|
|
OSSL_PARAM_utf8_string(OSSL_CIPHER_PARAM_CTS_MODE, NULL, 0),
|
|
CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(aes_cbc_cts)
|
|
|
|
static int aes_cbc_cts_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
|
{
|
|
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
|
|
const OSSL_PARAM *p;
|
|
int id;
|
|
|
|
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_CTS_MODE);
|
|
if (p != NULL) {
|
|
if (p->data_type != OSSL_PARAM_UTF8_STRING)
|
|
goto err;
|
|
id = aes_cbc_cts_mode_name2id(p->data);
|
|
if (id < 0)
|
|
goto err;
|
|
|
|
ctx->cts_mode = (unsigned int)id;
|
|
}
|
|
return cipher_generic_set_ctx_params(vctx, params);
|
|
err:
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
|
|
/* NOTE: The underlying block cipher is AES CBC so we reuse most of the code */
|
|
#define IMPLEMENT_cts_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \
|
|
blkbits, ivbits, typ) \
|
|
static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lcmode##_get_params; \
|
|
static int alg##_cts_##kbits##_##lcmode##_get_params(OSSL_PARAM params[]) \
|
|
{ \
|
|
return cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, flags, \
|
|
kbits, blkbits, ivbits); \
|
|
} \
|
|
const OSSL_DISPATCH alg##kbits##lcmode##_cts_functions[] = { \
|
|
{ OSSL_FUNC_CIPHER_NEWCTX, \
|
|
(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))cipher_generic_einit }, \
|
|
{ OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))cipher_generic_dinit }, \
|
|
{ OSSL_FUNC_CIPHER_UPDATE, \
|
|
(void (*)(void)) alg##_##lcmode##_cts_block_update }, \
|
|
{ OSSL_FUNC_CIPHER_FINAL, \
|
|
(void (*)(void)) alg##_##lcmode##_cts_block_final }, \
|
|
{ OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))cipher_generic_cipher }, \
|
|
{ OSSL_FUNC_CIPHER_GET_PARAMS, \
|
|
(void (*)(void)) alg##_cts_##kbits##_##lcmode##_get_params }, \
|
|
{ OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
|
|
(void (*)(void))cipher_generic_gettable_params }, \
|
|
{ OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
|
|
(void (*)(void))aes_cbc_cts_get_ctx_params }, \
|
|
{ OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
|
|
(void (*)(void))aes_cbc_cts_set_ctx_params }, \
|
|
{ OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
|
|
(void (*)(void))aes_cbc_cts_gettable_ctx_params }, \
|
|
{ OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
|
|
(void (*)(void))aes_cbc_cts_settable_ctx_params }, \
|
|
{ 0, NULL } \
|
|
};
|
|
|
|
/* aes256cbc_cts_functions */
|
|
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 256, 128, 128, block)
|
|
/* aes192cbc_cts_functions */
|
|
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 192, 128, 128, block)
|
|
/* aes128cbc_cts_functions */
|
|
IMPLEMENT_cts_cipher(aes, AES, cbc, CBC, EVP_CIPH_FLAG_CTS, 128, 128, 128, block)
|