3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
20 #include "avr-asm-macros.S"
21 #include "bigint_adjust.S"
22 #include "bigint_add_u.S"
25 /******************************************************************************/
27 void bigint_add_scale_u(bigint_t *dest, const bigint_t *a, uint16_t scale){
30 if(scale>dest->length_B)
31 memset(dest->wordv+dest->length_B, 0, scale-dest->length_B);
32 for(i=scale; i<a->length_B+scale; ++i,++j){
37 dest->wordv[i] = (uint8_t)t;
42 t = dest->wordv[i] + t;
44 dest->wordv[i] = (uint8_t)t;
48 if(dest->length_B < i){
68 .global bigint_add_scale_u
71 /******************************************************************************/
72 /******************************************************************************/
73 /******************************************************************************/
87 movw r30, r24 /* dest ptr */
88 movw r26, r22 /* src ptr */
89 movw r24, r20 /* scale */
90 /* check if scale is zero */
97 10: /* check if src is zero */
108 /* pad dest with zeros to length of SRC_LENGTH + scale */
112 movw r26, TMP_0 /* move SRC_WORDV to X */
117 movw r30, TMP_0 /* move DEST_WORDV to Z */
122 brmi 40f /* no padding needed since DST_LEN > scale */
123 add r30, DST_LEN_0 /* add DST_LEN to Z (DEST_WORDV)*/
125 /* pad and copy src in front of dest */
126 10: /* padding loop */
153 /* Z points at DST_WORDV */
154 /* X points at SRC_WORDV */
155 /* r24:r25 and TMP contain scale - DST_LEN (negativ) */
156 /* set T bit if DST_LEN > SCR_LEN + scale */
164 /* DST_LEN > SRC_LEN + scale && DST_LEN > scale */
166 +-------+-------+ SRC + scale
167 +------+------------+ DST
172 /* DST_LEN <= SRC_LEN + scale && DST_LEN > scale */
174 +-------+-------+ SRC + scale
177 com r24 /* negate r24:r25 ==> DST_LEN - scale */
218 rol r1 /* backup carry */
228 ror r1 /* restore carry */