mirror of https://github.com/openssl/openssl.git
shake: update to use generated param decoders
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> (Merged from https://github.com/openssl/openssl/pull/28151)
This commit is contained in:
parent
1c5780ee52
commit
dc044f616e
|
@ -6,6 +6,9 @@
|
||||||
* in the file LICENSE in the source distribution or at
|
* in the file LICENSE in the source distribution or at
|
||||||
* https://www.openssl.org/source/license.html
|
* https://www.openssl.org/source/license.html
|
||||||
*/
|
*/
|
||||||
|
{-
|
||||||
|
use OpenSSL::paramnames qw(produce_param_decoder);
|
||||||
|
-}
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <openssl/core_names.h>
|
#include <openssl/core_names.h>
|
||||||
|
@ -14,6 +17,7 @@
|
||||||
#include <openssl/params.h>
|
#include <openssl/params.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/proverr.h>
|
#include <openssl/proverr.h>
|
||||||
|
#include "internal/cryptlib.h"
|
||||||
#include "internal/numbers.h"
|
#include "internal/numbers.h"
|
||||||
#include "internal/sha3.h"
|
#include "internal/sha3.h"
|
||||||
#include "prov/digestcommon.h"
|
#include "prov/digestcommon.h"
|
||||||
|
@ -582,68 +586,58 @@ static void *keccak_dupctx(void *ctx)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{- produce_param_decoder('shake_get_ctx_params',
|
||||||
|
(['DIGEST_PARAM_XOFLEN', 'xoflen', 'size_t'],
|
||||||
|
['DIGEST_PARAM_SIZE', 'size', 'size_t'],
|
||||||
|
)); -}
|
||||||
|
|
||||||
static const OSSL_PARAM *shake_gettable_ctx_params(ossl_unused void *ctx,
|
static const OSSL_PARAM *shake_gettable_ctx_params(ossl_unused void *ctx,
|
||||||
ossl_unused void *provctx)
|
ossl_unused void *provctx)
|
||||||
{
|
{
|
||||||
static const OSSL_PARAM known_shake_gettable_ctx_params[] = {
|
return shake_get_ctx_params_list;
|
||||||
{OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
|
|
||||||
{OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
|
|
||||||
OSSL_PARAM_END
|
|
||||||
};
|
|
||||||
return known_shake_gettable_ctx_params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shake_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
static int shake_get_ctx_params(void *vctx, OSSL_PARAM params[])
|
||||||
{
|
{
|
||||||
OSSL_PARAM *p;
|
struct shake_get_ctx_params_st p;
|
||||||
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
|
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
|
||||||
|
|
||||||
if (ctx == NULL)
|
if (ctx == NULL || !shake_get_ctx_params_decoder(params, &p))
|
||||||
return 0;
|
return 0;
|
||||||
if (ossl_param_is_empty(params))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_XOFLEN);
|
if (p.xoflen != NULL && !OSSL_PARAM_set_size_t(p.xoflen, ctx->md_size)) {
|
||||||
if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->md_size)) {
|
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Size is an alias of xoflen */
|
/* Size is an alias of xoflen but separate them for compatibility */
|
||||||
p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE);
|
if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, ctx->md_size)) {
|
||||||
if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->md_size)) {
|
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{- produce_param_decoder('shake_set_ctx_params',
|
||||||
|
(['DIGEST_PARAM_XOFLEN', 'xoflen', 'size_t'],
|
||||||
|
['DIGEST_PARAM_SIZE', 'xoflen', 'size_t'],
|
||||||
|
)); -}
|
||||||
|
|
||||||
static const OSSL_PARAM *shake_settable_ctx_params(ossl_unused void *ctx,
|
static const OSSL_PARAM *shake_settable_ctx_params(ossl_unused void *ctx,
|
||||||
ossl_unused void *provctx)
|
ossl_unused void *provctx)
|
||||||
{
|
{
|
||||||
static const OSSL_PARAM known_shake_settable_ctx_params[] = {
|
return shake_set_ctx_params_list;
|
||||||
{OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
|
|
||||||
{OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
|
|
||||||
OSSL_PARAM_END
|
|
||||||
};
|
|
||||||
|
|
||||||
return known_shake_settable_ctx_params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[])
|
||||||
{
|
{
|
||||||
const OSSL_PARAM *p;
|
struct shake_set_ctx_params_st p;
|
||||||
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
|
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
|
||||||
|
|
||||||
if (ossl_unlikely(ctx == NULL))
|
if (ossl_unlikely(ctx == NULL || !shake_set_ctx_params_decoder(params, &p)))
|
||||||
return 0;
|
return 0;
|
||||||
if (ossl_param_is_empty(params))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN);
|
if (ossl_unlikely(p.xoflen != NULL
|
||||||
if (ossl_unlikely(p == NULL))
|
&& !OSSL_PARAM_get_size_t(p.xoflen, &ctx->md_size))) {
|
||||||
p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE);
|
|
||||||
|
|
||||||
if (ossl_unlikely(p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->md_size))) {
|
|
||||||
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue