diff --git a/CryptX.xs b/CryptX.xs index 53bfff7..5d76d98 100644 --- a/CryptX.xs +++ b/CryptX.xs @@ -175,25 +175,6 @@ } return MP_OKAY; -} - -int _base16_encode(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen) -{ - unsigned long i; - const char alphabet[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; - - if (*outlen < inlen * 2) { - *outlen = inlen * 2; - return CRYPT_BUFFER_OVERFLOW; - } - - for (i = 0; i < inlen; i++) { - out[i*2] = (unsigned char)alphabet[in[i] >> 4]; - out[i*2+1] = (unsigned char)alphabet[in[i] & 0xF]; - } - - *outlen = inlen * 2; - return CRYPT_OK; } size_t _find_start(const char *name, char *ltcname, size_t ltclen) @@ -268,17 +249,17 @@ if ((err = ltc_mp.init(&tmp)) != CRYPT_OK) return; for (cu = ltc_ecc_curves; cu->prime != NULL; cu++) { if ((err = mp_read_radix(tmp, cu->prime, 16)) != CRYPT_OK) continue; - if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; + if ((mp_cmp(tmp, key->dp.prime) != LTC_MP_EQ)) continue; if ((err = mp_read_radix(tmp, cu->order, 16)) != CRYPT_OK) continue; - if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; + if ((mp_cmp(tmp, key->dp.order) != LTC_MP_EQ)) continue; if ((err = mp_read_radix(tmp, cu->A, 16)) != CRYPT_OK) continue; - if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; + if ((mp_cmp(tmp, key->dp.A) != LTC_MP_EQ)) continue; if ((err = mp_read_radix(tmp, cu->B, 16)) != CRYPT_OK) continue; - if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; + if ((mp_cmp(tmp, key->dp.B) != LTC_MP_EQ)) continue; if ((err = mp_read_radix(tmp, cu->Gx, 16)) != CRYPT_OK) continue; - if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; + if ((mp_cmp(tmp, key->dp.base.x) != LTC_MP_EQ)) continue; if ((err = mp_read_radix(tmp, cu->Gy, 16)) != CRYPT_OK) continue; - if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; + if ((mp_cmp(tmp, key->dp.base.y) != LTC_MP_EQ)) continue; if (key->dp.cofactor != cu->cofactor) continue; break; /* found */ } @@ -532,7 +513,7 @@ SvREFCNT_dec(RETVAL); XSRETURN_UNDEF; } - SvCUR_set(RETVAL, strlen(out_data)); + SvCUR_set(RETVAL, out_len); } } OUTPUT: @@ -607,7 +588,7 @@ SvREFCNT_dec(RETVAL); XSRETURN_UNDEF; } - SvCUR_set(RETVAL, strlen(out_data)); + SvCUR_set(RETVAL, out_len); } } OUTPUT: diff --git a/_generators/Mac.xs.inc.tt b/_generators/Mac.xs.inc.tt index de2737a..781cf2f 100644 --- a/_generators/Mac.xs.inc.tt +++ b/_generators/Mac.xs.inc.tt @@ -111,7 +111,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; [%-IF lc_name == 'pelican' %] maclen = 16; @@ -138,7 +138,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -258,7 +258,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Checksum_Adler32.xs.inc b/inc/CryptX_Checksum_Adler32.xs.inc index eb30b81..6b2292a 100644 --- a/inc/CryptX_Checksum_Adler32.xs.inc +++ b/inc/CryptX_Checksum_Adler32.xs.inc @@ -59,13 +59,13 @@ CODE: { int rv; - unsigned char hash[4], out[8]; - unsigned long outlen = 8; + unsigned char hash[4], out[9]; + unsigned long outlen = 9; unsigned int ui32; adler32_finish(self, hash, 4); /* returns void */ if (ix == 1) { - rv = _base16_encode(hash, 4, out, &outlen); + rv = base16_encode(hash, 4, out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *)out, outlen); } @@ -89,8 +89,8 @@ { adler32_state st; int rv, j; - unsigned char hash[4], out[8], *in; - unsigned long outlen = 8; + unsigned char hash[4], out[9], *in; + unsigned long outlen = 9; unsigned int ui32; STRLEN inlen; @@ -103,7 +103,7 @@ } adler32_finish(&st, hash, 4); /* returns void */ if (ix == 1) { - rv = _base16_encode(hash, 4, out, &outlen); + rv = base16_encode(hash, 4, out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *)out, outlen); } diff --git a/inc/CryptX_Checksum_CRC32.xs.inc b/inc/CryptX_Checksum_CRC32.xs.inc index 3c86e7c..700db43 100644 --- a/inc/CryptX_Checksum_CRC32.xs.inc +++ b/inc/CryptX_Checksum_CRC32.xs.inc @@ -59,13 +59,13 @@ CODE: { int rv; - unsigned char hash[4], out[8]; - unsigned long outlen = 8; + unsigned char hash[4], out[9]; + unsigned long outlen = 9; unsigned int ui32; crc32_finish(self, hash, 4); /* returns void */ if (ix == 1) { - rv = _base16_encode(hash, 4, out, &outlen); + rv = base16_encode(hash, 4, out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *)out, outlen); } @@ -89,8 +89,8 @@ { crc32_state st; int rv, j; - unsigned char hash[4], out[8], *in; - unsigned long outlen = 8; + unsigned char hash[4], out[9], *in; + unsigned long outlen = 9; unsigned int ui32; STRLEN inlen; @@ -103,7 +103,7 @@ } crc32_finish(&st, hash, 4); /* returns void */ if (ix == 1) { - rv = _base16_encode(hash, 4, out, &outlen); + rv = base16_encode(hash, 4, out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *)out, outlen); } diff --git a/inc/CryptX_Digest.xs.inc b/inc/CryptX_Digest.xs.inc index 8a97c1a..bbf337a 100644 --- a/inc/CryptX_Digest.xs.inc +++ b/inc/CryptX_Digest.xs.inc @@ -79,7 +79,7 @@ int rv; unsigned long outlen; unsigned char hash[MAXBLOCKSIZE]; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; rv = self->desc->done(&self->state, hash); if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv)); @@ -96,7 +96,7 @@ RETVAL = newSVpvn(out, outlen); } else if (ix == 1) { - rv = _base16_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen); + rv = base16_encode(hash, self->desc->hashsize, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -119,7 +119,7 @@ int rv, id, i; unsigned char *in, hash[MAXBLOCKSIZE]; unsigned long len = sizeof(hash), outlen; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; hash_state md; id = _find_hash(digest_name); @@ -151,7 +151,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(hash, len, (unsigned char *)out, &outlen); + rv = base16_encode(hash, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_BLAKE2b.xs.inc b/inc/CryptX_Mac_BLAKE2b.xs.inc index 6d27e3e..8c00ed4 100644 --- a/inc/CryptX_Mac_BLAKE2b.xs.inc +++ b/inc/CryptX_Mac_BLAKE2b.xs.inc @@ -70,7 +70,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = blake2bmac_done(self, mac, &maclen); @@ -87,7 +87,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -140,7 +140,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_BLAKE2s.xs.inc b/inc/CryptX_Mac_BLAKE2s.xs.inc index 3ac3467..f9fd0a1 100644 --- a/inc/CryptX_Mac_BLAKE2s.xs.inc +++ b/inc/CryptX_Mac_BLAKE2s.xs.inc @@ -70,7 +70,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = blake2smac_done(self, mac, &maclen); @@ -87,7 +87,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -140,7 +140,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_F9.xs.inc b/inc/CryptX_Mac_F9.xs.inc index e1782c6..b21099e 100644 --- a/inc/CryptX_Mac_F9.xs.inc +++ b/inc/CryptX_Mac_F9.xs.inc @@ -74,7 +74,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = f9_done(self, mac, &maclen); @@ -91,7 +91,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -145,7 +145,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_HMAC.xs.inc b/inc/CryptX_Mac_HMAC.xs.inc index 8e4f73c..da87bc1 100644 --- a/inc/CryptX_Mac_HMAC.xs.inc +++ b/inc/CryptX_Mac_HMAC.xs.inc @@ -74,7 +74,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = hmac_done(self, mac, &maclen); @@ -91,7 +91,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -145,7 +145,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_OMAC.xs.inc b/inc/CryptX_Mac_OMAC.xs.inc index aa8699a..0510825 100644 --- a/inc/CryptX_Mac_OMAC.xs.inc +++ b/inc/CryptX_Mac_OMAC.xs.inc @@ -74,7 +74,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = omac_done(self, mac, &maclen); @@ -91,7 +91,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -145,7 +145,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_PMAC.xs.inc b/inc/CryptX_Mac_PMAC.xs.inc index 9ee709d..f8eb832 100644 --- a/inc/CryptX_Mac_PMAC.xs.inc +++ b/inc/CryptX_Mac_PMAC.xs.inc @@ -74,7 +74,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = pmac_done(self, mac, &maclen); @@ -91,7 +91,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -145,7 +145,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_Pelican.xs.inc b/inc/CryptX_Mac_Pelican.xs.inc index 3484019..ea2e22a 100644 --- a/inc/CryptX_Mac_Pelican.xs.inc +++ b/inc/CryptX_Mac_Pelican.xs.inc @@ -70,7 +70,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = 16; rv = pelican_done(self, mac); @@ -87,7 +87,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -140,7 +140,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_Poly1305.xs.inc b/inc/CryptX_Mac_Poly1305.xs.inc index 6e50821..c42d3a9 100644 --- a/inc/CryptX_Mac_Poly1305.xs.inc +++ b/inc/CryptX_Mac_Poly1305.xs.inc @@ -70,7 +70,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = poly1305_done(self, mac, &maclen); @@ -87,7 +87,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -139,7 +139,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_Mac_XCBC.xs.inc b/inc/CryptX_Mac_XCBC.xs.inc index 6563b67..809f583 100644 --- a/inc/CryptX_Mac_XCBC.xs.inc +++ b/inc/CryptX_Mac_XCBC.xs.inc @@ -74,7 +74,7 @@ unsigned char mac[MAXBLOCKSIZE]; unsigned long maclen, outlen; int rv; - char out[MAXBLOCKSIZE*2]; + char out[MAXBLOCKSIZE*2+1]; maclen = sizeof(mac); rv = xcbc_done(self, mac, &maclen); @@ -91,7 +91,7 @@ RETVAL = newSVpvn(out, outlen); } if (ix == 1) { - rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen); + rv = base16_encode(mac, maclen, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn(out, outlen); } @@ -145,7 +145,7 @@ RETVAL = newSVpvn((char *) out, outlen); } else if (ix == 1) { - rv = _base16_encode(mac, len, (unsigned char *)out, &outlen); + rv = base16_encode(mac, len, (unsigned char *)out, &outlen, 0); if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); RETVAL = newSVpvn((char *) out, outlen); } diff --git a/inc/CryptX_PRNG.xs.inc b/inc/CryptX_PRNG.xs.inc index 9345311..ddc19fa 100644 --- a/inc/CryptX_PRNG.xs.inc +++ b/inc/CryptX_PRNG.xs.inc @@ -124,12 +124,13 @@ if (tmp == NULL) croak("FATAL: Newz failed"); rv_len = (self->desc->read)(tmp, (unsigned long)output_len, &self->state); if ((UV)rv_len != output_len) croak("FATAL: PRNG_read failed"); - RETVAL = NEWSV(0, output_len * 2); /* avoid zero! */ + RETVAL = NEWSV(0, output_len * 2 + 1); /* avoid zero! */ SvPOK_only(RETVAL); - SvCUR_set(RETVAL, output_len * 2); + SvCUR_set(RETVAL, output_len * 2 + 1); rdata = (unsigned char *)SvPVX(RETVAL); - len = output_len * 2; - rv = _base16_encode(tmp, output_len, rdata, &len); + len = output_len * 2 + 1; + rv = base16_encode(tmp, output_len, rdata, &len, 0); + SvCUR_set(RETVAL, len); Safefree(tmp); if (rv != CRYPT_OK) { SvREFCNT_dec(RETVAL); diff --git a/src/ltc/misc/base16/base16_encode.c b/src/ltc/misc/base16/base16_encode.c index d400d76..428002a 100644 --- a/src/ltc/misc/base16/base16_encode.c +++ b/src/ltc/misc/base16/base16_encode.c @@ -49,12 +49,12 @@ *outlen = x; return CRYPT_BUFFER_OVERFLOW; } - *outlen = x; + x--; + *outlen = x; /* returning the length without terminating NUL */ if (caps == 0) alphabet = alphabets[0]; else alphabet = alphabets[1]; - x -= 1; for (i = 0; i < x; i += 2) { out[i] = alphabet[(in[i/2] >> 4) & 0x0f]; out[i+1] = alphabet[in[i/2] & 0x0f]; diff --git a/src/ltc/misc/base32/base32_encode.c b/src/ltc/misc/base32/base32_encode.c index 13c7ce0..81fa97a 100644 --- a/src/ltc/misc/base32/base32_encode.c +++ b/src/ltc/misc/base32/base32_encode.c @@ -45,7 +45,7 @@ *outlen = x; return CRYPT_BUFFER_OVERFLOW; } - *outlen = x; + *outlen = x - 1; /* returning the length without terminating NUL */ /* no input, nothing to do */ if (inlen == 0) { diff --git a/src/ltc/misc/base64/base64_encode.c b/src/ltc/misc/base64/base64_encode.c index 985ba8d..788c9d5 100644 --- a/src/ltc/misc/base64/base64_encode.c +++ b/src/ltc/misc/base64/base64_encode.c @@ -73,7 +73,7 @@ *p = '\0'; /* return ok */ - *outlen = (unsigned long)(p - out); + *outlen = (unsigned long)(p - out); /* the length without terminating NUL */ return CRYPT_OK; }