Commit edfc8cb6 authored by bernd's avatar bernd

Keccak encrypt/decrypt bytewise

parent 186e15a3
......@@ -8,7 +8,7 @@ require rng.fs
\ random initializer for hash
: hash-init-rng ( -- ) rng@ hashinit 64! rng@ hashinit 64'+ 64! ;
: hash-init-rng ( -- ) rng@ rng@ hashinit 128! ;
hash-init-rng
......
/*
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
Michaël Peeters and Gilles Van Assche. For more information, feedback or
questions, please refer to our website: http://keccak.noekeon.org/
Implementation by the designers,
hereby denoted as "the implementer".
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/
*/
typedef unsigned long long int STATEI;
#include <string.h>
#include "brg_endian.h"
#include "KeccakF-1600-opt64-settings.h"
#include "KeccakF-1600.h"
void KeccakF(keccak_state state)
{
KeccakF_armv7a_neon(state);
}
void KeccakInitializeState(keccak_state state)
{
memset(state, 0, 200);
}
void KeccakInitialize()
{
}
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int laneCount)
{
memcpy(data, state, laneCount*8);
}
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int laneCount)
{
unsigned int i;
for(i=0; i<laneCount; i++) {
state[i] ^= data[i];
}
}
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
{
unsigned int i;
for(i=0; i<laneCount; i++) {
data[i] = state[i] ^= data[i];
}
}
void KeccakDecrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
{
unsigned int i;
for(i=0; i<laneCount; i++) {
UINT64 tmp;
tmp = data[i] ^ state[i];
state[i] = data[i];
data[i] = tmp;
}
}
......@@ -76,12 +76,14 @@ void xor8bytesIntoInterleavedWords(UINT32 *even, UINT32 *odd, const UINT8* sourc
xor2bytesIntoInterleavedWords(even, odd, source, 3)
}
#define xorLanesIntoState(laneCount, state, input) \
{ \
int i; \
for(i=0; i<(laneCount); i++) \
xor8bytesIntoInterleavedWords(state+i*2, state+i*2+1, input+i*8); \
}
#define xorLanesIntoState(byteCount, state, input) { \
int i; \
UINT64 tmp=0; \
for(i=0; i<(byteCount-7); i+=8) \
xor8bytesIntoInterleavedWords(state+(i>>2), state+(i>>2)+1, input+i); \
memcpy(&tmp, input+i, byteCount & 7); \
xor8bytesIntoInterleavedWords(state+(i>>2), state+(i>>2)+1, &tmp); \
}
void setInterleavedWordsInto8bytes(UINT8* dest, UINT32 even, UINT32 odd)
{
......@@ -93,43 +95,58 @@ void setInterleavedWordsInto8bytes(UINT8* dest, UINT32 even, UINT32 odd)
setInterleavedWordsInto2bytes(dest, even, odd, 3)
}
#define extractLanes(laneCount, state, data) \
{ \
int i; \
for(i=0; i<(laneCount); i++) \
setInterleavedWordsInto8bytes(data+i*8, ((UINT32*)state)[i*2], ((UINT32*)state)[i*2+1]); \
}
#define extractLanes(byteCount, state, data) \
{ \
int i; \
UINT64 tmp=0; \
for(i=0; i<(byteCount-7); i+=8) \
setInterleavedWordsInto8bytes(data+i, ((UINT32*)state)[i>>2], ((UINT32*)state)[(i>>2)+1]); \
setInterleavedWordsInto8bytes(&tmp, ((UINT32*)state)[i>>2], ((UINT32*)state)[(i>>2)+1]); \
memcpy(data+i, &tmp, byteCount & 7); \
}
#else // No interleaving tables
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
#define xorInterleavedLE(rateInLanes, state, input) \
{ \
const UINT32 * pI = (const UINT32 *)input; \
UINT32 * pS = state; \
UINT32 t, x0, x1; \
int i; \
for (i = (rateInLanes)-1; i >= 0; --i) \
{ \
x0 = *(pI++); \
t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1); \
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2); \
t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4); \
t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8); \
x1 = *(pI++); \
t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1); \
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2); \
t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4); \
t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8); \
*(pS++) ^= (UINT16)x0 | (x1 << 16); \
*(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000); \
} \
}
#define xorLanesIntoState(laneCount, state, input) \
xorInterleavedLE(laneCount, state, input)
#define xorInterleavedLE(byteCount, state, input) \
{ \
const UINT32 * pI = (const UINT32 *)input; \
UINT32 * pS = state; \
UINT32 t, x0, x1; \
int i; \
for (i = (byteCount)-8; i >= 0; i-=8) \
{ \
x0 = *(pI++); \
t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1); \
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2); \
t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4); \
t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8); \
x1 = *(pI++); \
t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1); \
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2); \
t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4); \
t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8); \
*(pS++) ^= (UINT16)x0 | (x1 << 16); \
*(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000); \
} \
x0 = byteCount >= 4 ? *(pI++) : *(pI++) & 0xffffffffu >> (8*((4-byteCount) & 3)); \
t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1); \
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2); \
t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4); \
t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8); \
x1 = byteCount < 4 ? 0 : *(pI++) & 0xffffffffu >> (8*((4-byteCount) & 3)); \
t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1); \
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2); \
t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4); \
t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8); \
*(pS++) ^= (UINT16)x0 | (x1 << 16); \
*(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000); \
}
#define xorLanesIntoState(byteCount, state, input) \
xorInterleavedLE(byteCount, state, input)
#else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
......@@ -164,12 +181,14 @@ void xor8bytesIntoInterleavedWords(UINT32* evenAndOdd, const UINT8* source)
evenAndOdd[1] ^= (UINT32)(evenAndOddWord >> 32);
}
#define xorLanesIntoState(laneCount, state, input) \
{ \
int i; \
for(i=0; i<(laneCount); i++) \
xor8bytesIntoInterleavedWords(state+i*2, input+i*8); \
}
#define xorLanesIntoState(byteCount, state, input) \
{ \
int i; UINT64 tmp=0; \
for(i=0; i<(byteCount-7); i+=8) \
xor8bytesIntoInterleavedWords(((char*)state)+i, input+i); \
memcpy(state+i, &tmp, byteCount & 7); \
xor8bytesIntoInterleavedWords(((char*)state)+i, &tmp); \
}
#endif // Endianness
......@@ -206,11 +225,13 @@ void setInterleavedWordsInto8bytes(UINT8* dest, UINT32* evenAndOdd)
#endif // Endianness
}
#define extractLanes(laneCount, state, data) \
#define extractLanes(byteCount, state, data) \
{ \
int i; \
for(i=0; i<(laneCount); i++) \
setInterleavedWordsInto8bytes(data+i*8, (UINT32*)state+i*2); \
int i; UINT64 tmp=0; \
for(i=0; i<(byteCount-7); i+=8) \
setInterleavedWordsInto8bytes(data+i, (UINT32*)state+i>>2); \
setInterleavedWordsInto8bytes(&tmp, (UINT32*)state+i>>2;); \
memcpy(data+i, &tmp, byteCount & 7); \
}
#endif // With or without interleaving tables
......@@ -261,30 +282,31 @@ void KeccakInitializeState(keccak_state state)
memset(state, 0, 200);
}
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int byteCount)
{
extractLanes(laneCount, state, (char*)data)
extractLanes(byteCount, state, (char*)data)
}
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int byteCount)
{
xorLanesIntoState(laneCount, state, (char*)data)
xorLanesIntoState(byteCount, state, (char*)data)
}
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int byteCount)
{
xorLanesIntoState(laneCount, state, (char*)data);
extractLanes(laneCount, state, (char*)data);
xorLanesIntoState(byteCount, state, (char*)data);
extractLanes(byteCount, state, (char*)data);
}
void KeccakDecrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakDecrypt(keccak_state state, UINT64 *data, unsigned int byteCount)
{
UINT64 tmp[laneCount];
UINT64 tmp[(byteCount>>3)+1];
int i;
tmp[(byteCount>>3)]=0;
extractLanes(laneCount, state, (char*)tmp);
for(i=0; i<laneCount; i++) {
extractLanes(byteCount, state, (char*)tmp);
for(i=0; i<byteCount-7; i+=8) {
data[i] ^= tmp[i];
}
xorLanesIntoState(laneCount, state, (char*)data);
xorLanesIntoState(byteCount, state, (char*)data);
}
......@@ -220,116 +220,143 @@ void KeccakInitialize()
{
}
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int byteCount)
{
UINT64 m = 0xffffffffffffffffull;
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
memcpy(data, state, laneCount*8);
memcpy(data, state, byteCount);
#else
unsigned int i;
for(i=0; i<laneCount; i++)
fromWordToBytes(data+i, ((const UINT64*)state)[i]);
for(i=0; i<byteCount-7; i+=8)
fromWordToBytes(data+i>>3, ((const UINT64*)state)[i>>3]);
#endif
#ifdef UseBebigokimisa
switch(laneCount) {
case 25: case 24: case 23: case 22: case 21:
data[20] = ~data[20];
case 20: case 19: case 18:
data[17] = ~data[17];
case 17: case 16: case 15: case 14: case 13:
data[12] = ~data[12];
case 12: case 11: case 10: case 9:
data[ 8] = ~data[ 8];
case 8: case 7: case 6: case 5: case 4: case 3:
data[ 2] = ~data[ 2];
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
m >>= ((8-byteCount) & 7)*8;
#else
m <<= ((8-byteCount) & 7)*8;
#endif
switch((byteCount+7)>>3) {
case 25: case 24: case 23: case 22: m = 0xffffffffffffffffull;
case 21:
data[20] ^= m; m = 0xffffffffffffffffull;
case 20: case 19: m = 0xffffffffffffffffull; case 18:
data[17] ^= m; m = 0xffffffffffffffffull;
case 17: case 16: case 15: case 14: m = 0xffffffffffffffffull; case 13:
data[12] ^= m; m = 0xffffffffffffffffull;
case 12: case 11: case 10: m = 0xffffffffffffffffull; case 9:
data[ 8] ^= m; m = 0xffffffffffffffffull;
case 8: case 7: case 6: case 5: case 4: m = 0xffffffffffffffffull; case 3:
data[ 2] ^= m; m = 0xffffffffffffffffull;
case 2:
data[ 1] = ~data[ 1];
data[ 1] ^= m;
}
#endif
}
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int byteCount)
{
unsigned int i;
for(i=0; i<laneCount; i++) {
UINT64 m = 0xffffffffffffffffull;
for(i=0; i<byteCount-7; i+=8) {
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
state[i] ^= data[i];
state[i>>3] ^= data[i>>3];
#else
UINT64 tmp;
fromWordToBytes(&tmp, data[i]);
state[i] ^= tmp;
fromWordToBytes(&tmp, data[i>>3]);
state[i>>3] ^= tmp;
#endif
}
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
m >>= ((8-byteCount) & 7)*8;
if(byteCount & 7)
state[i>>3] ^= data[i>>3] & m;
#else
m <<= ((8-byteCount) & 7)*8;
if(byteCount & 7) {
fromWordToBytes(&tmp, data[i>>3] & m);
state[i>>3] ^= data[i>>3] & m;
}
#endif
}
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int byteCount)
{
unsigned int i;
for(i=0; i<laneCount; i++) {
UINT64 m = 0xffffffffffffffffull;
for(i=0; i<byteCount-7; i+=8) {
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
data[i] = state[i] ^= data[i];
data[i>>3] = state[i>>3] ^= data[i>>3];
#else
UINT64 tmp;
fromWordToBytes(&tmp, data[i]);
tmp = state[i] ^= tmp;
fromWordToBytes(data+i, tmp);
fromWordToBytes(&tmp, data[i>>3]);
tmp = state[i>>3] ^= tmp;
fromWordToBytes(data+i>>3, tmp);
#endif
}
#ifdef UseBebigokimisa
switch(laneCount) {
case 25: case 24: case 23: case 22: case 21:
data[20] = ~data[20];
case 20: case 19: case 18:
data[17] = ~data[17];
case 17: case 16: case 15: case 14: case 13:
data[12] = ~data[12];
case 12: case 11: case 10: case 9:
data[ 8] = ~data[ 8];
case 8: case 7: case 6: case 5: case 4: case 3:
data[ 2] = ~data[ 2];
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
m >>= ((8-byteCount) & 7)*8;
#else
m <<= ((8-byteCount) & 7)*8;
#endif
switch((byteCount+7)>>3) {
case 25: case 24: case 23: case 22: m = 0xffffffffffffffffull;
case 21:
data[20] ^= m; m = 0xffffffffffffffffull;
case 20: case 19: m = 0xffffffffffffffffull; case 18:
data[17] ^= m; m = 0xffffffffffffffffull;
case 17: case 16: case 15: case 14: m = 0xffffffffffffffffull; case 13:
data[12] ^= m; m = 0xffffffffffffffffull;
case 12: case 11: case 10: m = 0xffffffffffffffffull; case 9:
data[ 8] ^= m; m = 0xffffffffffffffffull;
case 8: case 7: case 6: case 5: case 4: m = 0xffffffffffffffffull; case 3:
data[ 2] ^= m; m = 0xffffffffffffffffull;
case 2:
data[ 1] = ~data[ 1];
data[ 1] ^= m;
}
#endif
}
void KeccakDecrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
void KeccakDecrypt(keccak_state state, UINT64 *data, unsigned int byteCount)
{
unsigned int i;
for(i=0; i<laneCount; i++) {
UINT64 m = 0xffffffffffffffffull;
for(i=0; i<byteCount-7; i+=8) {
UINT64 tmp;
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
tmp = data[i] ^ state[i];
state[i] = data[i];
data[i] = tmp;
tmp = data[i>>3] ^ state[i>>3];
state[i>>3] = data[i>>3];
data[i>>3] = tmp;
#else
UINT64 tmp1;
fromWordToBytes(&tmp, data[i]);
tmp1 = tmp ^ state[i];
state[i] = tmp;
fromWordToBytes(data+i, tmp1);
fromWordToBytes(&tmp, data[i>>3]);
tmp1 = tmp ^ state[i>>3];
state[i>>3] = tmp;
fromWordToBytes(data+i>>3, tmp1);
#endif
}
#ifdef UseBebigokimisa
switch(laneCount) {
case 25: case 24: case 23: case 22: case 21:
data[20] = ~data[20];
state[20] = ~state[20];
case 20: case 19: case 18:
data[17] = ~data[17];
state[17] = ~state[17];
case 17: case 16: case 15: case 14: case 13:
data[12] = ~data[12];
state[12] = ~state[12];
case 12: case 11: case 10: case 9:
data[ 8] = ~data[ 8];
state[ 8] = ~state[ 8];
case 8: case 7: case 6: case 5: case 4: case 3:
data[ 2] = ~data[ 2];
state[ 2] = ~state[ 2];
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
m >>= ((8-byteCount) & 7)*8;
#else
m <<= ((8-byteCount) & 7)*8;
#endif
switch((byteCount+7)>>3) {
case 25: case 24: case 23: case 22: m = 0xffffffffffffffffull;
case 21:
data[20] ^= m; state[20] ^= m; m = 0xffffffffffffffffull;
case 20: case 19: m = 0xffffffffffffffffull; case 18:
data[17] ^= m; state[17] ^= m; m = 0xffffffffffffffffull;
case 17: case 16: case 15: case 14: m = 0xffffffffffffffffull; case 13:
data[12] ^= m; state[12] ^= m; m = 0xffffffffffffffffull;
case 12: case 11: case 10: m = 0xffffffffffffffffull; case 9:
data[ 8] ^= m; state[ 8] ^= m; m = 0xffffffffffffffffull;
case 8: case 7: case 6: case 5: case 4: m = 0xffffffffffffffffull; case 3:
data[ 2] ^= m; state[ 2] ^= m; m = 0xffffffffffffffffull;
case 2:
data[ 1] = ~data[ 1];
state[ 1] = ~state[ 1];
data[ 1] ^= m; state[ 1] ^= m;
}
#endif
}
......@@ -16,6 +16,10 @@ ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
AM_CPPFLAGS = $(EXAMPLE_CFLAGS)
lib_LTLIBRARIES = libkeccak.la
libkeccak_la_SOURCES = KeccakF-1600-opt@ws@.c
if ASM
libkeccak_la_SOURCES = KeccakF-1600-@as@.s KeccakF-1600-@plattform@.c
else
libkeccak_la_SOURCES = KeccakF-1600-@ws@.c
endif
include_HEADERS = KeccakF-1600.h
libkeccak_la_LIBADD =
......@@ -7,24 +7,48 @@ AM_INIT_AUTOMAKE([1.10 -Wall no-define])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
AM_PROG_AS
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT
AC_CHECK_SIZEOF(void *)
case "$ac_cv_sizeof_void_p" in
4)
ws=${ws-32}
ws=${ws-opt32}
;;
8)
ws=${ws-64}
ws=${ws-opt64}
;;
esac
# special optimizations for some plattforms
case "$host_alias" in
arm-linux-androideabi)
CCASFLAGS="$CCASFLAGS -mfpu=neon-vfpv4"
as="inplace-armgcc-ARMv7A-NEON"
enable_asm=yes
plattform=neon
;;
esac
AC_ARG_ENABLE([asm],
[ --enable-asm Turn on assembler sources],
[case "${enableval}" in
yes) asm=true ;;
no) asm=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-asm]) ;;
esac],[asm=false])
AM_CONDITIONAL([ASM], [test x$asm = xtrue])
#x86 on x86_64 plattforms:
#./configure CC="gcc -m32 -mssse3 -DUseSSE" ws=64
#ARM with NEON
#./configure --enable-asm as="inplace-armgcc-ARMv7A-NEON" plattform=neon CC="arm-linux-androideabi-gcc -mfpu=neon-vfpv4" --host=arm-linux-androideabi
LIBTOOL=${CC%gcc*}libtool
AC_SUBST(ws)
AC_SUBST(as)
AC_SUBST(plattform)
AC_SUBST(LIBTOOL)
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
......@@ -25,7 +25,7 @@ $4000 Constant /kregion
r@ /kregion u> !!kr-size!!
kregion 2@ dup r@ u< IF
2drop /kregion alloc+lock /kregion 2dup kregion 2! THEN
over swap r> safe/string kregion 2! kalloc( ." kalloc: " dup hex. cr ) ;
over swap r> safe/string kregion 2! ( kalloc( ." kalloc: " dup hex. cr ) ;
\ fixed size secrets are assumed to be all 64 bytes long
\ if they are just 32 bytes, the second half is all zero
......
\ keccak wrapper
require 64bit.fs
require unix/mmap.fs
require unix/pthread.fs
require 64bit.fs
require crypto-api.fs
require net2o-err.fs
require kregion.fs
......@@ -23,8 +24,8 @@ c-library keccak
\c while(n>0) {
\c unsigned int p = n >= 128 ? 128 : n;
\c KeccakF(state);
\c KeccakEncrypt(state, data, p>>3);
\c data += p>>3; n-=p;
\c KeccakEncrypt(state, data, p);
\c data = (UINT64*)(((char*)data)+p); n-=p;
\c }
\c return data;
\c }
......@@ -33,8 +34,8 @@ c-library keccak
\c while(n>0) {
\c unsigned int p = n >= 128 ? 128 : n;
\c KeccakF(state);
\c KeccakDecrypt(state, data, p>>3);
\c data += p>>3; n-=p;
\c KeccakDecrypt(state, data, p);
\c data = (UINT64*)(((char*)data)+p); n-=p;
\c }
\c return data;
\c }
......@@ -61,10 +62,10 @@ UValue @keccak
: keccak0 ( -- ) @keccak KeccakInitializeState ;
: keccak* ( -- ) @keccak KeccakF ;
: >keccak ( addr u -- ) 3 rshift @keccak -rot KeccakAbsorb ;
: +keccak ( addr u -- ) 3 rshift @keccak -rot KeccakEncrypt ;
: -keccak ( addr u -- ) 3 rshift @keccak -rot KeccakDecrypt ;
: keccak> ( addr u -- ) 3 rshift @keccak -rot KeccakExtract ;
: >keccak ( addr u -- ) @keccak -rot KeccakAbsorb ;
: +keccak ( addr u -- ) @keccak -rot KeccakEncrypt ;
: -keccak ( addr u -- ) @keccak -rot KeccakDecrypt ;
: keccak> ( addr u -- ) @keccak -rot KeccakExtract ;
\ crypto api integration
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment