]> git.cryptolib.org Git - avr-crypto-lib.git/blob - bigint/bigint_adjust.S
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / bigint / bigint_adjust.S
1 /* bigint_adjust.S */
2 /*
3     This file is part of the ARM-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 /*
21 void bigint_adjust(bigint_t *a){
22         while(a->length_B!=0 && a->wordv[a->length_B-1]==0){
23                 a->length_B--;
24         }
25         if(a->length_B==0){
26                 a->info=0;
27                 return;
28         }
29         uint8_t t;
30         uint8_t i = 0x07;
31         t = a->wordv[a->length_B-1];
32         while((t&0x80)==0 && i){
33                 t<<=1;
34                 i--;
35         }
36         SET_FBS(a, i);
37 }
38 */
39 .global bigint_adjust
40 bigint_adjust:
41         movw r30, r24
42         ldd r24, Z+0
43         ldd r25, Z+1
44         ldd r26, Z+3
45         ldd r27, Z+4
46         add r26, r24
47         adc r27, r25
48 20:
49         sbiw r24, 1
50         brmi 30f
51         ld r23, -X
52         tst r23
53         brne 40f
54         rjmp 20b
55 30:
56         std Z+0, r1
57         std Z+0, r1
58         std Z+2, r1
59         ret
60 40:
61         adiw r24, 1
62         std Z+0, r24
63         std Z+1, r25
64         clr r24
65 50:
66         sbrc r23, 0
67         mov r25, r24
68         lsr r23
69         inc r24
70         brpl 50b
71         ldd r23, Z+2
72         andi r23, 0xF8
73         or r23, r25
74         std Z+2, r23
75 bigint_adjust_ret:
76         ret
77
78 /*
79 void bigint_copy(bigint_t *dest, const bigint_t *src){
80         memcpy(dest->wordv, src->wordv, src->length_B);
81         dest->length_B = src->length_B;
82         dest->info = src->info;
83 }
84 */
85 .global bigint_copy
86 bigint_copy:
87         movw r26, r24
88         movw r30, r22
89         /* copy length */
90         ld r24, Z+
91         st X+, r24
92         ld r25, Z+
93         st X+, r25
94         /* copy info */
95         ld r22, Z+
96         st X+, r22
97         /* load wordv pointers */
98         ld r22, Z+
99         ld r23, Z
100         movw r30, r22
101         ld r22, X+
102         ld r23, X
103         movw r26, r22
104 10:
105         sbiw r24, 1
106         brmi bigint_adjust_ret
107         ld r22, Z+
108         st X+, r22
109         rjmp 10b
110