]> git.cryptolib.org Git - avr-crypto-lib.git/blob - memxor.S
2e8223766785f1aefed253cc2f681041e875554a
[avr-crypto-lib.git] / memxor.S
1 /* memxor.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 /* 
21  * File:        memxor.S
22  * Author:      Daniel Otte
23  * Date:        2008-08-07
24  * License:     GPLv3 or later
25  * Description: memxor, XORing one block into another
26  * 
27  */
28  
29 #include <avr/io.h>
30
31
32 .macro push_ p1:req, p2:vararg
33         push \p1
34 .ifnb \p2       
35         push_ \p2
36 .endif
37 .endm
38
39 .macro pop_ p1:req, p2:vararg
40         pop \p1
41 .ifnb \p2       
42         pop_ \p2
43 .endif
44 .endm
45
46 .macro push_range from:req, to:req
47         push \from
48 .if     \to-\from
49         push_range "(\from+1)",\to
50 .endif          
51 .endm
52
53 .macro pop_range from:req, to:req
54         pop \to
55 .if     \to-\from
56         pop_range \from,"(\to-1)"       
57 .endif
58 .endm
59
60 .macro stack_alloc size:req, reg1=r30, reg2=r31
61         in \reg1, _SFR_IO_ADDR(SPL)
62         in \reg2, _SFR_IO_ADDR(SPH)
63         sbiw r30, \size 
64         out  _SFR_IO_ADDR(SPH), \reg2
65         out  _SFR_IO_ADDR(SPL), \reg1
66 .endm
67
68 .macro stack_free size:req, reg1=r30, reg2=r31
69         in \reg1, _SFR_IO_ADDR(SPL)
70         in \reg2, _SFR_IO_ADDR(SPH)
71         adiw r30, \size 
72         out  _SFR_IO_ADDR(SPH), \reg2
73         out  _SFR_IO_ADDR(SPL), \reg1
74 .endm
75
76 /*
77  * void memxor(void* dest, const void* src, uint16_t n);
78  */
79  /*
80   * param dest is passed in r24:r25
81   * param src  is passed in r22:r23
82   * param n    is passed in r20:r21
83   */
84 .global memxor
85 memxor:
86         movw r30, r24
87         movw r26, r22
88         movw r24, r20
89         tst r24
90         brne 1f
91         tst r25
92         breq 2f
93 1:
94         ld r20, X+
95         ld r21, Z
96         eor r20, r21
97         st Z+, r20
98         sbiw r24, 1
99         brne 1b
100 2:
101         ret
102         
103         
104         
105         
106         
107         
108         
109         
110         
111         
112         
113         
114         
115