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;
98 if (allocated - idx < 1) {
100 p = realloc(buf, (allocated += BLOCKSIZE) * sizeof(bigint_word_t));
102 cli_putstr("\r\nERROR: Out of memory!");
106 memset((uint8_t*)p + (allocated - BLOCKSIZE) * sizeof(bigint_word_t), 0, BLOCKSIZE * sizeof(bigint_word_t));
113 a->info |= BIGINT_NEG_MASK;
124 buf[idx++] = (uint8_t)t;
128 buf[idx++] = (uint8_t)((t & 0x0f) << 4);
133 /* we have to reverse the byte array */
136 a->length_W = (idx + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
145 a->wordv = (bigint_word_t*)buf;
148 bigint_shiftright(a, 4);
150 if(a->length_W == 1 && a->wordv[0] == 0){