2 # threefish_helper_rc.rb
4 This file is part of the ARM-Crypto-Lib.
5 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 byteshift = (value+3)/8
24 bitshift = value-byteshift*8
25 # printf("%d --> %d,%d\n", value,byteshift,bitshift)
30 ret = byteshift*16+bitshift
34 r00 = [14, 52, 23, 5, 25, 46, 58, 32]
35 r01 = [16, 57, 40, 37, 33, 12, 22, 32]
37 r10 = [46, 33, 17, 44, 39, 13, 25, 8]
38 r11 = [36, 27, 49, 9, 30, 50, 29, 35]
39 r12 = [19, 14, 36, 54, 34, 10, 39, 56]
40 r13 = [37, 42, 39, 56, 24, 17, 43, 22]
42 r20 = [24, 38, 33, 5, 41, 16, 31, 9]
43 r21 = [13, 19, 4, 20, 9, 34, 44, 48]
44 r22 = [ 8, 10, 51, 48, 37, 56, 47, 35]
45 r23 = [47, 55, 13, 41, 31, 51, 46, 52]
46 r24 = [ 8, 49, 34, 47, 12, 4, 19, 23]
47 r25 = [17, 18, 41, 28, 47, 53, 42, 31]
48 r26 = [22, 23, 59, 16, 44, 42, 44, 37]
49 r27 = [37, 52, 17, 25, 30, 41, 25, 20]
51 #################################################
53 printf("threefish256_rc0: .byte ")
54 r00.each{ |x| printf("0x%2.2x, ",convert(x))}
57 printf("threefish256_rc1: .byte ")
58 r01.each{ |x| printf("0x%2.2x, ",convert(x))}
61 #################################################
63 printf("threefish512_rc0: .byte ")
64 r10.each{ |x| printf("0x%2.2x, ",convert(x))}
67 printf("threefish512_rc1: .byte ")
68 r11.each{ |x| printf("0x%2.2x, ",convert(x))}
71 printf("threefish512_rc2: .byte ")
72 r12.each{ |x| printf("0x%2.2x, ",convert(x))}
75 printf("threefish512_rc3: .byte ")
76 r13.each{ |x| printf("0x%2.2x, ",convert(x))}
79 #################################################
81 printf("threefish1024_rc0: .byte ")
82 r20.each{ |x| printf("0x%2.2x, ",convert(x))}
85 printf("threefish1024_rc1: .byte ")
86 r21.each{ |x| printf("0x%2.2x, ",convert(x))}
89 printf("threefish1024_rc2: .byte ")
90 r22.each{ |x| printf("0x%2.2x, ",convert(x))}
93 printf("threefish1024_rc3: .byte ")
94 r23.each{ |x| printf("0x%2.2x, ",convert(x))}
97 printf("threefish1024_rc4: .byte ")
98 r24.each{ |x| printf("0x%2.2x, ",convert(x))}
101 printf("threefish1024_rc5: .byte ")
102 r25.each{ |x| printf("0x%2.2x, ",convert(x))}
105 printf("threefish1024_rc6: .byte ")
106 r26.each{ |x| printf("0x%2.2x, ",convert(x))}
109 printf("threefish1024_rc7: .byte ")
110 r27.each{ |x| printf("0x%2.2x, ",convert(x))}
113 #################################################
117 printf(" uint8_t rc0[8] = { ")
118 8.times{ |x| printf("%2.2d, ",r00[(7 - x)]) }
121 printf(" uint8_t rc1[8] = { ")
122 8.times{ |x| printf("%2.2d, ",r01[(7 - x)]) }
125 printf("threefish256_rc0: .byte ")
126 8.times{ |x| printf("0x%2.2x, ",convert(r00[(7 - x)]) ) }
129 printf("threefish256_rc1: .byte ")
130 8.times{ |x| printf("0x%2.2x, ",convert(r01[(7 - x)]) ) }
133 #################################################
135 printf(" uint8_t rc0[8] = { ")
136 8.times{ |x| printf("%2.2d, ",r10[(7 - x)]) }
139 printf(" uint8_t rc1[8] = { ")
140 8.times{ |x| printf("%2.2d, ",r11[(7 - x)]) }
143 printf(" uint8_t rc2[8] = { ")
144 8.times{ |x| printf("%2.2d, ",r12[(7 - x)]) }
147 printf(" uint8_t rc3[8] = { ")
148 8.times{ |x| printf("%2.2d, ",r13[(7 - x)]) }
152 printf("threefish512_rc0: .byte ")
153 8.times{ |x| printf("0x%2.2x, ",convert(r10[(7 - x)]) ) }
156 printf("threefish512_rc1: .byte ")
157 8.times{ |x| printf("0x%2.2x, ",convert(r11[(7 - x)]) ) }
160 printf("threefish512_rc2: .byte ")
161 8.times{ |x| printf("0x%2.2x, ",convert(r12[(7 - x)]) ) }
164 printf("threefish512_rc3: .byte ")
165 8.times{ |x| printf("0x%2.2x, ",convert(r13[(7 - x)]) ) }
168 #################################################
170 printf(" uint8_t rc0[8] = { ")
171 8.times{ |x| printf("%2.2d, ",r20[(7 - x)]) }
174 printf(" uint8_t rc1[8] = { ")
175 8.times{ |x| printf("%2.2d, ",r21[(7 - x)]) }
178 printf(" uint8_t rc2[8] = { ")
179 8.times{ |x| printf("%2.2d, ",r22[(7 - x)]) }
182 printf(" uint8_t rc3[8] = { ")
183 8.times{ |x| printf("%2.2d, ",r23[(7 - x)]) }
186 printf(" uint8_t rc4[8] = { ")
187 8.times{ |x| printf("%2.2d, ",r24[(7 - x)]) }
190 printf(" uint8_t rc5[8] = { ")
191 8.times{ |x| printf("%2.2d, ",r25[(7 - x)]) }
194 printf(" uint8_t rc6[8] = { ")
195 8.times{ |x| printf("%2.2d, ",r26[(7 - x)]) }
198 printf(" uint8_t rc7[8] = { ")
199 8.times{ |x| printf("%2.2d, ",r27[(7 - x)]) }
202 printf("threefish1024_rc0: .byte ")
203 8.times{ |x| printf("0x%2.2x, ",convert(r20[(7 - x)]) ) }
206 printf("threefish1024_rc1: .byte ")
207 8.times{ |x| printf("0x%2.2x, ",convert(r21[(7 - x)]) ) }
210 printf("threefish1024_rc2: .byte ")
211 8.times{ |x| printf("0x%2.2x, ",convert(r22[(7 - x)]) ) }
214 printf("threefish1024_rc3: .byte ")
215 8.times{ |x| printf("0x%2.2x, ",convert(r23[(7 - x)]) ) }
218 printf("threefish1024_rc4: .byte ")
219 8.times{ |x| printf("0x%2.2x, ",convert(r24[(7 - x)]) ) }
222 printf("threefish1024_rc5: .byte ")
223 8.times{ |x| printf("0x%2.2x, ",convert(r25[(7 - x)]) ) }
226 printf("threefish1024_rc6: .byte ")
227 8.times{ |x| printf("0x%2.2x, ",convert(r26[(7 - x)]) ) }
230 printf("threefish1024_rc7: .byte ")
231 8.times{ |x| printf("0x%2.2x, ",convert(r27[(7 - x)]) ) }