Commit 59bcb570 authored by bernd's avatar bernd

Symlinks to keccak

parent 32555204
\ Keccak: Forth version derived from "readable keccak" by Bernd Paysan
\ 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
\ A baseline Keccak (3rd round) implementation.
24 Value keccak-rounds
Create keccakf-rndc
$0000000000000001 , $0000000000008082 , $800000000000808a ,
$8000000080008000 , $000000000000808b , $0000000080000001 ,
$8000000080008081 , $8000000000008009 , $000000000000008a ,
$0000000000000088 , $0000000080008009 , $000000008000000a ,
$000000008000808b , $800000000000008b , $8000000000008089 ,
$8000000000008003 , $8000000000008002 , $8000000000000080 ,
$000000000000800a , $800000008000000a , $8000000080008081 ,
$8000000000008080 , $0000000080000001 , $8000000080008008 ,
Create keccakf-rotc
1 c, 3 c, 6 c, 10 c, 15 c, 21 c, 28 c, 36 c, 45 c, 55 c, 2 c, 14 c,
27 c, 41 c, 56 c, 8 c, 25 c, 43 c, 62 c, 18 c, 39 c, 61 c, 20 c, 44 c,
Create keccakf-piln
10 c, 7 c, 11 c, 17 c, 18 c, 3 c, 5 c, 16 c, 8 c, 21 c, 24 c, 4 c,
15 c, 23 c, 19 c, 13 c, 12 c, 2 c, 20 c, 14 c, 22 c, 9 c, 6 c, 1 c,
\ update the state with given number of rounds
5 cells buffer: bc
25 cells buffer: st
: lrot1 ( x1 -- x2 ) dup 2* swap 0< - ;
: lrot ( x1 n -- x2 ) 2dup lshift >r 64 swap - rshift r> or ;
: xor! ( x addr -- ) dup >r @ xor r> ! ;
: theta1 ( -- )
5 0 DO
0 st i cells + 25 cells bounds DO I @ xor [ 5 cells ]L +LOOP
bc i cells + !
LOOP ;
: theta2 ( -- )
5 0 DO
bc I 4 + 5 mod cells + @
bc I 1 + 5 mod cells + @ lrot1 xor
st i cells + 25 cells bounds DO dup I xor! [ 5 cells ]L +LOOP
drop
LOOP ;
: rhopi ( -- )
st cell+ @
24 0 DO
keccakf-piln I + c@
cells st + dup @
rot keccakf-rotc I + c@ lrot
rot !
LOOP drop ;
: chi ( -- )
st 25 cells bounds DO
I bc 5 cells move
5 0 DO
bc I 1+ 5 mod cells + @ bc I 2 + 5 mod cells + @ and
J I cells + xor!
LOOP
[ 5 cells ]L +LOOP ;
: iota ( round -- )
cells keccakf-rndc + @ st @ xor st ! ;
: keccakf ( -- )
keccak-rounds 0 ?DO theta1 theta2 rhopi chi I iota LOOP ;
: st0 ( -- ) st 25 cells erase ;
: >sponge ( addr u -- )
\ fill in sponge function
st swap bounds DO dup @ I xor! cell+ cell +LOOP drop ;
144 buffer: kpad
: padded>sponge ( addr u1 u2 -- ) >r
\ pad last round
kpad r@ erase tuck kpad swap move
kpad + 1 swap c!
kpad r@ + 1- dup c@ $80 or swap c!
kpad r> >sponge ;
\ No newline at end of file
\ Keccak: Forth version derived from "readable keccak" by Bernd Paysan
\ 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
\ A baseline Keccak (3rd round) implementation.
24 Value keccak-rounds
Create keccakf-rndc
$0000000000000001 , $0000000000008082 , $800000000000808a ,
$8000000080008000 , $000000000000808b , $0000000080000001 ,
$8000000080008081 , $8000000000008009 , $000000000000008a ,
$0000000000000088 , $0000000080008009 , $000000008000000a ,
$000000008000808b , $800000000000008b , $8000000000008089 ,
$8000000000008003 , $8000000000008002 , $8000000000000080 ,
$000000000000800a , $800000008000000a , $8000000080008081 ,
$8000000000008080 , $0000000080000001 , $8000000080008008 ,
Create keccakf-rotc
1 c, 3 c, 6 c, 10 c, 15 c, 21 c, 28 c, 36 c, 45 c, 55 c, 2 c, 14 c,
27 c, 41 c, 56 c, 8 c, 25 c, 43 c, 62 c, 18 c, 39 c, 61 c, 20 c, 44 c,
Create keccakf-piln
10 c, 7 c, 11 c, 17 c, 18 c, 3 c, 5 c, 16 c, 8 c, 21 c, 24 c, 4 c,
15 c, 23 c, 19 c, 13 c, 12 c, 2 c, 20 c, 14 c, 22 c, 9 c, 6 c, 1 c,
\ update the state with given number of rounds
5 cells buffer: bc
25 cells buffer: st
: lrot1 ( x1 -- x2 ) dup 2* swap 0< - ;
: lrot ( x1 n -- x2 ) 2dup lshift >r 64 swap - rshift r> or ;
: xor! ( x addr -- ) dup >r @ xor r> ! ;
: theta1 ( -- )
5 0 DO
0 st i cells + 25 cells bounds DO I @ xor [ 5 cells ]L +LOOP
bc i cells + !
LOOP ;
: theta2 ( -- )
5 0 DO
bc I 4 + 5 mod cells + @
bc I 1 + 5 mod cells + @ lrot1 xor
st i cells + 25 cells bounds DO dup I xor! [ 5 cells ]L +LOOP
drop
LOOP ;
: rhopi ( -- )
st cell+ @
24 0 DO
keccakf-piln I + c@
cells st + dup @
rot keccakf-rotc I + c@ lrot
rot !
LOOP drop ;
: chi ( -- )
st 25 cells bounds DO
I bc 5 cells move
5 0 DO
bc I 1+ 5 mod cells + @ bc I 2 + 5 mod cells + @ and
J I cells + xor!
LOOP
[ 5 cells ]L +LOOP ;
: iota ( round -- )
cells keccakf-rndc + @ st @ xor st ! ;
: keccakf ( -- )
keccak-rounds 0 ?DO theta1 theta2 rhopi chi I iota LOOP ;
: st0 ( -- ) st 25 cells erase ;
: >sponge ( addr u -- )
\ fill in sponge function
st swap bounds DO dup @ I xor! cell+ cell +LOOP drop ;
144 buffer: kpad
: padded>sponge ( addr u1 u2 -- ) >r
\ pad last round
kpad r@ erase tuck kpad swap move
kpad + 1 swap c!
kpad r@ + 1- dup c@ $80 or swap c!
kpad r> >sponge ;
\ No newline at end of file
\ This file has been generated using SWIG and fsi,
\ and is already platform dependent, search for the corresponding
\ fsi-file to compile it where no one has compiled it before ;)
\ GForth has its own dynamic loader and doesn't need addional C-Code.
\ That's why this file contains normal Gforth-code( version 0.6.9 or higher )
\ and could be used directly with include or require.
\ As all comments are stripped during the compilation, please
\ insert the copyright notice of the original file here.
\ ------===< functions >===-------
c-function KeccakInitialize KeccakInitialize -- void
c-function KeccakF KeccakF a -- void
c-function KeccakInitializeState KeccakInitializeState a -- void
c-function KeccakExtract KeccakExtract a a n -- void
c-function KeccakAbsorb KeccakAbsorb a a n -- void
c-function KeccakEncrypt KeccakEncrypt a a n -- void
c-function KeccakDecrypt KeccakDecrypt a a n -- void
#define Unrolling 2
//#define UseBebigokimisa
//#define UseInterleaveTables
#define UseSchedule 3
#define UseSchedule 1
......@@ -235,7 +235,9 @@ void setInterleavedWordsInto8bytes(UINT8* dest, UINT32* evenAndOdd)
#error "Only unrolling 2 is supported by schedule 3."
#endif
void KeccakF(UINT32 *state)
#endif
void KeccakF(keccak_state state)
{
declareABCDE
#if (Unrolling != 24)
......@@ -253,19 +255,19 @@ void KeccakInitialize()
#endif
}
void KeccakInitializeState(unsigned char *state)
void KeccakInitializeState(keccak_state state)
{
memset(state, 0, 200);
}
void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount)
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int laneCount)
{
extractLanes(laneCount, state, data)
}
void KeccakAbsorb(UINT32 *state, const UINT8 *input, unsigned int laneCount)
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int laneCount)
{
xorLanesIntoState(laneCount, state, input)
xorLanesIntoState(laneCount, state, data)
}
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int laneCount)
......
......@@ -211,7 +211,7 @@ void KeccakInitialize()
{
}
void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount)
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int laneCount)
{
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
memcpy(data, state, laneCount*8);
......@@ -219,7 +219,7 @@ void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int
unsigned int i;
for(i=0; i<laneCount; i++)
fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]);
fromWordToBytes(data+i, ((const UINT64*)state)[i]);
#endif
}
......
......@@ -12,7 +12,7 @@ typedef unsigned long keccak_state[25*sizeof(UINT64)/sizeof(unsigned long)];
void KeccakInitialize();
void KeccakF(keccak_state state);
void KeccakInitializeState(keccak_state state);
void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount);
void KeccakExtract(keccak_state state, UINT64 *data, unsigned int laneCount);
void KeccakAbsorb(keccak_state state, UINT64 *data, unsigned int laneCount);
void KeccakEncrypt(keccak_state state, UINT64 *data, unsigned int laneCount);
void KeccakDecrypt(keccak_state state, UINT64 *data, unsigned int laneCount);
......
NDK = $(HOME)/proj/android-toolchain/sysroot
GFORTH = $(HOME)/proj/gforths/gforth-android
CC = arm-linux-androideabi-gcc
LIBTOOL = arm-linux-androideabi-libtool
SUFFIX = .android
include Makefile.forth
......@@ -22,7 +22,7 @@ all: $(TARGETS)
build-libcc-named: $(LIBRARY) $(TARGETS)
$(RMTREE) lib/gforth$(ARCH)/$(VERSION)/libcc-named/
-for i in $(LIBRARY); do ./libforth -e "s\" `pwd`/lib/gforth$(ARCH)/$(VERSION)/libcc-named/\" libcc-named-dir-v 2! libcc-path clear-path libcc-named-dir libcc-path also-path :noname 2drop s\" $(DESTDIR)$(libccdir)\" ; is replace-rpath" $(srcdir)/$$i -e bye; done
-for i in $(LIBRARY); do ./libforth$SUFFIX -e "s\" `pwd`/lib/gforth$(ARCH)/$(VERSION)/libcc-named/\" libcc-named-dir-v 2! libcc-path clear-path libcc-named-dir libcc-path also-path :noname 2drop s\" $(DESTDIR)$(libccdir)\" ; is replace-rpath" $(srcdir)/$$i -e bye; done
libs: build-libcc-named $(LIBRARY)
for i in $(LIBRARY); do \
......
#!/bin/sh
#Copyright (C) 2008,2011 Free Software Foundation, Inc.
#This file is part of Gforth.
#Gforth 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 3
#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, see http://www.gnu.org/licenses/.
ENGINE=${ENGINE:-gforth-x32}
KERNL=$($ENGINE --debug -e bye 2>&1 |grep "Opened image file: "|sed -e 's/Opened image file: //g' -e 's/gforth.fi/kernl*.fi/g')
VERSION=$($ENGINE --version | tr ' ' '/')
#test -f "gforth.fi" && KERNEL="gforth.fi"
if test -f "$ENGINE" -a -f "$KERNEL"; then
$ENGINE --die-on-signal "$@"
else
export includedir=`pwd`/include
$ENGINE -i $KERNL -p ".:~+:~/proj/gforths/gforth-android" exboot.fs startup.fs "$@"
fi
......@@ -22,7 +22,7 @@ require struct0x.fs
require curve25519.fs
require wurstkessel.fs
require wurstkessel-init.fs
require keccak/libkeccak.fs
require libkeccak.fs
require hash-table.fs
require debugging.fs
require mini-oof2.fs
......
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