]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
+small jh
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Fri, 17 Dec 2010 00:17:21 +0000 (00:17 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Fri, 17 Dec 2010 00:17:21 +0000 (00:17 +0000)
config.h [deleted file]
jh/jh_simple.h
jh/jh_simple_aux.c [new file with mode: 0644]
jh/jh_simple_small_core.c [new file with mode: 0644]
jh/jh_simple_speed.c [deleted file]
jh/jh_simple_speed_core.c [new file with mode: 0644]
mkfiles/jh_simple_small_c.mk [new file with mode: 0644]
mkfiles/jh_simple_speed_c.mk
test_src/config.h
test_src/main-jh-test.c
testport.conf

diff --git a/config.h b/config.h
deleted file mode 100644 (file)
index 04c8cd2..0000000
--- a/config.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* config.h */
-/*
-    This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
-
-    This program 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/>.
-*/
-#ifndef __CONFIG_H__
-#define __CONFIG_H__
-#include <avr/io.h>
-// #define F_CPU 20000000
-// #define F_CPU 16000000         /* oscillator-frequency in Hz */
-// #define F_CPU 14745600
-#define F_CPU 20000000 /* this is out of spec but lets try it */
-
-#define DEBUG_METHOD uart
-
-#include "uart_defs.h"
-
-#define UART0_I 1
-#define UART0_BAUD_RATE  38400
-#define UART0_PARATY     UART_PARATY_NONE
-#define UART0_STOPBITS   UART_STOPBITS_1
-#define UART0_DATABITS   UART_DATABITS_8
-#define UART0_RXBUFFER_SIZE 120
-#define UART0_TXBUFFER_SIZE 120
-#define UART0_SWFLOWCTRL     1
-#define UART0_THRESH_LOW     0
-#define UART0_THRESH_HIGH   32
-
-#define CLI_AUTO_HELP
-
-#endif
-
index 8deb4a7243d98978293858524f204d6ca5443342..b97d7f1ca12d951ce7fde3c960eca5eb35a69495 100644 (file)
@@ -36,10 +36,6 @@ typedef struct {
        uint32_t block_hashed;
 } jh_ctx_t;
 
-void jh_round(uint8_t* a, uint8_t roundno);
-void jh_encrypt(uint8_t* a);
-
-
 
 void jh_init(uint16_t hashlen_b, jh_ctx_t* ctx);
 void jh_nextBlock(jh_ctx_t* ctx, void* block);
diff --git a/jh/jh_simple_aux.c b/jh/jh_simple_aux.c
new file mode 100644 (file)
index 0000000..c48fa63
--- /dev/null
@@ -0,0 +1,114 @@
+/* jh_simple_speed.c */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
+
+    This program 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/>.
+*/
+
+#include <stdint.h>
+#include <avr/pgmspace.h>
+#include <stdlib.h>
+#include <string.h>
+#include "memxor.h"
+#include "jh_simple.h"
+
+#define DEBUG 0
+
+#if DEBUG
+#include "cli.h"
+#endif
+
+
+void jh_init(uint16_t hashlen_b, jh_ctx_t* ctx){
+       memset(ctx->a, 0, 128);
+       ctx->a[0] = hashlen_b>>8;
+       ctx->a[1] = hashlen_b&0xff;
+       jh_encrypt(ctx->a);
+       ctx->block_hashed=0;
+}
+
+void jh_nextBlock(jh_ctx_t* ctx, void* block){
+       memxor(ctx->a, block, 64);
+       jh_encrypt(ctx->a);
+       memxor(ctx->a+64, block, 64);
+       ctx->block_hashed++;
+}
+
+void jh_lastBlock(jh_ctx_t* ctx, void* block, uint16_t length_b){
+       while(length_b>=64*8){
+               jh_nextBlock(ctx, block);
+               block = (uint8_t*)block + 64;
+               length_b -= 64*8;
+       }
+       uint8_t buffer[64];
+       uint64_t total_length;
+       memset(buffer, 0, 64);
+       memcpy(buffer, block, (length_b+7)/8);
+       buffer[length_b/8] |= 0x80>>(length_b%8);
+       total_length=ctx->block_hashed*512+length_b;
+       if(length_b==0){
+
+       }else{
+               jh_nextBlock(ctx, buffer);
+               buffer[0]=0;
+       }
+       memset(buffer+1, 0, 64-8-1);
+       buffer[63] = total_length&0xff;
+       buffer[62] = (total_length>> 8)&0xff;
+       buffer[61] = (total_length>>16)&0xff;
+       buffer[60] = (total_length>>24)&0xff;
+       buffer[59] = (total_length>>32)&0xff;
+       buffer[58] = (total_length>>40)&0xff;
+       buffer[57] = (total_length>>48)&0xff;
+       buffer[56] = (total_length>>56)&0xff;
+       jh_nextBlock(ctx, buffer);
+}
+
+void jh_ctx2hash(void* dest, uint16_t length_b, jh_ctx_t* ctx){
+       memcpy(dest, ctx->a+128-(length_b+7)/8, (length_b+7)/8);
+}
+
+
+void jh224_init(jh_ctx_t* ctx){
+       jh_init(224, ctx);
+}
+
+void jh224_ctx2hash(void* dest, jh_ctx_t* ctx){
+       jh_ctx2hash(dest, 224, ctx);
+}
+
+void jh256_init(jh_ctx_t* ctx){
+       jh_init(256, ctx);
+}
+
+void jh256_ctx2hash(void* dest, jh_ctx_t* ctx){
+       jh_ctx2hash(dest, 256, ctx);
+}
+
+void jh384_init(jh_ctx_t* ctx){
+       jh_init(384, ctx);
+}
+
+void jh384_ctx2hash(void* dest, jh_ctx_t* ctx){
+       jh_ctx2hash(dest, 384, ctx);
+}
+
+void jh512_init(jh_ctx_t* ctx){
+       jh_init(512, ctx);
+}
+
+void jh512_ctx2hash(void* dest, jh_ctx_t* ctx){
+       jh_ctx2hash(dest, 512, ctx);
+}
diff --git a/jh/jh_simple_small_core.c b/jh/jh_simple_small_core.c
new file mode 100644 (file)
index 0000000..c3c97ae
--- /dev/null
@@ -0,0 +1,182 @@
+/* jh_simple_speed.c */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
+
+    This program 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/>.
+*/
+
+#include <stdint.h>
+#include <avr/pgmspace.h>
+#include <stdlib.h>
+#include <string.h>
+#include "memxor.h"
+#include "jh_simple.h"
+
+#define DEBUG 0
+
+#if DEBUG
+#include "cli.h"
+#endif
+
+static uint8_t sbox0[] PROGMEM =
+       {  9,  0,  4, 11, 13, 12,  3, 15,  1, 10,  2,  6,  7,  5,  8, 14 };
+static uint8_t sbox1[] PROGMEM =
+       {  3, 12,  6, 13,  5,  7,  1,  9, 15,  2,  0,  4, 11, 10, 14,  8 };
+
+static uint8_t round_const_0[] PROGMEM = {
+  0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
+  0xb2, 0xfb, 0x13, 0x66, 0xea, 0x95, 0x7d, 0x3e,
+  0x3a, 0xde, 0xc1, 0x75, 0x12, 0x77, 0x50, 0x99,
+  0xda, 0x2f, 0x59, 0x0b, 0x06, 0x67, 0x32, 0x2a,
+};
+
+static
+uint8_t jh_l(uint8_t v, uint8_t w){
+       v ^= ((w<<1)^(w>>3)^((w>>2)&2))&0xf;
+       w ^= ((v<<1)^(v>>3)^((v>>2)&2))&0xf;
+       return v|(w<<4);
+}
+
+static
+void jh_round(uint8_t* a, uint8_t* rc){
+       uint8_t b[128];
+       uint8_t i,r,x,y;
+       for(i=0; i<128; ++i){
+               if(i%4==0){
+                       r = rc[i/4];
+               }
+               x = pgm_read_byte(((r&0x80)?sbox1:sbox0)+(a[i]>>4));
+               y = pgm_read_byte(((r&0x40)?sbox1:sbox0)+(a[i]&0xf));
+               a[i]=jh_l(y,x);
+               r<<=2;
+       }
+       /* pi permutation */
+       for(i=1; i<128; i+=2){
+               a[i] = (a[i]<<4)|(a[i]>>4);
+       }
+       /* P' permutation */
+       for(i=0; i<64; ++i){
+               b[i] = (a[i*2]&0xF0) | (a[i*2+1]>>4);
+               b[64+i] = (a[i*2]<<4) | (a[i*2+1]&0x0F);
+       }
+       memcpy(a,b,64);
+       /* phi permutation */
+       for(i=64; i<128; i+=1){
+               a[i] = (b[i]<<4)|(b[i]>>4);
+       }
+}
+
+static
+void jh_next_round_const(uint8_t* a){
+       uint8_t b[32];
+       uint8_t i,x,y;
+       for(i=0; i<32; ++i){
+               x = pgm_read_byte(sbox0+(a[i]>>4));
+               y = pgm_read_byte(sbox0+(a[i]&0xf));
+               a[i]=jh_l(y,x);
+       }
+       /* pi permutation */
+       for(i=1; i<32; i+=2){
+               a[i] = (a[i]<<4)|(a[i]>>4);
+       }
+       /* P' permutation */
+       for(i=0; i<16; ++i){
+               b[i] = (a[i*2]&0xF0) | (a[i*2+1]>>4);
+               b[16+i] = (a[i*2]<<4) | (a[i*2+1]&0x0F);
+       }
+       memcpy(a,b,16);
+       /* phi permutation */
+       for(i=16; i<32; i+=1){
+               a[i] = (b[i]<<4)|(b[i]>>4);
+       }
+}
+
+
+
+static inline
+void group(uint8_t *a){
+       uint8_t b[128];
+       uint8_t i,x,y;
+       for(i=0; i<128; ++i){
+               x =   (((a[i/8+  0])>>4)&0x8)
+                       | (((a[i/8+ 32])>>5)&0x4)
+                       | (((a[i/8+ 64])>>6)&0x2)
+                       | (((a[i/8+ 96])>>7)&0x1);
+               a[i/8] <<= 1; a[i/8+32]<<=1; a[i/8+64]<<=1; a[i/8+96]<<=1;
+               y =   (((a[i/8+ 16])>>4)&0x8)
+                   | (((a[i/8+ 48])>>5)&0x4)
+                   | (((a[i/8+ 80])>>6)&0x2)
+                   | (((a[i/8+112])>>7)&0x1);
+               a[i/8+16] <<= 1; a[i/8+48]<<=1; a[i/8+80]<<=1; a[i/8+112]<<=1;
+               b[i]= (x<<4)|y;
+       }
+       memcpy(a,b,128);
+}
+
+static inline
+void degroup(uint8_t *a){
+       uint8_t b[128];
+       static uint8_t idx[]={112,80,48,16,96,64,32,0};
+       uint8_t i,j,k,t;
+       for(i=0;i<128;++i){
+               j=i/8;
+               t = a[i];
+               for(k=0; k<8; ++k){
+                       b[j+idx[k]]<<=1; b[j+idx[k]] |= t&1; t>>=1;
+               }
+       }
+       memcpy(a,b,128);
+}
+
+void jh_encrypt(uint8_t* a){
+       uint8_t i;
+       uint8_t rc[32];
+       /* grouping */
+#if DEBUG
+       cli_putstr_P(PSTR("\r\n== pre group ==\r\n"));
+       cli_hexdump_block(a, 128, 4, 16);
+#endif
+       group(a);
+       for(i=0;i<32;++i){
+               rc[i] = pgm_read_byte(&(round_const_0[i]));
+       }
+       for(i=0;i<35;++i){
+               jh_round(a, rc);
+               jh_next_round_const(rc);
+       }
+       uint8_t r,x,y;
+
+       for(i=0; i<128; ++i){
+               if(i%4==0){
+                       r = rc[i/4];
+               }
+               x = pgm_read_byte(((r&0x80)?sbox1:sbox0)+(a[i]>>4));
+               y = pgm_read_byte(((r&0x40)?sbox1:sbox0)+(a[i]&0xf));
+               a[i]=(x<<4)|y;
+               r<<=2;
+       }
+       /* degrouping */
+#if DEBUG
+       cli_putstr_P(PSTR("\r\n== pre degroup ==\r\n"));
+       cli_hexdump_block(a, 128, 4, 16);
+#endif
+       degroup(a);
+#if DEBUG
+       cli_putstr_P(PSTR("\r\n== post degroup ==\r\n"));
+       cli_hexdump_block(a, 128, 4, 16);
+#endif
+}
+
+
diff --git a/jh/jh_simple_speed.c b/jh/jh_simple_speed.c
deleted file mode 100644 (file)
index 6c3e32d..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-/* jh_simple_speed.c */
-/*
-    This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
-
-    This program 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/>.
-*/
-
-#include <stdint.h>
-#include <avr/pgmspace.h>
-#include <stdlib.h>
-#include <string.h>
-#include "memxor.h"
-#include "jh_simple.h"
-#include "jh_tables.h"
-
-#define DEBUG 0
-
-#if DEBUG
-#include "cli.h"
-#endif
-
-void jh_round(uint8_t* a, uint8_t roundno){
-       uint8_t b[128];
-       uint8_t i,r,u,v,x,y;
-       uint8_t *pr;
-       pr = jh_round_const + 32*roundno;
-       for(i=0; i<128; ++i){
-               if(i%4==0){
-                       r = pgm_read_byte(pr++);
-               }
-               b[i]=pgm_read_byte(&(jh_lutbox[((r&0xC0)<<2)|a[i]]));
-               r<<=2;
-       }
-       for(i=0;i<128;++i){
-               u = pgm_read_byte(jh_permutation_table+2*i);
-               v = pgm_read_byte(jh_permutation_table+2*i+1);
-               x = b[u>>1];
-               y = b[v>>1];
-               if(u&1){
-                       x <<= 4;
-               }else{
-                       x &= 0xf0;
-               }
-               if(v&1){
-                       y &= 0x0f;
-               }else{
-                       y >>= 4;
-               }
-               a[i] = x|y;
-       }
-}
-
-uint8_t jh_l_inv(uint8_t a){
-       uint8_t v,w;
-       v = a>>4;
-       w = a&0xf;
-       v ^= ((w<<1)^(w>>3)^((w>>2)&2))&0xf;
-       w ^= ((v<<1)^(v>>3)^((v>>2)&2))&0xf;
-       return w|(v<<4);
-}
-
-void group(uint8_t *a){
-       uint8_t b[128];
-       uint8_t i,x,y;
-       for(i=0; i<128; ++i){
-               x =   (((a[i/8+  0])>>4)&0x8)
-                       | (((a[i/8+ 32])>>5)&0x4)
-                       | (((a[i/8+ 64])>>6)&0x2)
-                       | (((a[i/8+ 96])>>7)&0x1);
-               a[i/8] <<= 1; a[i/8+32]<<=1; a[i/8+64]<<=1; a[i/8+96]<<=1;
-               y =   (((a[i/8+ 16])>>4)&0x8)
-                   | (((a[i/8+ 48])>>5)&0x4)
-                   | (((a[i/8+ 80])>>6)&0x2)
-                   | (((a[i/8+112])>>7)&0x1);
-               a[i/8+16] <<= 1; a[i/8+48]<<=1; a[i/8+80]<<=1; a[i/8+112]<<=1;
-               b[i]= (x<<4)|y;
-       }
-       memcpy(a,b,128);
-}
-
-void degroup(uint8_t *a){
-       uint8_t b[128];
-       uint8_t i,j;
-       for(i=0;i<128;++i){
-               j=i/8;
-           b[j+  0]<<=1; b[j+  0] |= ((a[i])>>7)&1;
-           b[j+ 32]<<=1; b[j+ 32] |= ((a[i])>>6)&1;
-           b[j+ 64]<<=1; b[j+ 64] |= ((a[i])>>5)&1;
-           b[j+ 96]<<=1; b[j+ 96] |= ((a[i])>>4)&1;
-           b[j+ 16]<<=1; b[j+ 16] |= ((a[i])>>3)&1;
-           b[j+ 48]<<=1; b[j+ 48] |= ((a[i])>>2)&1;
-           b[j+ 80]<<=1; b[j+ 80] |= ((a[i])>>1)&1;
-           b[j+112]<<=1; b[j+112] |= ((a[i])>>0)&1;
-       }
-       memcpy(a,b,128);
-}
-
-void jh_encrypt(uint8_t* a){
-       uint8_t i;
-       /* grouping */
-#if DEBUG
-       cli_putstr_P(PSTR("\r\n== pre group ==\r\n"));
-       cli_hexdump_block(a, 128, 4, 16);
-#endif
-       group(a);
-       for(i=0;i<35;++i){
-               jh_round(a, i);
-       }
-       uint8_t r;
-       uint8_t *pr;
-
-       pr = jh_round_const + 32*35;
-       for(i=0; i<128; ++i){
-               if(i%4==0){
-                       r = pgm_read_byte(pr++);
-               }
-               a[i]=jh_l_inv(pgm_read_byte(&(jh_lutbox[((r&0xC0)<<2)|a[i]])));
-               r<<=2;
-       }
-       /* degrouping */
-#if DEBUG
-       cli_putstr_P(PSTR("\r\n== pre degroup ==\r\n"));
-       cli_hexdump_block(a, 128, 4, 16);
-#endif
-       degroup(a);
-#if DEBUG
-       cli_putstr_P(PSTR("\r\n== post degroup ==\r\n"));
-       cli_hexdump_block(a, 128, 4, 16);
-#endif
-}
-
-void jh_init(uint16_t hashlen_b, jh_ctx_t* ctx){
-       memset(ctx->a, 0, 128);
-       ctx->a[0] = hashlen_b>>8;
-       ctx->a[1] = hashlen_b&0xff;
-       jh_encrypt(ctx->a);
-       ctx->block_hashed=0;
-}
-
-void jh_nextBlock(jh_ctx_t* ctx, void* block){
-       memxor(ctx->a, block, 64);
-       jh_encrypt(ctx->a);
-       memxor(ctx->a+64, block, 64);
-       ctx->block_hashed++;
-}
-
-void jh_lastBlock(jh_ctx_t* ctx, void* block, uint16_t length_b){
-       while(length_b>=64*8){
-               jh_nextBlock(ctx, block);
-               block = (uint8_t*)block + 64;
-               length_b -= 64*8;
-       }
-       uint8_t buffer[64];
-       uint64_t total_length;
-       memset(buffer, 0, 64);
-       memcpy(buffer, block, (length_b+7)/8);
-       buffer[length_b/8] |= 0x80>>(length_b%8);
-       total_length=ctx->block_hashed*512+length_b;
-       if(length_b==0){
-
-       }else{
-               jh_nextBlock(ctx, buffer);
-               buffer[0]=0;
-       }
-       memset(buffer+1, 0, 64-8-1);
-       buffer[63] = total_length&0xff;
-       buffer[62] = (total_length>> 8)&0xff;
-       buffer[61] = (total_length>>16)&0xff;
-       buffer[60] = (total_length>>24)&0xff;
-       buffer[59] = (total_length>>32)&0xff;
-       buffer[58] = (total_length>>40)&0xff;
-       buffer[57] = (total_length>>48)&0xff;
-       buffer[56] = (total_length>>56)&0xff;
-       jh_nextBlock(ctx, buffer);
-}
-
-void jh_ctx2hash(void* dest, uint16_t length_b, jh_ctx_t* ctx){
-       memcpy(dest, ctx->a+128-(length_b+7)/8, (length_b+7)/8);
-}
-
-
-void jh224_init(jh_ctx_t* ctx){
-       jh_init(224, ctx);
-}
-
-void jh224_ctx2hash(void* dest, jh_ctx_t* ctx){
-       jh_ctx2hash(dest, 224, ctx);
-}
-
-void jh256_init(jh_ctx_t* ctx){
-       jh_init(256, ctx);
-}
-
-void jh256_ctx2hash(void* dest, jh_ctx_t* ctx){
-       jh_ctx2hash(dest, 256, ctx);
-}
-
-void jh384_init(jh_ctx_t* ctx){
-       jh_init(384, ctx);
-}
-
-void jh384_ctx2hash(void* dest, jh_ctx_t* ctx){
-       jh_ctx2hash(dest, 384, ctx);
-}
-
-void jh512_init(jh_ctx_t* ctx){
-       jh_init(512, ctx);
-}
-
-void jh512_ctx2hash(void* dest, jh_ctx_t* ctx){
-       jh_ctx2hash(dest, 512, ctx);
-}
diff --git a/jh/jh_simple_speed_core.c b/jh/jh_simple_speed_core.c
new file mode 100644 (file)
index 0000000..6ff0072
--- /dev/null
@@ -0,0 +1,148 @@
+/* jh_simple_speed.c */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
+
+    This program 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/>.
+*/
+
+#include <stdint.h>
+#include <avr/pgmspace.h>
+#include <stdlib.h>
+#include <string.h>
+#include "memxor.h"
+#include "jh_simple.h"
+#include "jh_tables.h"
+
+#define DEBUG 0
+
+#if DEBUG
+#include "cli.h"
+#endif
+
+static
+void jh_round(uint8_t* a, uint8_t roundno){
+       uint8_t b[128];
+       uint8_t i,r,u,v,x,y;
+       uint8_t *pr;
+       pr = jh_round_const + 32*roundno;
+       for(i=0; i<128; ++i){
+               if(i%4==0){
+                       r = pgm_read_byte(pr++);
+               }
+               b[i]=pgm_read_byte(&(jh_lutbox[((r&0xC0)<<2)|a[i]]));
+               r<<=2;
+       }
+       for(i=0;i<128;++i){
+               u = pgm_read_byte(jh_permutation_table+2*i);
+               v = pgm_read_byte(jh_permutation_table+2*i+1);
+               x = b[u>>1];
+               y = b[v>>1];
+               if(u&1){
+                       x <<= 4;
+               }else{
+                       x &= 0xf0;
+               }
+               if(v&1){
+                       y &= 0x0f;
+               }else{
+                       y >>= 4;
+               }
+               a[i] = x|y;
+       }
+}
+
+static
+uint8_t jh_l_inv(uint8_t a){
+       uint8_t v,w;
+       v = a>>4;
+       w = a&0xf;
+       v ^= ((w<<1)^(w>>3)^((w>>2)&2))&0xf;
+       w ^= ((v<<1)^(v>>3)^((v>>2)&2))&0xf;
+       return w|(v<<4);
+}
+
+static inline
+void group(uint8_t *a){
+       uint8_t b[128];
+       uint8_t i,x,y;
+       for(i=0; i<128; ++i){
+               x =   (((a[i/8+  0])>>4)&0x8)
+                       | (((a[i/8+ 32])>>5)&0x4)
+                       | (((a[i/8+ 64])>>6)&0x2)
+                       | (((a[i/8+ 96])>>7)&0x1);
+               a[i/8] <<= 1; a[i/8+32]<<=1; a[i/8+64]<<=1; a[i/8+96]<<=1;
+               y =   (((a[i/8+ 16])>>4)&0x8)
+                   | (((a[i/8+ 48])>>5)&0x4)
+                   | (((a[i/8+ 80])>>6)&0x2)
+                   | (((a[i/8+112])>>7)&0x1);
+               a[i/8+16] <<= 1; a[i/8+48]<<=1; a[i/8+80]<<=1; a[i/8+112]<<=1;
+               b[i]= (x<<4)|y;
+       }
+       memcpy(a,b,128);
+}
+
+static inline
+void degroup(uint8_t *a){
+       uint8_t b[128];
+       uint8_t i,j;
+       for(i=0;i<128;++i){
+               j=i/8;
+           b[j+  0]<<=1; b[j+  0] |= ((a[i])>>7)&1;
+           b[j+ 32]<<=1; b[j+ 32] |= ((a[i])>>6)&1;
+           b[j+ 64]<<=1; b[j+ 64] |= ((a[i])>>5)&1;
+           b[j+ 96]<<=1; b[j+ 96] |= ((a[i])>>4)&1;
+           b[j+ 16]<<=1; b[j+ 16] |= ((a[i])>>3)&1;
+           b[j+ 48]<<=1; b[j+ 48] |= ((a[i])>>2)&1;
+           b[j+ 80]<<=1; b[j+ 80] |= ((a[i])>>1)&1;
+           b[j+112]<<=1; b[j+112] |= ((a[i])>>0)&1;
+       }
+       memcpy(a,b,128);
+}
+
+void jh_encrypt(uint8_t* a){
+       uint8_t i;
+       /* grouping */
+#if DEBUG
+       cli_putstr_P(PSTR("\r\n== pre group ==\r\n"));
+       cli_hexdump_block(a, 128, 4, 16);
+#endif
+       group(a);
+       for(i=0;i<35;++i){
+               jh_round(a, i);
+       }
+       uint8_t r;
+       uint8_t *pr;
+
+       pr = jh_round_const + 32*35;
+       for(i=0; i<128; ++i){
+               if(i%4==0){
+                       r = pgm_read_byte(pr++);
+               }
+               a[i]=jh_l_inv(pgm_read_byte(&(jh_lutbox[((r&0xC0)<<2)|a[i]])));
+               r<<=2;
+       }
+       /* degrouping */
+#if DEBUG
+       cli_putstr_P(PSTR("\r\n== pre degroup ==\r\n"));
+       cli_hexdump_block(a, 128, 4, 16);
+#endif
+       degroup(a);
+#if DEBUG
+       cli_putstr_P(PSTR("\r\n== post degroup ==\r\n"));
+       cli_hexdump_block(a, 128, 4, 16);
+#endif
+}
+
+
diff --git a/mkfiles/jh_simple_small_c.mk b/mkfiles/jh_simple_small_c.mk
new file mode 100644 (file)
index 0000000..a916a7c
--- /dev/null
@@ -0,0 +1,13 @@
+# Makefile for Grøstl
+ALGO_NAME := JH_SIMPLE_SMALL_C
+
+# comment out the following line for removement of Grøstl from the build process
+HASHES += $(ALGO_NAME)
+
+$(ALGO_NAME)_DIR      := jh/
+$(ALGO_NAME)_INCDIR   := hfal/ memxor/
+$(ALGO_NAME)_OBJ      := jh_simple_small_core.o jh_simple_aux.o  memxor.o 
+$(ALGO_NAME)_TEST_BIN := hfal_jh.o main-jh-test.o $(CLI_STD) $(HFAL_STD)
+$(ALGO_NAME)_NESSIE_TEST      := test nessie
+$(ALGO_NAME)_PERFORMANCE_TEST := performance
+
index acec9f7edd0106e932a2f91ee4408cb42794c6f9..8dcd96f7315ba87c2dd58d2558775410a5b9f91f 100644 (file)
@@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME)
 
 $(ALGO_NAME)_DIR      := jh/
 $(ALGO_NAME)_INCDIR   := hfal/ memxor/
