shake.c File Reference

SHAKE extendable-output function. More...

#include "core/crypto.h"
#include "xof/shake.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t shakeCompute (uint_t strength, const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
 Digest a message using SHAKE. More...
 
error_t shake128Compute (const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
 Digest a message using SHAKE128. More...
 
error_t shake256Compute (const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
 Digest a message using SHAKE256. More...
 
error_t shakeInit (ShakeContext *context, uint_t strength)
 Initialize SHAKE context. More...
 
error_t shake128Init (ShakeContext *context)
 Initialize SHAKE128 context. More...
 
error_t shake256Init (ShakeContext *context)
 Initialize SHAKE256 context. More...
 
void shakeAbsorb (ShakeContext *context, const void *input, size_t length)
 Absorb data. More...
 
void shakeFinal (ShakeContext *context)
 Finish absorbing phase. More...
 
void shakeSqueeze (ShakeContext *context, uint8_t *output, size_t length)
 Extract data from the squeezing phase. More...
 

Variables

const uint8_t SHAKE128_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0B}
 
const uint8_t SHAKE256_OID [9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0C}
 
const XofAlgo shake128XofAlgo
 
const XofAlgo shake256XofAlgo
 

Detailed Description

SHAKE extendable-output function.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

SHAKE is a function on binary data in which the output can be extended to any desired length. SHAKE128 supports 128 bits of security strength. SHAKE256 supports 256 bits of security strength. Refer to FIPS 202 for more details

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.6.6

Definition in file shake.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 38 of file shake.c.

Function Documentation

◆ shake128Compute()

error_t shake128Compute ( const void *  input,
size_t  inputLen,
uint8_t *  output,
size_t  outputLen 
)

Digest a message using SHAKE128.

Parameters
[in]inputPointer to the input data
[in]inputLenLength of the input data
[out]outputPointer to the output data
[in]outputLenExpected length of the output data
Returns
Error code

Definition at line 154 of file shake.c.

◆ shake128Init()

error_t shake128Init ( ShakeContext *  context)

Initialize SHAKE128 context.

Parameters
[in]contextPointer to the SHAKE context to initialize
Returns
Error code

Definition at line 214 of file shake.c.

◆ shake256Compute()

error_t shake256Compute ( const void *  input,
size_t  inputLen,
uint8_t *  output,
size_t  outputLen 
)

Digest a message using SHAKE256.

Parameters
[in]inputPointer to the input data
[in]inputLenLength of the input data
[out]outputPointer to the output data
[in]outputLenExpected length of the output data
Returns
Error code

Definition at line 171 of file shake.c.

◆ shake256Init()

error_t shake256Init ( ShakeContext *  context)

Initialize SHAKE256 context.

Parameters
[in]contextPointer to the SHAKE context to initialize
Returns
Error code

Definition at line 227 of file shake.c.

◆ shakeAbsorb()

void shakeAbsorb ( ShakeContext *  context,
const void *  input,
size_t  length 
)

Absorb data.

Parameters
[in]contextPointer to the SHAKE context
[in]inputPointer to the buffer being hashed
[in]lengthLength of the buffer

Definition at line 241 of file shake.c.

◆ shakeCompute()

error_t shakeCompute ( uint_t  strength,
const void *  input,
size_t  inputLen,
uint8_t *  output,
size_t  outputLen 
)

Digest a message using SHAKE.

Parameters
[in]strengthNumber of bits of security (128 for SHAKE128 and 256 for SHAKE256)
[in]inputPointer to the input data
[in]inputLenLength of the input data
[out]outputPointer to the output data
[in]outputLenExpected length of the output data
Returns
Error code

Definition at line 96 of file shake.c.

◆ shakeFinal()

void shakeFinal ( ShakeContext *  context)

Finish absorbing phase.

Parameters
[in]contextPointer to the SHAKE context

Definition at line 253 of file shake.c.

◆ shakeInit()

error_t shakeInit ( ShakeContext *  context,
uint_t  strength 
)

Initialize SHAKE context.

Parameters
[in]contextPointer to the SHAKE context to initialize
[in]strengthNumber of bits of security (128 for SHAKE128 and 256 for SHAKE256)
Returns
Error code

Definition at line 187 of file shake.c.

◆ shakeSqueeze()

void shakeSqueeze ( ShakeContext *  context,
uint8_t *  output,
size_t  length 
)

Extract data from the squeezing phase.

Parameters
[in]contextPointer to the SHAKE context
[out]outputOutput string
[in]lengthDesired output length, in bytes

Definition at line 267 of file shake.c.

Variable Documentation

◆ SHAKE128_OID

const uint8_t SHAKE128_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0B}

Definition at line 48 of file shake.c.

◆ shake128XofAlgo

const XofAlgo shake128XofAlgo

◆ SHAKE256_OID

const uint8_t SHAKE256_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x0C}

Definition at line 50 of file shake.c.

◆ shake256XofAlgo

const XofAlgo shake256XofAlgo
void(* XofAlgoAbsorb)(void *context, const void *input, size_t length)
Definition: crypto.h:1191
error_t(* XofAlgoInit)(void *context)
Definition: crypto.h:1186
error_t(* XofAlgoInitEx)(void *context, const char_t *custom, size_t customLen)
Definition: crypto.h:1188
const uint8_t SHAKE256_OID[9]
Definition: shake.c:50
void shakeAbsorb(ShakeContext *context, const void *input, size_t length)
Absorb data.
Definition: shake.c:241
void shakeSqueeze(ShakeContext *context, uint8_t *output, size_t length)
Extract data from the squeezing phase.
Definition: shake.c:267
SHAKE algorithm context.
Definition: shake.h:53
error_t shake256Init(ShakeContext *context)
Initialize SHAKE256 context.
Definition: shake.c:227
error_t(* XofAlgoCompute)(const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
Definition: crypto.h:1180
error_t shake128Compute(const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
Digest a message using SHAKE128.
Definition: shake.c:154
void shakeFinal(ShakeContext *context)
Finish absorbing phase.
Definition: shake.c:253
error_t shake256Compute(const void *input, size_t inputLen, uint8_t *output, size_t outputLen)
Digest a message using SHAKE256.
Definition: shake.c:171
void(* XofAlgoSqueeze)(void *context, uint8_t *output, size_t length)
Definition: crypto.h:1193
error_t(* XofAlgoComputeEx)(const void *input, size_t inputLen, const char_t *custom, size_t customLen, uint8_t *output, size_t outputLen)
Definition: crypto.h:1183
error_t shake128Init(ShakeContext *context)
Initialize SHAKE128 context.
Definition: shake.c:214
void(* XofAlgoFinal)(void *context)
Definition: crypto.h:1192
const uint8_t SHAKE128_OID[9]
Definition: shake.c:48