@@ -39,9 +39,9 @@ typedef enum {
BASE32_CROCKFORD = 3
} base32_alphabet;
int base32_encode(const unsigned char *in, unsigned long inlen,
- unsigned char *out, unsigned long *outlen,
+ char *out, unsigned long *outlen,
base32_alphabet id);
-int base32_decode(const unsigned char *in, unsigned long inlen,
+int base32_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen,
#endif
@@ -20,14 +20,14 @@
@param id Alphabet to use BASE32_RFC4648, BASE32_BASE32HEX, BASE32_ZBASE32 or BASE32_CROCKFORD
@return CRYPT_OK if successful
*/
base32_alphabet id)
{
unsigned long x;
int y = 0;
ulong64 t = 0;
- unsigned char c;
+ char c;
const unsigned char *map;
const unsigned char tables[4][43] = {
{ /* id = BASE32_RFC4648 : ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 */
@@ -90,11 +90,10 @@ int base32_decode(const unsigned char *in, unsigned long inlen,
c = in[x];
/* convert to upper case */
if ((c >= 'a') && (c <= 'z')) c -= 32;
- /* '0' = 48 .. 'Z' = 90 */
- if (c < 48 || c > 90 || map[c-48] > 31) {
+ if (c < '0' || c > 'Z' || map[c-'0'] > 31) {
return CRYPT_INVALID_PACKET;
}
- t = (t<<5)|map[c-48];
+ t = (t<<5) | map[c-'0'];
if (++y == 8) {
*out++ = (unsigned char)((t>>32) & 255);
*out++ = (unsigned char)((t>>24) & 255);
@@ -21,11 +21,11 @@
unsigned long i, x;
- unsigned char *codes;
+ const char *codes;
const char *alphabet[4] = {
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", /* id = BASE32_RFC4648 */
"0123456789ABCDEFGHIJKLMNOPQRSTUV", /* id = BASE32_BASE32HEX */
@@ -53,7 +53,7 @@ int base32_encode(const unsigned char *in, unsigned long inlen,
*outlen = x;
- codes = (unsigned char*)alphabet[id];
+ codes = alphabet[id];
x = 5 * (inlen / 5);
for (i = 0; i < x; i += 5) {
*out++ = codes[(in[0] >> 3) & 0x1F];
@@ -13,7 +13,8 @@
int base32_test(void)
- unsigned char in[100], out[160], tmp[100];
+ unsigned char in[100], tmp[100];
+ char out[160];
unsigned char testin[] = { 0x61,0xc2,0xcb,0xbc,0x5e,0x6d,0x2a,0x7a,0x1a,0x19,0x1a,0xae,0xc9,0x02,0xd4,0xbf,0x7d };
const int testid[4] = {
BASE32_RFC4648,