diff options
-rw-r--r-- | onion_base32.c | 28 | ||||
-rw-r--r-- | onion_base32.h | 1 |
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 (*)); |