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) {
27 if (a->length_W == 0) {
31 if (a->info&BIGINT_NEG_MASK) {
35 uint8_t print_zero = 0;
37 p = (uint8_t*)&(a->wordv[a->length_W - 1]) + sizeof(bigint_word_t) - 1;
38 for (idx = a->length_W * sizeof(bigint_word_t); idx > 0; --idx) {
41 if (x != 0 || print_zero != 0) {
42 cli_putc(pgm_read_byte(&hexdigit_tab_lc_P[x]));
47 if (y != 0 || print_zero != 0) {
48 cli_putc(pgm_read_byte(&hexdigit_tab_lc_P[y]));
59 static uint8_t char2nibble(char c) {
60 if (c >= '0' && c <= '9') {
63 c |= 'A' ^ 'a'; /* to lower case */
64 if ( c>= 'a' && c <= 'f') {
70 static uint16_t read_byte(void) {
89 uint8_t bigint_read_hex_echo(bigint_t *a) {
90 uint16_t allocated = 0;
97 if (allocated - idx < 1) {
99 p = realloc(a->wordv, allocated += BLOCKSIZE);
101 cli_putstr("\r\nERROR: Out of memory!");
105 memset((uint8_t*)p + allocated - BLOCKSIZE, 0, BLOCKSIZE);
112 a->info |= BIGINT_NEG_MASK;
123 ((uint8_t*)(a->wordv))[idx++] = (uint8_t)t;
127 ((uint8_t*)(a->wordv))[idx++] = (uint8_t)((t & 0x0f) << 4);
132 /* we have to reverse the byte array */
135 a->length_W = (idx + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
136 p = (uint8_t*)(a->wordv);
137 q = (uint8_t*)a->wordv + a->length_W * sizeof(bigint_word_t) - 1;
146 bigint_shiftright(a, 4);
148 if(a->length_W == 1 && a->wordv[0] == 0){