aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-05-28 13:59:01 +1200
committerDavid Phillips <david@sighup.nz>2017-05-28 13:59:01 +1200
commitcc9a95e708ac558dc5c7aebd121d82fd9a59ebcd (patch)
treed6169a8939980ac2eb168e16dbead8adf01b7a24
parentea3bd627021614efb6c6c3529656cbed376c637e (diff)
downloadsand-leek-cc9a95e708ac558dc5c7aebd121d82fd9a59ebcd.tar.xz
Add naive base32 decoder in preparation for new algo
-rw-r--r--onion_base32.c28
-rw-r--r--onion_base32.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/onion_base32.c b/onion_base32.c
index 78753ab..6f1713d 100644
--- a/onion_base32.c
+++ b/onion_base32.c
@@ -35,6 +35,34 @@ onion_base32(char output[16], unsigned char sum[20]) {
}
}
+unsigned char
+base32_dec_single(char b) {
+ int ret = 0;
+
+ if (b < 'a')
+ ret = b - '2' + 26;
+ else
+ ret = b - 'a';
+
+ printf("%d «%d»\n", ret, b);
+ return ret;
+}
+
+void
+onion_base32_dec(unsigned char dec[10], char base32[16])
+{
+ size_t c = 0;
+ size_t i = 0;
+
+ for (i = 0; i < 16; i += 8) {
+ dec[c++] = base32_dec_single(base32[i]) << 3 | base32_dec_single(base32[i+1]) >> 2;
+ dec[c++] = base32_dec_single(base32[i+1]) << 6 | base32_dec_single(base32[i+2]) << 1 | base32_dec_single(base32[i+3]) >> 4;
+ dec[c++] = base32_dec_single(base32[i+3]) << 4 | base32_dec_single(base32[i+4]) >> 1;
+ dec[c++] = base32_dec_single(base32[i+4]) << 7 | base32_dec_single(base32[i+5]) << 2 | base32_dec_single(base32[i+6]) >> 3;
+ dec[c++] = base32_dec_single(base32[i+7]) | base32_dec_single(base32[i+6]) << 5;
+ }
+
+}
#ifdef __SSSE3__
#include <tmmintrin.h>
diff --git a/onion_base32.h b/onion_base32.h
index c196dea..23e7bd2 100644
--- a/onion_base32.h
+++ b/onion_base32.h
@@ -1,5 +1,6 @@
int check_base32(char *);
void onion_base32(char [16], unsigned char (*));
+void onion_base32_dec(unsigned char [10], char[16]);
#ifdef __SSSE3__
void onion_base32_ssse3(char [16], unsigned char (*));