diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
commit | e2967396ac73cb7410787886cdaf072a184ffc49 (patch) | |
tree | 527a74d25a4a0705fc641994fd35bfab22662034 /nacl/curvecp/hexparse.c | |
parent | 8928c817df345f29aa0b194743595aa11bd6a8ba (diff) |
Added NaCl crypto library.
Diffstat (limited to 'nacl/curvecp/hexparse.c')
-rw-r--r-- | nacl/curvecp/hexparse.c | 25 |
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 | |||
3 | static 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 | |||
11 | int 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 | } | ||