3 This file is part of the AVR-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"
23 #include <avr/pgmspace.h>
27 void bigint_print_hex(const bigint_t* a){
32 if(a->info&BIGINT_NEG_MASK){
35 // cli_putc((a->info&BIGINT_NEG_MASK)?'-':'+'); /* print sign */
36 if(a->wordv[a->length_B-1]<0x10){
37 cli_putc(pgm_read_byte(hexdigit_tab_uc_P+a->wordv[a->length_B-1]));
38 cli_hexdump_rev(a->wordv, a->length_B-1);
40 cli_hexdump_rev(a->wordv, a->length_B);
46 static uint8_t char2nibble(char c){
47 if(c>='0' && c <='9'){
50 c |= 'A'^'a'; /* to lower case */
51 if(c>='a' && c <='f'){
57 static uint16_t read_byte(void){
76 uint8_t bigint_read_hex_echo(bigint_t* a){
84 if(allocated-a->length_B < 1){
86 p = realloc(a->wordv, allocated+=BLOCKSIZE);
88 cli_putstr_P(PSTR("\r\nERROR: Out of memory!"));
98 a->info |= BIGINT_NEG_MASK;
109 a->wordv[a->length_B++] = (uint8_t)t;
113 a->wordv[a->length_B++] = (uint8_t)((t&0x0f)<<4);
118 /* we have to reverse the byte array */
122 q = a->wordv+a->length_B-1;
131 bigint_shiftright(a, 4);