1 /* jh_simple_speed.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "jh_simple.h"
32 static const uint8_t sbox0[] =
33 { 9, 0, 4, 11, 13, 12, 3, 15, 1, 10, 2, 6, 7, 5, 8, 14 };
34 static const uint8_t sbox1[] =
35 { 3, 12, 6, 13, 5, 7, 1, 9, 15, 2, 0, 4, 11, 10, 14, 8 };
37 static const uint8_t round_const_0[] = {
38 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
39 0xb2, 0xfb, 0x13, 0x66, 0xea, 0x95, 0x7d, 0x3e,
40 0x3a, 0xde, 0xc1, 0x75, 0x12, 0x77, 0x50, 0x99,
41 0xda, 0x2f, 0x59, 0x0b, 0x06, 0x67, 0x32, 0x2a,
45 uint8_t jh_l(uint8_t v, uint8_t w){
46 v ^= ((w<<1)^(w>>3)^((w>>2)&2))&0xf;
47 w ^= ((v<<1)^(v>>3)^((v>>2)&2))&0xf;
52 void jh_round(uint8_t* a, const uint8_t* rc){
59 x = ((r&0x80)?sbox1:sbox0)[a[i]>>4];
60 y = ((r&0x40)?sbox1:sbox0)[a[i]&0xf];
65 for(i=1; i<128; i+=2){
66 a[i] = (a[i]<<4)|(a[i]>>4);
70 b[i] = (a[i*2]&0xF0) | (a[i*2+1]>>4);
71 b[64+i] = (a[i*2]<<4) | (a[i*2+1]&0x0F);
75 for(i=64; i<128; i+=1){
76 a[i] = (b[i]<<4)|(b[i]>>4);
81 void jh_next_round_const(uint8_t* a){
91 a[i] = (a[i]<<4)|(a[i]>>4);
95 b[i] = (a[i*2]&0xF0) | (a[i*2+1]>>4);
96 b[16+i] = (a[i*2]<<4) | (a[i*2+1]&0x0F);
100 for(i=16; i<32; i+=1){
101 a[i] = (b[i]<<4)|(b[i]>>4);
105 static const uint8_t idx[]={112,80,48,16,96,64,32,0};
109 void group(uint8_t *a){
112 for(i=0; i<128; ++i){
116 x |= a[j+idx[k]]&0x80;
125 void degroup(uint8_t *a){
140 void jh_encrypt(uint8_t* a){
145 cli_putstr("\r\n== pre group ==\r\n");
146 cli_hexdump_block(a, 128, 4, 16);
150 rc[i] = round_const_0[i];
154 jh_next_round_const(rc);
159 cli_putstr("\r\n== pre degroup ==\r\n");
160 cli_hexdump_block(a, 128, 4, 16);
164 cli_putstr("\r\n== post degroup ==\r\n");
165 cli_hexdump_block(a, 128, 4, 16);