Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • car/libdap-crypto
1 result
Show changes
Showing
with 1800 additions and 0 deletions
/*
Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen,
Michaël Peeters, Gilles Van Assche and Ronny Van Keer,
hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "KeccakSpongeWidth200.h"
#ifdef KeccakReference
#include "displayIntermediateValues.h"
#endif
#ifndef KeccakP200_excluded
#include "KeccakP-200-SnP.h"
#define prefix KeccakWidth200
#define SnP KeccakP200
#define SnP_width 200
#define SnP_Permute KeccakP200_Permute_18rounds
#if defined(KeccakF200_FastLoop_supported)
#define SnP_FastLoop_Absorb KeccakF200_FastLoop_Absorb
#endif
#include "KeccakSponge.inc"
#undef prefix
#undef SnP
#undef SnP_width
#undef SnP_Permute
#undef SnP_FastLoop_Absorb
#endif
/*
Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen,
Michaël Peeters, Gilles Van Assche and Ronny Van Keer,
hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _KeccakSpongeWidth200_h_
#define _KeccakSpongeWidth200_h_
#include "KeccakSponge-common.h"
#ifndef KeccakP200_excluded
#include "KeccakP-200-SnP.h"
KCP_DeclareSpongeStructure(KeccakWidth200, KeccakP200_stateSizeInBytes, KeccakP200_stateAlignment)
KCP_DeclareSpongeFunctions(KeccakWidth200)
#endif
#endif
/*
Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen,
Michaël Peeters, Gilles Van Assche and Ronny Van Keer,
hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "KeccakSpongeWidth400.h"
#ifdef KeccakReference
#include "displayIntermediateValues.h"
#endif
#ifndef KeccakP400_excluded
#include "KeccakP-400-SnP.h"
#define prefix KeccakWidth400
#define SnP KeccakP400
#define SnP_width 400
#define SnP_Permute KeccakP400_Permute_20rounds
#if defined(KeccakF400_FastLoop_supported)
#define SnP_FastLoop_Absorb KeccakF400_FastLoop_Absorb
#endif
#include "KeccakSponge.inc"
#undef prefix
#undef SnP
#undef SnP_width
#undef SnP_Permute
#undef SnP_FastLoop_Absorb
#endif
/*
Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen,
Michaël Peeters, Gilles Van Assche and Ronny Van Keer,
hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _KeccakSpongeWidth400_h_
#define _KeccakSpongeWidth400_h_
#include "KeccakSponge-common.h"
#ifndef KeccakP400_excluded
#include "KeccakP-400-SnP.h"
KCP_DeclareSpongeStructure(KeccakWidth400, KeccakP400_stateSizeInBytes, KeccakP400_stateAlignment)
KCP_DeclareSpongeFunctions(KeccakWidth400)
#endif
#endif
/*
Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen,
Michaël Peeters, Gilles Van Assche and Ronny Van Keer,
hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "KeccakSpongeWidth800.h"
#ifdef KeccakReference
#include "displayIntermediateValues.h"
#endif
#ifndef KeccakP800_excluded
#include "KeccakP-800-SnP.h"
#define prefix KeccakWidth800
#define SnP KeccakP800
#define SnP_width 800
#define SnP_Permute KeccakP800_Permute_22rounds
#if defined(KeccakF800_FastLoop_supported)
#define SnP_FastLoop_Absorb KeccakF800_FastLoop_Absorb
#endif
#include "KeccakSponge.inc"
#undef prefix
#undef SnP
#undef SnP_width
#undef SnP_Permute
#undef SnP_FastLoop_Absorb
#endif
/*
Implementation by the Keccak Team, namely, Guido Bertoni, Joan Daemen,
Michaël Peeters, Gilles Van Assche and Ronny Van Keer,
hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _KeccakSpongeWidth800_h_
#define _KeccakSpongeWidth800_h_
#include "KeccakSponge-common.h"
#ifndef KeccakP800_excluded
#include "KeccakP-800-SnP.h"
KCP_DeclareSpongeStructure(KeccakWidth800, KeccakP800_stateSizeInBytes, KeccakP800_stateAlignment)
KCP_DeclareSpongeFunctions(KeccakWidth800)
#endif
#endif
/*
Implementation by Gilles Van Assche, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _KeccakPRGCommon_h_
#define _KeccakPRGCommon_h_
#include "align.h"
#define KCP_DeclareSpongePRG_Structure(prefix, size, alignment) \
ALIGN(alignment) typedef struct prefix##_SpongePRG_InstanceStruct { \
prefix##_DuplexInstance duplex; \
} prefix##_SpongePRG_Instance;
#define KCP_DeclareSpongePRG_Functions(prefix) \
int prefix##_SpongePRG_Initialize(prefix##_SpongePRG_Instance *instance, unsigned int capacity); \
int prefix##_SpongePRG_Feed(prefix##_SpongePRG_Instance *instance, const unsigned char *input, unsigned int inputByteLen); \
int prefix##_SpongePRG_Fetch(prefix##_SpongePRG_Instance *Instance, unsigned char *out, unsigned int outByteLen); \
int prefix##_SpongePRG_Forget(prefix##_SpongePRG_Instance *instance);
#endif
/*
Implementation by Gilles Van Assche, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef _KeccakPRG_h_
#define _KeccakPRG_h_
/* For the documentation, please follow the link: */
/* #include "KeccakPRG-documentation.h" */
#include "KeccakPRGWidth200.h"
#include "KeccakPRGWidth400.h"
#include "KeccakPRGWidth800.h"
#include "KeccakPRGWidth1600.h"
#endif
/*
Implementation by Gilles Van Assche, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#define JOIN0(a, b) a ## b
#define JOIN(a, b) JOIN0(a, b)
#define SpongePRG_Instance JOIN(prefix, _SpongePRG_Instance)
#define SpongePRG_Initialize JOIN(prefix, _SpongePRG_Initialize)
#define SpongePRG_Feed JOIN(prefix, _SpongePRG_Feed)
#define SpongePRG_Fetch JOIN(prefix, _SpongePRG_Fetch)
#define SpongePRG_Forget JOIN(prefix, _SpongePRG_Forget)
#define DuplexInstance JOIN(prefix, _DuplexInstance)
#define DuplexInitialize JOIN(prefix, _DuplexInitialize)
#define Duplexing JOIN(prefix, _Duplexing)
#define DuplexingFeedPartialInput JOIN(prefix, _DuplexingFeedPartialInput)
#define DuplexingOverwriteWithZeroes JOIN(prefix, _DuplexingOverwriteWithZeroes)
#define DuplexingGetFurtherOutput JOIN(prefix, _DuplexingGetFurtherOutput)
#define DuplexGetInputIndex(duplex) (duplex)->byteInputIndex
#define DuplexGetOutputIndex(duplex) (duplex)->byteOutputIndex
#define DuplexSetOutputIndex(duplex, i) (duplex)->byteOutputIndex = (i)
int SpongePRG_Initialize(SpongePRG_Instance *instance, unsigned int capacity)
{
unsigned int rate;
unsigned int rhoInBytes;
if (capacity > (SnP_width-10))
return 1;
rate = SnP_width - capacity;
rhoInBytes = (rate-2)/8;
if ( (rhoInBytes == 0) || (rhoInBytes >= SnP_width/8) )
return 1;
return DuplexInitialize(&instance->duplex, rate, capacity);
}
int SpongePRG_Feed(SpongePRG_Instance *instance, const unsigned char *input, unsigned int inputByteLen)
{
unsigned int rhoInBytes = (instance->duplex.rate-2)/8;
int error = 0;
while( !error && ((DuplexGetInputIndex(&instance->duplex) + inputByteLen) >= rhoInBytes)) {
unsigned int localSize = rhoInBytes - DuplexGetInputIndex(&instance->duplex);
error |= DuplexingFeedPartialInput(&instance->duplex, input, localSize);
error |= Duplexing(&instance->duplex, 0, 0, 0, 0, 0x01);
input += localSize;
inputByteLen -= localSize;
}
if (!error)
error = DuplexingFeedPartialInput(&instance->duplex, input, inputByteLen);
DuplexSetOutputIndex(&instance->duplex, rhoInBytes);
return error;
}
int SpongePRG_Fetch(SpongePRG_Instance *instance, unsigned char *output, unsigned int outputByteLen)
{
unsigned int rhoInBytes = (instance->duplex.rate-2)/8;
int error = 0;
if (DuplexGetOutputIndex(&instance->duplex) < rhoInBytes) {
unsigned int localSize = rhoInBytes - DuplexGetOutputIndex(&instance->duplex);
localSize = (localSize <= outputByteLen) ? localSize : outputByteLen;
error = DuplexingGetFurtherOutput(&instance->duplex, output, localSize);
output += localSize;
outputByteLen -= localSize;
}
while( !error && (outputByteLen > 0) ) {
error = Duplexing(&instance->duplex, 0, 0, 0, 0, 0x01);
if (!error) {
unsigned int localSize = (rhoInBytes <= outputByteLen) ? rhoInBytes : outputByteLen;
error = DuplexingGetFurtherOutput(&instance->duplex, output, localSize);
output += localSize;
outputByteLen -= localSize;
}
}
return error;
}
int SpongePRG_Forget(SpongePRG_Instance *instance)
{
unsigned int rhoInBytes = (instance->duplex.rate-2)/8;
unsigned int capacity = SnP_width - instance->duplex.rate;
int error;
if ((rhoInBytes*8) < capacity)
return 1;
error = Duplexing(&instance->duplex, 0, 0, 0, 0, 0x01);
if ( !error ) {
error = DuplexingOverwriteWithZeroes(&instance->duplex, rhoInBytes);
if ( !error )
error = Duplexing(&instance->duplex, 0, 0, 0, 0, 0x01);
}
DuplexSetOutputIndex(&instance->duplex, rhoInBytes);
return error;
}
#undef SpongePRG_Instance
#undef SpongePRG_Initialize
#undef SpongePRG_Feed
#undef SpongePRG_Fetch
#undef SpongePRG_Forget
#undef DuplexInstance
#undef DuplexInitialize
#undef Duplexing
#undef DuplexingFeedPartialInput
#undef DuplexingOverwriteWithZeroes
#undef DuplexingGetFurtherOutput
#undef DuplexGetInputIndex
#undef DuplexGetOutputIndex
#undef DuplexSetOutputIndex
/*
Implementation by Gilles Van Assche, hereby denoted as "the implementer".
For more information, feedback or questions, please refer to our website:
https://keccak.team/
To the extent possible under law, the implementer has waived all copyright
and related or neighboring rights to the source code in this file.
http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "KeccakPRGWidth1600.h"
#ifdef KeccakReference
#include <string.h>
#include "displayIntermediateValues.h"
#endif
#ifndef KeccakP1600_excluded
#include "KeccakP-1600-SnP.h"
#define prefix KeccakWidth1600
#define SnP_width 1600
#include "KeccakPRG.inc"
#undef prefix
#undef SnP_width
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.