-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc3f0b8
commit 23d9991
Showing
14 changed files
with
6,295 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
K12 based on the eXtended Keccak Code Package (XKCP) | ||
https://github.com/XKCP/XKCP | ||
The Keccak-p permutations, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche. | ||
Implementation by Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". | ||
For more information, feedback or questions, please refer to the Keccak Team 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/ | ||
--- | ||
Please refer to the XKCP for more details. | ||
*/ | ||
|
||
#ifndef _KeccakP_1600_SnP_h_ | ||
#define _KeccakP_1600_SnP_h_ | ||
|
||
/* Keccak-p[1600] */ | ||
|
||
#define KeccakP1600_stateSizeInBytes 200 | ||
#define KeccakP1600_stateAlignment 8 | ||
#define KeccakP1600_12rounds_FastLoop_supported | ||
|
||
const char * KeccakP1600_GetImplementation(); | ||
void KeccakP1600_opt64_Initialize(void *state); | ||
void KeccakP1600_opt64_AddByte(void *state, unsigned char data, unsigned int offset); | ||
void KeccakP1600_opt64_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length); | ||
void KeccakP1600_ARMv8Asha3_Permute_12rounds(void *state); | ||
void KeccakP1600_opt64_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length); | ||
size_t KeccakP1600_ARMv8Asha3_12rounds_FastLoop_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen); | ||
|
||
#define KeccakP1600_Initialize KeccakP1600_opt64_Initialize | ||
#define KeccakP1600_AddByte KeccakP1600_opt64_AddByte | ||
#define KeccakP1600_AddBytes KeccakP1600_opt64_AddBytes | ||
#define KeccakP1600_Permute_12rounds KeccakP1600_ARMv8Asha3_Permute_12rounds | ||
#define KeccakP1600_ExtractBytes KeccakP1600_opt64_ExtractBytes | ||
#define KeccakP1600_12rounds_FastLoop_Absorb KeccakP1600_ARMv8Asha3_12rounds_FastLoop_Absorb | ||
|
||
/* Keccak-p[1600]×2 */ | ||
|
||
int KeccakP1600times2_IsAvailable(); | ||
const char * KeccakP1600times2_GetImplementation(); | ||
void KeccakP1600times2_ARMv8Asha3_Permute_12rounds(void *state); | ||
void KangarooTwelve_ARMv8Asha3_Process2Leaves(const unsigned char *input, unsigned char *output); | ||
|
||
#define KeccakP1600times2_Permute_12rounds KeccakP1600times2_ARMv8Asha3_Permute_12rounds | ||
#define KangarooTwelve_Process2Leaves KangarooTwelve_ARMv8Asha3_Process2Leaves | ||
|
||
/* Keccak-p[1600]×4 */ | ||
|
||
int KeccakP1600times4_IsAvailable(); | ||
const char * KeccakP1600times4_GetImplementation(); | ||
|
||
/* Keccak-p[1600]×8 */ | ||
|
||
int KeccakP1600times8_IsAvailable(); | ||
const char * KeccakP1600times8_GetImplementation(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
/* | ||
K12 based on the eXtended Keccak Code Package (XKCP) | ||
https://github.com/XKCP/XKCP | ||
The Keccak-p permutations, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche. | ||
Implementation by Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". | ||
For more information, feedback or questions, please refer to the Keccak Team 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/ | ||
--- | ||
Please refer to the XKCP for more details. | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <KeccakP-1600-SnP.h> | ||
|
||
const char * KeccakP1600_GetImplementation() | ||
{ | ||
return "ARMv8-A+SHA3 optimized implementation"; | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
void KeccakP1600_opt64_Initialize(void *state) | ||
{ | ||
memset(state, 0, 200); | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
void KeccakP1600_opt64_AddBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length) | ||
{ | ||
uint64_t lane; | ||
|
||
if (length == 0) | ||
return; | ||
if (length == 1) | ||
lane = data[0]; | ||
else { | ||
lane = 0; | ||
memcpy(&lane, data, length); | ||
} | ||
lane <<= offset*8; | ||
((uint64_t*)state)[lanePosition] ^= lane; | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
static void KeccakP1600_opt64_AddLanes(void *state, const unsigned char *data, unsigned int laneCount) | ||
{ | ||
unsigned int i = 0; | ||
|
||
for( ; (i+8)<=laneCount; i+=8) { | ||
((uint64_t*)state)[i+0] ^= ((uint64_t*)data)[i+0]; | ||
((uint64_t*)state)[i+1] ^= ((uint64_t*)data)[i+1]; | ||
((uint64_t*)state)[i+2] ^= ((uint64_t*)data)[i+2]; | ||
((uint64_t*)state)[i+3] ^= ((uint64_t*)data)[i+3]; | ||
((uint64_t*)state)[i+4] ^= ((uint64_t*)data)[i+4]; | ||
((uint64_t*)state)[i+5] ^= ((uint64_t*)data)[i+5]; | ||
((uint64_t*)state)[i+6] ^= ((uint64_t*)data)[i+6]; | ||
((uint64_t*)state)[i+7] ^= ((uint64_t*)data)[i+7]; | ||
} | ||
for( ; (i+4)<=laneCount; i+=4) { | ||
((uint64_t*)state)[i+0] ^= ((uint64_t*)data)[i+0]; | ||
((uint64_t*)state)[i+1] ^= ((uint64_t*)data)[i+1]; | ||
((uint64_t*)state)[i+2] ^= ((uint64_t*)data)[i+2]; | ||
((uint64_t*)state)[i+3] ^= ((uint64_t*)data)[i+3]; | ||
} | ||
for( ; (i+2)<=laneCount; i+=2) { | ||
((uint64_t*)state)[i+0] ^= ((uint64_t*)data)[i+0]; | ||
((uint64_t*)state)[i+1] ^= ((uint64_t*)data)[i+1]; | ||
} | ||
if (i<laneCount) { | ||
((uint64_t*)state)[i+0] ^= ((uint64_t*)data)[i+0]; | ||
} | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
void KeccakP1600_opt64_AddByte(void *state, unsigned char byte, unsigned int offset) | ||
{ | ||
((unsigned char*)(state))[offset] ^= byte; | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
#define SnP_AddBytes(state, data, offset, length, SnP_AddLanes, SnP_AddBytesInLane, SnP_laneLengthInBytes) \ | ||
{ \ | ||
if ((offset) == 0) { \ | ||
SnP_AddLanes(state, data, (length)/SnP_laneLengthInBytes); \ | ||
SnP_AddBytesInLane(state, \ | ||
(length)/SnP_laneLengthInBytes, \ | ||
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \ | ||
0, \ | ||
(length)%SnP_laneLengthInBytes); \ | ||
} \ | ||
else { \ | ||
unsigned int _sizeLeft = (length); \ | ||
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \ | ||
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \ | ||
const unsigned char *_curData = (data); \ | ||
while(_sizeLeft > 0) { \ | ||
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \ | ||
if (_bytesInLane > _sizeLeft) \ | ||
_bytesInLane = _sizeLeft; \ | ||
SnP_AddBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \ | ||
_sizeLeft -= _bytesInLane; \ | ||
_lanePosition++; \ | ||
_offsetInLane = 0; \ | ||
_curData += _bytesInLane; \ | ||
} \ | ||
} \ | ||
} | ||
|
||
void KeccakP1600_opt64_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length) | ||
{ | ||
SnP_AddBytes(state, data, offset, length, KeccakP1600_opt64_AddLanes, KeccakP1600_opt64_AddBytesInLane, 8); | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
void KeccakP1600_opt64_ExtractBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length) | ||
{ | ||
uint64_t lane = ((uint64_t*)state)[lanePosition]; | ||
{ | ||
uint64_t lane1[1]; | ||
lane1[0] = lane; | ||
memcpy(data, (uint8_t*)lane1+offset, length); | ||
} | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
void KeccakP1600_opt64_ExtractLanes(const void *state, unsigned char *data, unsigned int laneCount) | ||
{ | ||
memcpy(data, state, laneCount*8); | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
#define SnP_ExtractBytes(state, data, offset, length, SnP_ExtractLanes, SnP_ExtractBytesInLane, SnP_laneLengthInBytes) \ | ||
{ \ | ||
if ((offset) == 0) { \ | ||
SnP_ExtractLanes(state, data, (length)/SnP_laneLengthInBytes); \ | ||
SnP_ExtractBytesInLane(state, \ | ||
(length)/SnP_laneLengthInBytes, \ | ||
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \ | ||
0, \ | ||
(length)%SnP_laneLengthInBytes); \ | ||
} \ | ||
else { \ | ||
unsigned int _sizeLeft = (length); \ | ||
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \ | ||
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \ | ||
unsigned char *_curData = (data); \ | ||
while(_sizeLeft > 0) { \ | ||
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \ | ||
if (_bytesInLane > _sizeLeft) \ | ||
_bytesInLane = _sizeLeft; \ | ||
SnP_ExtractBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \ | ||
_sizeLeft -= _bytesInLane; \ | ||
_lanePosition++; \ | ||
_offsetInLane = 0; \ | ||
_curData += _bytesInLane; \ | ||
} \ | ||
} \ | ||
} | ||
|
||
void KeccakP1600_opt64_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length) | ||
{ | ||
SnP_ExtractBytes(state, data, offset, length, KeccakP1600_opt64_ExtractLanes, KeccakP1600_opt64_ExtractBytesInLane, 8); | ||
} | ||
|
||
/* ---------------------------------------------------------------- */ | ||
|
||
/* Keccak-p[1600]×2 */ | ||
|
||
int KeccakP1600times2_IsAvailable() | ||
{ | ||
return 1; | ||
} | ||
|
||
const char * KeccakP1600times2_GetImplementation() | ||
{ | ||
return "ARMv8-A+SHA3 optimized implementation"; | ||
} | ||
|
||
/* Keccak-p[1600]×4 */ | ||
|
||
int KeccakP1600times4_IsAvailable() | ||
{ | ||
return 0; | ||
} | ||
|
||
const char * KeccakP1600times4_GetImplementation() | ||
{ | ||
return ""; | ||
} | ||
|
||
void KangarooTwelve_Process4Leaves(const unsigned char *input, unsigned char *output) | ||
{ | ||
} | ||
|
||
/* Keccak-p[1600]×8 */ | ||
|
||
int KeccakP1600times8_IsAvailable() | ||
{ | ||
return 0; | ||
} | ||
|
||
const char * KeccakP1600times8_GetImplementation() | ||
{ | ||
return ""; | ||
} | ||
|
||
void KangarooTwelve_Process8Leaves(const unsigned char *input, unsigned char *output) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
K12 based on the eXtended Keccak Code Package (XKCP) | ||
https://github.com/XKCP/XKCP | ||
The Keccak-p permutations, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche. | ||
Implementation by Ronny Van Keer, hereby denoted as "the implementer". | ||
For more information, feedback or questions, please refer to the Keccak Team 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/ | ||
--- | ||
Please refer to the XKCP for more details. | ||
*/ | ||
|
||
#ifndef _KeccakP_1600_SnP_h_ | ||
#define _KeccakP_1600_SnP_h_ | ||
|
||
#define KeccakP1600_stateSizeInBytes 200 | ||
#define KeccakP1600_stateAlignment 8 | ||
#define KeccakP1600_disableParallelism | ||
|
||
const char * KeccakP1600_GetImplementation(); | ||
void KeccakP1600_Initialize(void *state); | ||
void KeccakP1600_AddByte(void *state, unsigned char data, unsigned int offset); | ||
void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length); | ||
void KeccakP1600_Permute_12rounds(void *state); | ||
void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length); | ||
|
||
#endif |
Oops, something went wrong.