-$(ALGO_NAME)_OBJ      := jh_simple_speed.o jh_tables.o memxor.o 
+$(ALGO_NAME)_OBJ      := jh_simple_speed_core.o jh_simple_aux.o jh_tables.o memxor.o 
 $(ALGO_NAME)_TEST_BIN := hfal_jh.o main-jh-test.o $(CLI_STD) $(HFAL_STD)
 $(ALGO_NAME)_NESSIE_TEST      := test nessie
 $(ALGO_NAME)_PERFORMANCE_TEST := performance
index 04c8cd2531b580a084dee1679d91ba1846ea40b8..46c039f36003426c27e6bf85598e31f4c2213a7e 100644 (file)
@@ -29,7 +29,7 @@
 #include "uart_defs.h"
 
 #define UART0_I 1
-#define UART0_BAUD_RATE  38400
+#define UART0_BAUD_RATE  115200
 #define UART0_PARATY     UART_PARATY_NONE
 #define UART0_STOPBITS   UART_STOPBITS_1
 #define UART0_DATABITS   UART_DATABITS_8
index 48f41dc86d06fc2fd32a1e0196e70a9ecd3ed2b1..c8fba92832d0a5bb0bebdb2cc80ba001a7ce7a43 100644 (file)
@@ -73,18 +73,6 @@ void test256Null(void){
        cli_hexdump_block(hash, 32, 4, 8);
 }
 
-
-void singleround_jh(void){
-       uint8_t data[] = {
-               0x1,0,0,0,0,0,0,0x0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-               0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-           0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-           0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
-       jh_encrypt(data);
-       cli_putstr_P(PSTR("\r\nresult:\r\n"));
-       cli_hexdump_block(data, 128, 4, 16);
-}
-
 /*****************************************************************************
  *  main                                                                                                                                        *
  *****************************************************************************/
@@ -104,7 +92,7 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
        { nessie_str,          NULL, testrun_nessie_jh},
        { performance_str,     NULL, performance_jh},
        { test256_str,         NULL, test256Null},
-       { singleround_str,     NULL, singleround_jh},
+//     { singleround_str,     NULL, singleround_jh},
        { shavs_list_str,      NULL, shavs_listalgos},
        { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
        { shavs_test1_str,     NULL, shavs_test1},
index 92c450e112d946c6929abb7b9dea0aacf9759927..e10ae6156b3362beecbba442ac478690bdb5adf8 100644 (file)
@@ -2,7 +2,7 @@
 
 [PORT]
 port = /dev/ttyUSB1
-baud = 38400
+baud = 115200
 databits = 8
 stopbits = 1
 paraty = none