3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 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/>.
21 #include "hexdigit_tab.h"
26 void bigint_print_hex(const bigint_t* a){
31 if(a->info&BIGINT_NEG_MASK){
34 // cli_putc((a->info&BIGINT_NEG_MASK)?'-':'+'); /* print sign */
35 /* if(a->wordv[a->length_W-1]<0x10){
36 cli_putc(hexdigit_tab_uc[a->wordv[a->length_W-1]]);
37 cli_hexdump_rev(a->wordv, a->length_W-1);
40 // cli_hexdump_rev(a->wordv, a->length_W*sizeof(bigint_word_t));
45 p = (uint8_t*)&(a->wordv[a->length_W-1])+sizeof(bigint_word_t)-1;
46 for(idx = a->length_W * sizeof(bigint_word_t); idx > 0; --idx){
49 if(x!=0 || print_zero!=0){
50 cli_putc(hexdigit_tab_lc[x]);
55 if(y!=0 || print_zero!=0){
56 cli_putc(hexdigit_tab_lc[y]);
67 static uint8_t char2nibble(char c){
68 if(c>='0' && c <='9'){
71 c |= 'A'^'a'; /* to lower case */
72 if(c>='a' && c <='f'){
78 static uint16_t read_byte(void){
97 uint8_t bigint_read_hex_echo(bigint_t* a){
105 if(allocated - idx < 1){
107 p = realloc(a->wordv, allocated += BLOCKSIZE);
109 cli_putstr("\r\nERROR: Out of memory!");
113 memset((uint8_t*)p + allocated - BLOCKSIZE, 0, BLOCKSIZE);
120 a->info |= BIGINT_NEG_MASK;
131 ((uint8_t*)(a->wordv))[idx++] = (uint8_t)t;
135 ((uint8_t*)(a->wordv))[idx++] = (uint8_t)((t&0x0f)<<4);
140 /* we have to reverse the byte array */
143 a->length_W = (idx + sizeof(bigint_word_t)-1)/sizeof(bigint_word_t);
144 p = (uint8_t*)(a->wordv);
145 q = (uint8_t*)a->wordv + idx - 1;
154 bigint_shiftright(a, 4);