summaryrefslogtreecommitdiff
path: root/nacl/curvecp/hexparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/curvecp/hexparse.c')
-rw-r--r--nacl/curvecp/hexparse.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/nacl/curvecp/hexparse.c b/nacl/curvecp/hexparse.c
new file mode 100644
index 00000000..43bfe044
--- /dev/null
+++ b/nacl/curvecp/hexparse.c
@@ -0,0 +1,25 @@
1#include "hexparse.h"
2
3static int hexdigit(char x)
4{
5 if (x >= '0' && x <= '9') return x - '0';
6 if (x >= 'a' && x <= 'f') return 10 + (x - 'a');
7 if (x >= 'A' && x <= 'F') return 10 + (x - 'A');
8 return -1;
9}
10
11int hexparse(unsigned char *y,long long len,const char *x)
12{
13 if (!x) return 0;
14 while (len > 0) {
15 int digit0;
16 int digit1;
17 digit0 = hexdigit(x[0]); if (digit0 == -1) return 0;
18 digit1 = hexdigit(x[1]); if (digit1 == -1) return 0;
19 *y++ = digit1 + 16 * digit0;
20 --len;
21 x += 2;
22 }
23 if (x[0]) return 0;
24 return 1;
25}