mirror of
https://github.com/openssl/openssl.git
synced 2025-01-06 13:26:43 +08:00
784883fc2c
Add test to evp_test_extra for ciphers (that is similiar to the digest_fetch). Move some of the aes and gcm methods that can be shared with other ciphers into ciphers_common.c Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9580)
116 lines
4.0 KiB
C
116 lines
4.0 KiB
C
/*
|
|
* Copyright 2019 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
|
|
*/
|
|
|
|
#include <openssl/core_names.h>
|
|
#include <openssl/params.h>
|
|
#include "ciphers_locl.h"
|
|
#include "internal/provider_algs.h"
|
|
#include "internal/providercommonerr.h"
|
|
|
|
/*-
|
|
* Default cipher functions for OSSL_PARAM gettables and settables
|
|
*/
|
|
static const OSSL_PARAM cipher_known_gettable_params[] = {
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_MODE, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_IVLEN, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_BLOCK_SIZE, NULL),
|
|
OSSL_PARAM_END
|
|
};
|
|
const OSSL_PARAM *cipher_default_gettable_params(void)
|
|
{
|
|
return cipher_known_gettable_params;
|
|
}
|
|
|
|
int cipher_default_get_params(OSSL_PARAM params[], int md, unsigned long flags,
|
|
int kbits, int blkbits, int ivbits)
|
|
{
|
|
OSSL_PARAM *p;
|
|
|
|
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_MODE);
|
|
if (p != NULL && !OSSL_PARAM_set_int(p, md)) {
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_FLAGS);
|
|
if (p != NULL && !OSSL_PARAM_set_ulong(p, flags)) {
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN);
|
|
if (p != NULL && !OSSL_PARAM_set_int(p, kbits / 8)) {
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_BLOCK_SIZE);
|
|
if (p != NULL && !OSSL_PARAM_set_int(p, blkbits / 8)) {
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN);
|
|
if (p != NULL && !OSSL_PARAM_set_int(p, ivbits / 8)) {
|
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static const OSSL_PARAM cipher_known_gettable_ctx_params[] = {
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_IVLEN, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_PADDING, NULL),
|
|
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_NUM, NULL),
|
|
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_IV, NULL, 0),
|
|
OSSL_PARAM_END
|
|
};
|
|
const OSSL_PARAM *cipher_default_gettable_ctx_params(void)
|
|
{
|
|
return cipher_known_gettable_ctx_params;
|
|
}
|
|
|
|
static const OSSL_PARAM cipher_known_settable_ctx_params[] = {
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_PADDING, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_NUM, NULL),
|
|
OSSL_PARAM_END
|
|
};
|
|
const OSSL_PARAM *cipher_default_settable_ctx_params(void)
|
|
{
|
|
return cipher_known_settable_ctx_params;
|
|
}
|
|
|
|
/*-
|
|
* AEAD cipher functions for OSSL_PARAM gettables and settables
|
|
*/
|
|
static const OSSL_PARAM cipher_aead_known_gettable_ctx_params[] = {
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_IVLEN, NULL),
|
|
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_IV, NULL, 0),
|
|
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, NULL, 0),
|
|
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD_PAD, NULL),
|
|
OSSL_PARAM_END
|
|
};
|
|
const OSSL_PARAM *cipher_aead_gettable_ctx_params(void)
|
|
{
|
|
return cipher_aead_known_gettable_ctx_params;
|
|
}
|
|
|
|
static const OSSL_PARAM cipher_aead_known_settable_ctx_params[] = {
|
|
OSSL_PARAM_int(OSSL_CIPHER_PARAM_KEYLEN, NULL),
|
|
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_AEAD_IVLEN, NULL),
|
|
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, NULL, 0),
|
|
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TLS1_AAD, NULL, 0),
|
|
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_AEAD_TLS1_IV_FIXED, NULL, 0),
|
|
OSSL_PARAM_END
|
|
};
|
|
const OSSL_PARAM *cipher_aead_settable_ctx_params(void)
|
|
{
|
|
return cipher_aead_known_settable_ctx_params;
|
|
}
|