Commit 2816c0cb authored by bernd's avatar bernd

Threefish as symmetric crypto

parent 5ffb7fd4
......@@ -56,4 +56,6 @@ object class
\G compute a 128 bit checksum
umethod c:cookie ( -- x )
\G compute a different 64 bit checksum
umethod c:tweak! ( x128 -- )
\G set 128 bit tweek (if tweekable)
end-class crypto
NDK = $(HOME)/proj/android-toolchain/sysroot
GFORTH = $(HOME)/proj/gforths/gforth-android
GFORTH = $(HOME)/proj/gforths/android
CC = arm-linux-androideabi-gcc
LIBTOOL = arm-linux-androideabi-libtool
SUFFIX = .android
......
# Generic makefile, for crosscompiling use make -f Makefile.<target>
INCLUDES = -I$(NDK)/usr/include -I$(NDK)/usr/local/include/
TOP = $(HOME)/proj/swig-2.0.1-bernd2
SWIG = $(TOP)/preinst-swig
SWIG = /usr/bin/swig
TARGETS = keccak.fsx
LIBRARY = libkeccak.fs
OPTIONS = -forth -no-sectioncomments -stackcomments $(INCLUDES)
......
......@@ -69,8 +69,6 @@ UValue @keccak
\ crypto api integration
require crypto-api.fs
crypto class
keccak# uvar keccak-state
keccak#cks uvar keccak-checksums
......@@ -155,7 +153,8 @@ keccak-init
64#0 keccak-checksums keccak#cks bounds ?DO
I 64@ 64xor 8 +LOOP ; to c:cookie ( -- x )
\G obtain a 64 bit checksum
keccak ' new static-a with-allocater Constant keccak-o
keccak-o crypto-o !
:noname @keccak keccak#max + dup >r 128@ 128xor r> 128! ;
to c:tweak! ( xd -- )
\G set 128 bit tweek
crypto-o @ Constant keccak-o
......@@ -33,8 +33,9 @@ require 64bit.fs
require debugging.fs
require kregion.fs
require libkeccak.fs
require threefish.fs
\ require wurstkessel.fs
\ wurstkessel-o crypto-o !
keccak-o crypto-o !
require rng.fs
require ed25519-donna.fs
require hash-table.fs
......
NDK = $(HOME)/proj/android-toolchain/sysroot
GFORTH = $(HOME)/proj/gforths/android
CC = arm-linux-androideabi-gcc
LIBTOOL = arm-linux-androideabi-libtool
SUFFIX = .android
include Makefile.forth
......@@ -58,6 +58,11 @@ inline void tf_prep(struct tf_ctx *ctx)
ctx->tweak[2] = ctx->tweak[0] ^ ctx->tweak[1];
}
inline void tf_tweak(struct tf_ctx *ctx)
{
ctx->tweak[2] = ctx->tweak[0] ^ ctx->tweak[1];
}
#define PERMUTE(i) \
m = tf_permut[2*i]; \
n = tf_permut[2*i+1]; \
......
\ 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.
\ ----===< int constants ===>-----
1 constant _THREEFISH_H_
\ -------===< structs >===--------
\ tf_ctx
begin-structure tf_ctx
drop 0 72 +field tf_ctx-key
drop 72 24 +field tf_ctx-tweak
drop 96 end-structure
\ ------===< functions >===-------
c-function tf_init tf_init a -- void
c-function tf_prep tf_prep a -- void
c-function tf_encrypt tf_encrypt a a a n -- void
c-function tf_decrypt tf_decrypt a a a -- void
c-function rot_l64 rot_l64 d n -- d
c-function rot_r64 rot_r64 d n -- d
......@@ -21,14 +21,14 @@
#include <stdint.h>
struct tf_ctx {
typedef struct tf_ctx {
uint64_t key[9];
uint64_t tweak[3];
};
} tf_ctx;
void tf_init(struct tf_ctx *ctx);
void tf_prep(struct tf_ctx *ctx);
void tf_tweak(struct tf_ctx *ctx);
void tf_encrypt(struct tf_ctx *ctx, const uint64_t *p, uint64_t *out, int feed);
void tf_decrypt(struct tf_ctx *ctx, const uint64_t *c, uint64_t *out);
......
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