1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

base32: Add base32_encode_unsafe

This commit is contained in:
Saleem Rashid 2017-05-25 20:21:53 +01:00 committed by Pavol Rusnak
parent afdcb37f82
commit 6b7553e2f2
2 changed files with 15 additions and 0 deletions

View File

@ -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);

View File

@ -23,6 +23,9 @@
#ifndef __BASE32_H__
#define __BASE32_H__
#include <stddef.h>
#include <stdint.h>
void base32_encode_unsafe(const uint8_t *in, size_t inlen, uint8_t *out);
#endif