]> git.cryptolib.org Git - avr-crypto-lib.git/blob - twister/gf256mul.S
b269d3a4a1b760d2d372598bb0cbfdf87de1009c
[avr-crypto-lib.git] / twister / gf256mul.S
1 /* gf256mul.S */
2 /*
3     This file is part of the AVR-Crypto-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 /* 
21  * File:        gf256mul.S
22  * Author:      Daniel Otte
23  * Date:        2008-12-19
24  * License:     GPLv3 or later
25  * Description: peasant's algorithm for multiplication in GF(2^8)
26  * 
27  */
28
29 #include <avr/io.h>
30 #define OPTIMIZE_SMALL_A
31
32 /*
33  * param a: r24
34  * param b: r22
35  * param reducer: r20
36  */
37 A = 23
38 B = 22
39 P = 24
40 .global gf256mul
41
42 #ifdef OPTIMIZE_SMALL_A
43 gf256mul:
44         mov A, r24
45         clr r24
46 1:      
47         lsr A
48         breq 4f
49         brcc 2f
50         eor P, B
51 2:
52         lsl B
53         brcc 3f
54         eor B, r20      
55 3:
56         rjmp 1b
57 4:
58         brcc 2f
59         eor P, B
60 2:
61         ret
62
63 #else
64
65 gf256mul:
66         mov r21, r24
67         clr r24
68         ldi r25, 8
69 1:      
70         lsr A
71         brcc 2f
72         eor P, B
73 2:
74         lsl B
75         brcc 3f
76         eor B, r20      
77 3:
78         dec r25
79         brne 1b
80         ret
81
82 #endif