2016-06-01 01:08:43 +02:00
|
|
|
/* This file is part of libbrandt.
|
|
|
|
* Copyright (C) 2016 GNUnet e.V.
|
|
|
|
*
|
|
|
|
* libbrandt is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file smc.c
|
|
|
|
* @brief Implementation of the smc primitives.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pari/pari.h>
|
|
|
|
|
|
|
|
GEN
|
2016-06-01 01:40:29 +02:00
|
|
|
smc_hextodec (char *s) /* int */
|
2016-06-01 01:08:43 +02:00
|
|
|
{
|
2016-06-02 13:26:37 +02:00
|
|
|
unsigned int i, tmp;
|
2016-06-01 01:08:43 +02:00
|
|
|
GEN ret = gen_0; /* int */
|
2016-06-01 01:40:29 +02:00
|
|
|
GEN v = gtovecsmall (strtoGENstr (s)); /* vecsmall */
|
2016-06-01 01:08:43 +02:00
|
|
|
|
2016-06-01 01:40:29 +02:00
|
|
|
for (i = 1; i < lg (v); ++i)
|
2016-06-01 01:08:43 +02:00
|
|
|
{
|
2016-06-02 13:26:37 +02:00
|
|
|
///TODO: scanf instead of if
|
2016-06-01 01:08:43 +02:00
|
|
|
if ((v[i] >= '0') && (v[i] <= '9'))
|
|
|
|
tmp = v[i] - '0';
|
|
|
|
else if ((v[i] >= 'a') && (v[i] <= 'f'))
|
|
|
|
tmp = v[i] + 10 - 'a';
|
|
|
|
else if ((v[i] >= 'A') && (v[i] <= 'F'))
|
|
|
|
tmp = v[i] + 10 - 'A';
|
|
|
|
else
|
2016-06-01 01:40:29 +02:00
|
|
|
pari_err (e_MISC, "invalid input format");
|
|
|
|
ret = addis (shifti (ret, 4), tmp);
|
2016-06-01 01:08:43 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|