diff options
author | David Phillips <david@sighup.nz> | 2017-05-28 13:59:01 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2017-05-28 13:59:01 +1200 |
commit | cc9a95e708ac558dc5c7aebd121d82fd9a59ebcd (patch) | |
tree | d6169a8939980ac2eb168e16dbead8adf01b7a24 /onion_base32.c | |
parent | ea3bd627021614efb6c6c3529656cbed376c637e (diff) | |
download | sand-leek-cc9a95e708ac558dc5c7aebd121d82fd9a59ebcd.tar.xz |
Add naive base32 decoder in preparation for new algo
Diffstat (limited to 'onion_base32.c')
-rw-r--r-- | onion_base32.c | 28 |
1 files changed, 28 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> |