]> git.cryptolib.org Git - arm-crypto-lib.git/blob - host/threefish_helper_rc.rb
Adding Khazad
[arm-crypto-lib.git] / host / threefish_helper_rc.rb
1 #!/usr/bin/ruby
2 # threefish_helper_rc.rb
3 =begin
4     This file is part of the ARM-Crypto-Lib.
5     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
6
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.
11
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.
16
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/>.
19 =end
20
21
22 def convert(value)
23   byteshift = (value+3)/8
24   bitshift = value-byteshift*8
25 #  printf("%d --> %d,%d\n", value,byteshift,bitshift)
26   if bitshift<0
27     bitshift *= -1
28     bitshift += 0x08
29   end
30   ret = byteshift*16+bitshift
31   return ret
32 end
33
34 r00 = [14, 52, 23,  5, 25, 46, 58, 32]
35 r01 = [16, 57, 40, 37, 33, 12, 22, 32]
36
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]
41
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]
50
51 #################################################
52
53 printf("threefish256_rc0:  .byte ")
54 r00.each{ |x| printf("0x%2.2x, ",convert(x))}
55 puts("")
56
57 printf("threefish256_rc1:  .byte ")
58 r01.each{ |x| printf("0x%2.2x, ",convert(x))}
59 puts("\n\n")
60
61 #################################################
62
63 printf("threefish512_rc0:  .byte ")
64 r10.each{ |x| printf("0x%2.2x, ",convert(x))}
65 puts("")
66
67 printf("threefish512_rc1:  .byte ")
68 r11.each{ |x| printf("0x%2.2x, ",convert(x))}
69 puts("")
70
71 printf("threefish512_rc2:  .byte ")
72 r12.each{ |x| printf("0x%2.2x, ",convert(x))}
73 puts("")
74
75 printf("threefish512_rc3:  .byte ")
76 r13.each{ |x| printf("0x%2.2x, ",convert(x))}
77 puts("\n\n")
78
79 #################################################
80
81 printf("threefish1024_rc0:  .byte ")
82 r20.each{ |x| printf("0x%2.2x, ",convert(x))}
83 puts("")
84
85 printf("threefish1024_rc1:  .byte ")
86 r21.each{ |x| printf("0x%2.2x, ",convert(x))}
87 puts("")
88
89 printf("threefish1024_rc2:  .byte ")
90 r22.each{ |x| printf("0x%2.2x, ",convert(x))}
91 puts("")
92
93 printf("threefish1024_rc3:  .byte ")
94 r23.each{ |x| printf("0x%2.2x, ",convert(x))}
95 puts("")
96
97 printf("threefish1024_rc4:  .byte ")
98 r24.each{ |x| printf("0x%2.2x, ",convert(x))}
99 puts("")
100
101 printf("threefish1024_rc5:  .byte ")
102 r25.each{ |x| printf("0x%2.2x, ",convert(x))}
103 puts("")
104
105 printf("threefish1024_rc6:  .byte ")
106 r26.each{ |x| printf("0x%2.2x, ",convert(x))}
107 puts("")
108
109 printf("threefish1024_rc7:  .byte ")
110 r27.each{ |x| printf("0x%2.2x, ",convert(x))}
111 puts("\n\n")
112
113 #################################################
114
115 puts("REVERSE")
116
117 printf(" uint8_t rc0[8] = { ")
118 8.times{ |x| printf("%2.2d, ",r00[(7 - x)]) }
119 puts("")
120
121 printf(" uint8_t rc1[8] = { ")
122 8.times{ |x| printf("%2.2d, ",r01[(7 - x)]) }
123 puts("")
124
125 printf("threefish256_rc0:  .byte ")
126 8.times{ |x| printf("0x%2.2x, ",convert(r00[(7 - x)]) ) }
127 puts("")
128
129 printf("threefish256_rc1:  .byte ")
130 8.times{ |x| printf("0x%2.2x, ",convert(r01[(7 - x)]) ) }
131 puts("\n\n")
132
133 #################################################
134
135 printf(" uint8_t rc0[8] = { ")
136 8.times{ |x| printf("%2.2d, ",r10[(7 - x)]) }
137 puts("")
138
139 printf(" uint8_t rc1[8] = { ")
140 8.times{ |x| printf("%2.2d, ",r11[(7 - x)]) }
141 puts("")
142
143 printf(" uint8_t rc2[8] = { ")
144 8.times{ |x| printf("%2.2d, ",r12[(7 - x)]) }
145 puts("")
146
147 printf(" uint8_t rc3[8] = { ")
148 8.times{ |x| printf("%2.2d, ",r13[(7 - x)]) }
149 puts("")
150
151
152 printf("threefish512_rc0:  .byte ")
153 8.times{ |x| printf("0x%2.2x, ",convert(r10[(7 - x)]) ) }
154 puts("")
155
156 printf("threefish512_rc1:  .byte ")
157 8.times{ |x| printf("0x%2.2x, ",convert(r11[(7 - x)]) ) }
158 puts("")
159
160 printf("threefish512_rc2:  .byte ")
161 8.times{ |x| printf("0x%2.2x, ",convert(r12[(7 - x)]) ) }
162 puts("")
163
164 printf("threefish512_rc3:  .byte ")
165 8.times{ |x| printf("0x%2.2x, ",convert(r13[(7 - x)]) ) }
166 puts("\n\n")
167
168 #################################################
169
170 printf(" uint8_t rc0[8] = { ")
171 8.times{ |x| printf("%2.2d, ",r20[(7 - x)]) }
172 puts("")
173
174 printf(" uint8_t rc1[8] = { ")
175 8.times{ |x| printf("%2.2d, ",r21[(7 - x)]) }
176 puts("")
177
178 printf(" uint8_t rc2[8] = { ")
179 8.times{ |x| printf("%2.2d, ",r22[(7 - x)]) }
180 puts("")
181
182 printf(" uint8_t rc3[8] = { ")
183 8.times{ |x| printf("%2.2d, ",r23[(7 - x)]) }
184 puts("")
185
186 printf(" uint8_t rc4[8] = { ")
187 8.times{ |x| printf("%2.2d, ",r24[(7 - x)]) }
188 puts("")
189
190 printf(" uint8_t rc5[8] = { ")
191 8.times{ |x| printf("%2.2d, ",r25[(7 - x)]) }
192 puts("")
193
194 printf(" uint8_t rc6[8] = { ")
195 8.times{ |x| printf("%2.2d, ",r26[(7 - x)]) }
196 puts("")
197
198 printf(" uint8_t rc7[8] = { ")
199 8.times{ |x| printf("%2.2d, ",r27[(7 - x)]) }
200 puts("")
201
202 printf("threefish1024_rc0:  .byte ")
203 8.times{ |x| printf("0x%2.2x, ",convert(r20[(7 - x)]) ) }
204 puts("")
205
206 printf("threefish1024_rc1:  .byte ")
207 8.times{ |x| printf("0x%2.2x, ",convert(r21[(7 - x)]) ) }
208 puts("")
209
210 printf("threefish1024_rc2:  .byte ")
211 8.times{ |x| printf("0x%2.2x, ",convert(r22[(7 - x)]) ) }
212 puts("")
213
214 printf("threefish1024_rc3:  .byte ")
215 8.times{ |x| printf("0x%2.2x, ",convert(r23[(7 - x)]) ) }
216 puts("")
217
218 printf("threefish1024_rc4:  .byte ")
219 8.times{ |x| printf("0x%2.2x, ",convert(r24[(7 - x)]) ) }
220 puts("")
221
222 printf("threefish1024_rc5:  .byte ")
223 8.times{ |x| printf("0x%2.2x, ",convert(r25[(7 - x)]) ) }
224 puts("")
225
226 printf("threefish1024_rc6:  .byte ")
227 8.times{ |x| printf("0x%2.2x, ",convert(r26[(7 - x)]) ) }
228 puts("")
229
230 printf("threefish1024_rc7:  .byte ")
231 8.times{ |x| printf("0x%2.2x, ",convert(r27[(7 - x)]) ) }
232 puts("\n\n")
233