aboutsummaryrefslogtreecommitdiff
path: root/smc.c
blob: e3e90cf1ef4b1e7a39d52bdc1811e4915b628639 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* 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
smc_hextodec (char *s)                      /* int */
{
	unsigned int i, tmp;
	GEN ret = gen_0;                        /* int */
	GEN v = gtovecsmall (strtoGENstr (s));  /* vecsmall */

	for (i = 1; i < lg (v); ++i)
	{
		///TODO: scanf instead of if
		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
			pari_err (e_MISC, "invalid input format");
		ret = addis (shifti (ret, 4), tmp);
	}
	return ret;
}