Remove USE_OPENSSL_BASE64 and the associated code.

The alternative has been available since 2007, there's no way to
actually enable the ifdef, and it breaks on well formed but not OpenSSL
style inputs.
This commit is contained in:
Yawning Angel 2015-04-10 09:12:47 +00:00
parent f9327848ba
commit ba2485f7df
2 changed files with 5 additions and 47 deletions

5
changes/feature15652 Normal file
View File

@ -0,0 +1,5 @@
o Removed code:
- Remove `USE_OPENSSL_BASE64` and the corresponding fallback code and
always use the internal Base64 decoder. The internal decoder has been
part of tor since tor-0.2.0.10-alpha, and no one should be using the
OpenSSL one. Part of ticket 15652.

View File

@ -2500,26 +2500,6 @@ static const uint8_t base64_decode_table[256] = {
int int
base64_decode(char *dest, size_t destlen, const char *src, size_t srclen) base64_decode(char *dest, size_t destlen, const char *src, size_t srclen)
{ {
#ifdef USE_OPENSSL_BASE64
EVP_ENCODE_CTX ctx;
int len, ret;
/* 64 bytes of input -> *up to* 48 bytes of output.
Plus one more byte, in case I'm wrong.
*/
if (destlen < ((srclen/64)+1)*49)
return -1;
if (destlen > SIZE_T_CEILING)
return -1;
memset(dest, 0, destlen);
EVP_DecodeInit(&ctx);
EVP_DecodeUpdate(&ctx, (unsigned char*)dest, &len,
(unsigned char*)src, srclen);
EVP_DecodeFinal(&ctx, (unsigned char*)dest, &ret);
ret += len;
return ret;
#else
const char *eos = src+srclen; const char *eos = src+srclen;
uint32_t n=0; uint32_t n=0;
int n_idx=0; int n_idx=0;
@ -2590,7 +2570,6 @@ base64_decode(char *dest, size_t destlen, const char *src, size_t srclen)
tor_assert((dest-dest_orig) <= INT_MAX); tor_assert((dest-dest_orig) <= INT_MAX);
return (int)(dest-dest_orig); return (int)(dest-dest_orig);
#endif
} }
#undef X #undef X
#undef SP #undef SP
@ -2615,23 +2594,10 @@ digest_to_base64(char *d64, const char *digest)
int int
digest_from_base64(char *digest, const char *d64) digest_from_base64(char *digest, const char *d64)
{ {
#ifdef USE_OPENSSL_BASE64
char buf_in[BASE64_DIGEST_LEN+3];
char buf[256];
if (strlen(d64) != BASE64_DIGEST_LEN)
return -1;
memcpy(buf_in, d64, BASE64_DIGEST_LEN);
memcpy(buf_in+BASE64_DIGEST_LEN, "=\n\0", 3);
if (base64_decode(buf, sizeof(buf), buf_in, strlen(buf_in)) != DIGEST_LEN)
return -1;
memcpy(digest, buf, DIGEST_LEN);
return 0;
#else
if (base64_decode(digest, DIGEST_LEN, d64, strlen(d64)) == DIGEST_LEN) if (base64_decode(digest, DIGEST_LEN, d64, strlen(d64)) == DIGEST_LEN)
return 0; return 0;
else else
return -1; return -1;
#endif
} }
/** Base64 encode DIGEST256_LINE bytes from <b>digest</b>, remove the /** Base64 encode DIGEST256_LINE bytes from <b>digest</b>, remove the
@ -2653,23 +2619,10 @@ digest256_to_base64(char *d64, const char *digest)
int int
digest256_from_base64(char *digest, const char *d64) digest256_from_base64(char *digest, const char *d64)
{ {
#ifdef USE_OPENSSL_BASE64
char buf_in[BASE64_DIGEST256_LEN+3];
char buf[256];
if (strlen(d64) != BASE64_DIGEST256_LEN)
return -1;
memcpy(buf_in, d64, BASE64_DIGEST256_LEN);
memcpy(buf_in+BASE64_DIGEST256_LEN, "=\n\0", 3);
if (base64_decode(buf, sizeof(buf), buf_in, strlen(buf_in)) != DIGEST256_LEN)
return -1;
memcpy(digest, buf, DIGEST256_LEN);
return 0;
#else
if (base64_decode(digest, DIGEST256_LEN, d64, strlen(d64)) == DIGEST256_LEN) if (base64_decode(digest, DIGEST256_LEN, d64, strlen(d64)) == DIGEST256_LEN)
return 0; return 0;
else else
return -1; return -1;
#endif
} }
/** Implements base32 encoding as in RFC 4648. Limitation: Requires /** Implements base32 encoding as in RFC 4648. Limitation: Requires