From 6b7553e2f2e07f6c05f096458c87dbb85925ef01 Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Thu, 25 May 2017 20:21:53 +0100 Subject: [PATCH] base32: Add base32_encode_unsafe --- base32.c | 12 ++++++++++++ base32.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/base32.c b/base32.c index 7f834983d2..0f9f90f3c7 100644 --- a/base32.c +++ b/base32.c @@ -24,6 +24,18 @@ static inline void base32_5to8(const uint8_t *in, uint8_t length, uint8_t *out); +void base32_encode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out) { + uint8_t remainder = inlen % 5; + size_t limit = inlen - remainder; + + size_t i, j; + for (i = 0, j = 0; i < limit; i += 5, j += 8) { + base32_5to8(&in[i], 5, &out[j]); + } + + if (remainder) base32_5to8(&in[i], remainder, &out[j]); +} + void base32_5to8(const uint8_t *in, uint8_t length, uint8_t *out) { if (length >= 1) { out[0] = (in[0] >> 3); diff --git a/base32.h b/base32.h index 48c340c234..e0b49375cf 100644 --- a/base32.h +++ b/base32.h @@ -23,6 +23,9 @@ #ifndef __BASE32_H__ #define __BASE32_H__ +#include #include +void base32_encode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out); + #endif