]> git.cryptolib.org Git - avr-crypto-lib.git/blob - noekeon/noekeon_ctr.S
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / noekeon / noekeon_ctr.S
1 /* noekeon_ctr.S */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
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  * \author  Daniel Otte
21  * \email   bg@nerilex.org
22  * \date    2008-08-06
23  * \license GPLv3 or later
24  * 
25  * 
26  * 
27  */
28  
29 .extern noekeon_enc
30
31 /*
32  * void noekeon_ctr_next(void *buffer, const noekeon_ctr_ctx_t *ctx); 
33  */
34 .global noekeon_ctr_next
35 /*
36  * param buffer passed in r24:r25
37  * param ctx    passed in r22:r23
38  */
39 noekeon_ctr_next:
40         /* copy counter to buffer */
41         movw r26, r24 /* copy buffer  pointer to X */
42         movw r30, r22 /* copy counter pointer to Z */  
43         ldi r16, 16
44 1:      
45         ld r0, Z+
46         st X+, r0
47         dec r16
48         brne 1b
49         /* increment counter */ 
50         movw r30, r22 /* copy counter pointer to Z */  
51         ldi r17, 1
52         ldi r16, 15
53         ld  r0, Z
54         add r0, r17
55         st  Z+, r0
56 1:      
57         ld  r0, Z
58         adc r0, r1
59         st  Z+, r0
60         dec r16
61         brne 1b
62         /* call encryption routine */
63         /* we can leave the first param as is, but have to adjust the second to point to the key */
64         //adiw r22, 16
65         ldi r16, 16
66         add r22, r16
67         adc r23, r0
68 //      rcall noekeon_enc
69 //      ret
70         rjmp noekeon_enc /* noekeon_enc will return for us */