#include "internal/sha3.h"
#include "prov/digestcommon.h"
#include "prov/implementations.h"
+#include "internal/common.h"
#define SHA3_FLAGS PROV_DIGEST_FLAG_ALGID_ABSENT
#define SHAKE_FLAGS (PROV_DIGEST_FLAG_XOF | PROV_DIGEST_FLAG_ALGID_ABSENT)
static int keccak_init(void *vctx, ossl_unused const OSSL_PARAM params[])
{
- if (!ossl_prov_is_running())
+ if (ossl_unlikely(!ossl_prov_is_running()))
return 0;
/* The newctx() handles most of the ctx fixed setup. */
ossl_sha3_reset((KECCAK1600_CTX *)vctx);
const size_t bsz = ctx->block_size;
size_t num, rem;
- if (len == 0)
+ if (ossl_unlikely(len == 0))
return 1;
/* Is there anything in the buffer already ? */
- if ((num = ctx->bufsz) != 0) {
+ if (ossl_likely((num = ctx->bufsz) != 0)) {
/* Calculate how much space is left in the buffer */
rem = bsz - num;
/* If the new input does not fill the buffer then just add it */
/* Absorb the input - rem = leftover part of the input < blocksize) */
rem = ctx->meth.absorb(ctx, inp, len);
/* Copy the leftover bit of the input into the buffer */
- if (rem) {
+ if (ossl_likely(rem)) {
memcpy(ctx->buf, inp + len - rem, rem);
ctx->bufsz = rem;
}
int ret = 1;
KECCAK1600_CTX *ctx = vctx;
- if (!ossl_prov_is_running())
+ if (ossl_unlikely(!ossl_prov_is_running()))
return 0;
- if (ctx->md_size == SIZE_MAX) {
+ if (ossl_unlikely(ctx->md_size == SIZE_MAX)) {
ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST_LENGTH);
return 0;
}
- if (outlen > 0)
+ if (ossl_likely(outlen > 0))
ret = ctx->meth.final(ctx, out, ctx->md_size);
*outl = ctx->md_size;
const OSSL_PARAM *p;
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
- if (ctx == NULL)
+ if (ossl_unlikely(ctx == NULL))
return 0;
if (ossl_param_is_empty(params))
return 1;
p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN);
- if (p == NULL)
+ if (ossl_unlikely(p == NULL))
p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE);
- if (p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->md_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);
return 0;
}