]> git.cryptolib.org Git - avr-crypto-lib.git/blob - seed-asm.S
further working on seed (openssl supports it :-);
[avr-crypto-lib.git] / seed-asm.S
1 /* seed-asm.S */
2 /*
3     This file is part of the Crypto-avr-lib/microcrypt-lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /**
20  * \file        seed-asm.S
21  * \author      Daniel Otte 
22  * \date        2007-06-1
23  * \brief       SEED parts in assembler for AVR
24  * \par License 
25  * GPLv3 or later
26  * 
27  */
28 #include "avr-asm-macros.S"
29
30 .global bigendian_sum32
31 ; === bigendian_sum32 ===
32 ; function that adds two 32-bit words in the bigendian way and returns the result
33 ;  param1: the first 32-bit word
34 ;       given in r25,r24,r23,22 (r25 is most significant for little endian)
35 ;  param2: the second 32-bit word
36 ;       given in r21,r20,r19,18 (r21 is most significant for little endian)
37 ;  modifys: 
38 bigendian_sum32:
39         add r25, r21
40         adc r24, r20
41         adc r23, r19
42         adc r22, r18
43         ret
44         
45 .global bigendian_sub32
46 ; === bigendian_sub32 ===
47 ; function that subtracts a 32-bit words from another in the bigendian way and returns the result
48 ;  param1: the minuend 32-bit word
49 ;       given in r25,r24,r23,22 (r25 is most significant for little endian)
50 ;  param2: the subtrahend 32-bit word
51 ;       given in r21,r20,r19,18 (r21 is most significant for little endian)
52 ;  modifys: 
53 bigendian_sub32:
54         sub r25, r21
55         sbc r24, r20
56         sbc r23, r19
57         sbc r22, r18
58         ret
59
60 /******************************************************************************/        
61 /*
62 #define M0 0xfc
63 #define M1 0xf3
64 #define M2 0xcf
65 #define M3 0x3f
66
67 #define X3 (((uint8_t*)(&x))[0])
68 #define X2 (((uint8_t*)(&x))[1])
69 #define X1 (((uint8_t*)(&x))[2])
70 #define X0 (((uint8_t*)(&x))[3])
71
72 #define Z3 (((uint8_t*)(&z))[0])
73 #define Z2 (((uint8_t*)(&z))[1])
74 #define Z1 (((uint8_t*)(&z))[2])
75 #define Z0 (((uint8_t*)(&z))[3])
76
77 uint32_t g_function(uint32_t x){
78         uint32_t z;
79         / * sbox substitution * /
80         X3 = pgm_read_byte(&(seed_sbox2[X3]));
81         X2 = pgm_read_byte(&(seed_sbox1[X2]));
82         X1 = pgm_read_byte(&(seed_sbox2[X1]));
83         X0 = pgm_read_byte(&(seed_sbox1[X0]));
84         / * now the permutation * /
85         Z0 = (X0 & M0) ^ (X1 & M1) ^ (X2 & M2) ^ (X3 & M3);
86         Z1 = (X0 & M1) ^ (X1 & M2) ^ (X2 & M3) ^ (X3 & M0);
87         Z2 = (X0 & M2) ^ (X1 & M3) ^ (X2 & M0) ^ (X3 & M1);
88         Z3 = (X0 & M3) ^ (X1 & M0) ^ (X2 & M1) ^ (X3 & M2);
89         return z;
90 }
91 */
92 M0 = 0xfc
93 M1 = 0xf3
94 M2 = 0xcf
95 M3 = 0x3f
96 X0 = 18
97 X1 = 19
98 X2 = 20
99 X3 = 21
100 Z0 = 25
101 Z1 = 24
102 Z2 = 23
103 Z3 = 22
104 T0 = X0
105 T1 = 26
106 T2 = 27
107 T3 = X1
108 /*
109  *  param x: r22:r25
110  *  X0 = R25
111  *  X1 = R24
112  *  X2 = R23
113  *  X3 = R22
114  */    
115 .global g_function
116 g_function:
117         ldi r30, lo8(seed_sbox1)
118         ldi r31, hi8(seed_sbox1)
119         movw r26, r30
120         add r30, Z2
121         adc r31, r1
122         lpm X2, Z
123         movw r30, r26
124         add r30, Z0
125         adc r31, r1
126         lpm X0, Z
127         inc r27 /* switch X to point to sbox2 */
128         movw r30, r26
129         add r30, Z3
130         adc r31, r1
131         lpm X3, Z
132         movw r30, r26
133         add r30, Z1
134         adc r31, r1
135         lpm X1, Z
136         /* now the secound part */
137         mov Z0, X0
138         mov Z1, X0
139         mov Z2, X0
140         mov Z3, X0
141         andi Z0, M0
142         andi Z1, M1
143         andi Z2, M2
144         andi Z3, M3     
145         mov T0, X1
146         mov T1, X1
147         mov T2, X1
148         ; mov T3, X1 /* T3 = X1 */
149         andi T0, M1
150         andi T1, M2
151         andi T2, M3
152         andi T3, M0
153         eor Z0, T0
154         eor Z1, T1
155         eor Z2, T2
156         eor Z3, T3
157         mov T0, X2
158         mov T1, X2
159         mov T2, X2
160         mov T3, X2
161         andi T0, M2
162         andi T1, M3
163         andi T2, M0
164         andi T3, M1
165         eor Z0, T0
166         eor Z1, T1
167         eor Z2, T2
168         eor Z3, T3
169         mov T0, X3
170         mov T1, X3
171         mov T2, X3
172         mov T3, X3
173         andi T0, M3
174         andi T1, M0
175         andi T2, M1
176         andi T3, M2
177         eor Z0, T0
178         eor Z1, T1
179         eor Z2, T2
180         eor Z3, T3
181         ret
182
183 seed_sbox1:
184 .byte   169,  133,  214,  211,   84,   29,  172,   37 
185 .byte    93,   67,   24,   30,   81,  252,  202,   99 
186 .byte    40,   68,   32,  157,  224,  226,  200,   23 
187 .byte   165,  143,    3,  123,  187,   19,  210,  238 
188 .byte   112,  140,   63,  168,   50,  221,  246,  116 
189 .byte   236,  149,   11,   87,   92,   91,  189,    1 
190 .byte    36,   28,  115,  152,   16,  204,  242,  217 
191 .byte    44,   231, 114,  131,  155,  209,  134,  201 
192 .byte    96,   80,  163,  235,   13,  182,  158,   79 
193 .byte   183,   90,  198,  120,  166,   18,  175,  213 
194 .byte    97,  195,  180,   65,   82,  125,  141,    8 
195 .byte    31,  153,    0,   25,    4,   83,  247,  225 
196 .byte   253,  118,   47,   39,  176,  139,   14,  171 
197 .byte   162,  110,  147,   77,  105,  124,    9,   10 
198 .byte   191,  239,  243,  197,  135,   20,  254,  100 
199 .byte   222,   46,   75,   26,    6,   33,  107,  102 
200 .byte     2,  245,  146,  138,   12,  179,  126,  208 
201 .byte   122,   71,  150,  229,   38,  128,  173,  223 
202 .byte   161,   48,   55,  174,   54,   21,   34,   56 
203 .byte   244,  167,   69,   76,  129,  233,  132,  151 
204 .byte    53,  203,  206,   60,  113,   17,  199,  137 
205 .byte   117,  251,  218,  248,  148,   89,  130,  196 
206 .byte   255,   73,   57,  103,  192,  207,  215,  184 
207 .byte    15,  142,   66,   35,  145,  108,  219,  164 
208 .byte    52,  241,   72,  194,  111,   61,   45,   64 
209 .byte   190,   62,  188,  193,  170,  186,   78,   85 
210 .byte    59,  220,  104,  127,  156,  216,   74,   86 
211 .byte   119,  160,  237,   70,  181,   43,  101,  250 
212 .byte   227,  185,  177,  159,   94,  249,  230,  178 
213 .byte    49,  234,  109,   95,  228,  240,  205,  136 
214 .byte    22,   58,   88,  212,   98,   41,    7,   51 
215 .byte   232,   27,    5,  121,  144,  106,   42,  154
216
217
218 seed_sbox2:
219 .byte    56,  232,   45,  166,  207,  222,  179,  184 
220 .byte   175,   96,   85,  199,   68,  111,  107,   91 
221 .byte   195,   98,   51,  181,   41,  160,  226,  167 
222 .byte   211,  145,   17,    6,   28,  188,   54,   75 
223 .byte   239,  136,  108,  168,   23,  196,   22,  244 
224 .byte   194,   69,  225,  214,   63,   61,  142,  152 
225 .byte    40,   78,  246,   62,  165,  249,   13,  223 
226 .byte   216,   43,  102,  122,   39,   47,  241,  114 
227 .byte    66,  212,   65,  192,  115,  103,  172,  139 
228 .byte   247,  173,  128,   31,  202,   44,  170,   52 
229 .byte   210,   11,  238,  233,   93,  148,   24,  248 
230 .byte    87,  174,    8,  197,   19,  205,  134,  185 
231 .byte   255,  125,  193,   49,  245,  138,  106,  177 
232 .byte   209,   32,  215,    2,   34,    4,  104,  113 
233 .byte     7,  219,  157,  153,   97,  190,  230,   89 
234 .byte   221,   81,  144,  220,  154,  163,  171,  208 
235 .byte   129,   15,   71,   26,  227,  236,  141,  191 
236 .byte   150,  123,   92,  162,  161,   99,   35,   77 
237 .byte   200,  158,  156,   58,   12,   46,  186,  110 
238 .byte   159,   90,  242,  146,  243,   73,  120,  204 
239 .byte    21,  251,  112,  117,  127,   53,   16,    3 
240 .byte   100,  109,  198,  116,  213,  180,  234,    9 
241 .byte   118,   25,  254,   64,   18,  224,  189,    5 
242 .byte   250,    1,  240,   42,   94,  169,   86,   67 
243 .byte   133,   20,  137,  155,  176,  229,   72,  121 
244 .byte   151,  252,   30,  130,   33,  140,   27,   95 
245 .byte   119,   84,  178,   29,   37,   79,    0,   70 
246 .byte   237,   88,   82,  235,  126,  218,  201,  253 
247 .byte    48,  149,  101,   60,  182,  228,  187,  124 
248 .byte    14,   80,   57,   38,   50,  132,  105,  147 
249 .byte    55,  231,   36,  164,  203,   83,   10,  135 
250 .byte   217,   76,  131,  143,  206,   59,   74,  183 
251
252
253
254
255
256