From e2967396ac73cb7410787886cdaf072a184ffc49 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 2 Jul 2013 09:53:34 -0400 Subject: Added NaCl crypto library. --- nacl/curvecp/hexparse.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 nacl/curvecp/hexparse.c (limited to 'nacl/curvecp/hexparse.c') 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 @@ +#include "hexparse.h" + +static int hexdigit(char x) +{ + if (x >= '0' && x <= '9') return x - '0'; + if (x >= 'a' && x <= 'f') return 10 + (x - 'a'); + if (x >= 'A' && x <= 'F') return 10 + (x - 'A'); + return -1; +} + +int hexparse(unsigned char *y,long long len,const char *x) +{ + if (!x) return 0; + while (len > 0) { + int digit0; + int digit1; + digit0 = hexdigit(x[0]); if (digit0 == -1) return 0; + digit1 = hexdigit(x[1]); if (digit1 == -1) return 0; + *y++ = digit1 + 16 * digit0; + --len; + x += 2; + } + if (x[0]) return 0; + return 1; +} -- cgit v1.2.3