Remove CHARSET_EBCDIC

Since crypto/ebcdic.{c,h} are not present in BoringSSL, remove the #ifdefs
Changes were made by running

find . -type f -name *.c | xargs unifdef -m -U CHARSET_EBCDIC
find . -type f -name *.h | xargs unifdef -m -U CHARSET_EBCDIC

using unifdef 2.10.

An additional two ifdefs (CHARSET_EBCDIC_not) were removed manually.

Change-Id: Ie174bb00782cc44c63b0f9fab69619b3a9f66d42
Reviewed-on: https://boringssl-review.googlesource.com/1093
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/asn1/a_gentm.c b/crypto/asn1/a_gentm.c
index 1b8d78e..b5bddb8 100644
--- a/crypto/asn1/a_gentm.c
+++ b/crypto/asn1/a_gentm.c
@@ -248,8 +248,5 @@
 		     ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
 	s->length=strlen(p);
 	s->type=V_ASN1_GENERALIZEDTIME;
-#ifdef CHARSET_EBCDIC_not
-	ebcdic2ascii(s->data, s->data, s->length);
-#endif
 	return(s);
 	}
diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c
index 6543f52..007f0e1 100644
--- a/crypto/asn1/a_mbstr.c
+++ b/crypto/asn1/a_mbstr.c
@@ -380,16 +380,9 @@
 	/* Note: we can't use 'isalnum' because certain accented 
 	 * characters may count as alphanumeric in some environments.
 	 */
-#ifndef CHARSET_EBCDIC
 	if((ch >= 'a') && (ch <= 'z')) return 1;
 	if((ch >= 'A') && (ch <= 'Z')) return 1;
 	if((ch >= '0') && (ch <= '9')) return 1;
 	if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1;
-#else /*CHARSET_EBCDIC*/
-	if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1;
-	if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1;
-	if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1;
-	if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1;
-#endif /*CHARSET_EBCDIC*/
 	return 0;
 }
diff --git a/crypto/asn1/a_print.c b/crypto/asn1/a_print.c
index e2cde68..3b6be10 100644
--- a/crypto/asn1/a_print.c
+++ b/crypto/asn1/a_print.c
@@ -72,7 +72,6 @@
 	while ((*s) && (len-- != 0))
 		{
 		c= *(s++);
-#ifndef CHARSET_EBCDIC
 		if (!(	((c >= 'a') && (c <= 'z')) ||
 			((c >= 'A') && (c <= 'Z')) ||
 			(c == ' ') ||
@@ -86,13 +85,6 @@
 			ia5=1;
 		if (c&0x80)
 			t61=1;
-#else
-		if (!isalnum(c) && (c != ' ') &&
-		    strchr("'()+,-./:=?", c) == NULL)
-			ia5=1;
-		if (os_toascii[c] & 0x80)
-			t61=1;
-#endif
 		}
 	if (t61) return(V_ASN1_T61STRING);
 	if (ia5) return(V_ASN1_IA5STRING);
diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
index 3b80ba4..4786024 100644
--- a/crypto/asn1/a_time.c
+++ b/crypto/asn1/a_time.c
@@ -79,21 +79,6 @@
 #if 0
 int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
 	{
-#ifdef CHARSET_EBCDIC
-	/* KLUDGE! We convert to ascii before writing DER */
-	char tmp[24];
-	ASN1_STRING tmpstr;
-
-	if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
-	    int len;
-
-	    tmpstr = *(ASN1_STRING *)a;
-	    len = tmpstr.length;
-	    ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
-	    tmpstr.data = tmp;
-	    a = (ASN1_GENERALIZEDTIME *) &tmpstr;
-	}
-#endif
 	if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
 				return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
 				     a->type ,V_ASN1_UNIVERSAL));
diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c
index 72a09be..41f3594 100644
--- a/crypto/asn1/a_utctm.c
+++ b/crypto/asn1/a_utctm.c
@@ -64,20 +64,8 @@
 #if 0
 int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
 	{
-#ifndef CHARSET_EBCDIC
 	return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
 		V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
-#else
-	/* KLUDGE! We convert to ascii before writing DER */
-	int len;
-	char tmp[24];
-	ASN1_STRING x = *(ASN1_STRING *)a;
-
-	len = x.length;
-	ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len);
-	x.data = tmp;
-	return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
-#endif
 	}
 
 
@@ -93,9 +81,6 @@
 		OPENSSL_PUT_ERROR(ASN1, XXX, ERR_R_NESTED_ASN1_ERROR);
 		return(NULL);
 		}
-#ifdef CHARSET_EBCDIC
-	ascii2ebcdic(ret->data, ret->data, ret->length);
-#endif
 	if (!ASN1_UTCTIME_check(ret))
 		{
 		OPENSSL_PUT_ERROR(ASN1, XXX, ASN1_R_INVALID_TIME_FORMAT);
@@ -276,9 +261,6 @@
 		     ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
 	s->length=strlen(p);
 	s->type=V_ASN1_UTCTIME;
-#ifdef CHARSET_EBCDIC_not
-	ebcdic2ascii(s->data, s->data, s->length);
-#endif
 	return(s);
 	}
 
diff --git a/crypto/asn1/f_int.c b/crypto/asn1/f_int.c
index d9ddcf8..7b8c61a 100644
--- a/crypto/asn1/f_int.c
+++ b/crypto/asn1/f_int.c
@@ -122,18 +122,9 @@
 
 		for (j=0; j<i; j++)
 			{
-#ifndef CHARSET_EBCDIC
 			if (!(	((buf[j] >= '0') && (buf[j] <= '9')) ||
 				((buf[j] >= 'a') && (buf[j] <= 'f')) ||
 				((buf[j] >= 'A') && (buf[j] <= 'F'))))
-#else
-			/* This #ifdef is not strictly necessary, since
-			 * the characters A...F a...f 0...9 are contiguous
-			 * (yes, even in EBCDIC - but not the whole alphabet).
-			 * Nevertheless, isxdigit() is faster.
-			 */
-			if (!isxdigit(buf[j]))
-#endif
 				{
 				i=j;
 				break;
diff --git a/crypto/asn1/f_string.c b/crypto/asn1/f_string.c
index 95e59ff..d6f128d 100644
--- a/crypto/asn1/f_string.c
+++ b/crypto/asn1/f_string.c
@@ -123,18 +123,9 @@
 
 		for (j=i-1; j>0; j--)
 			{
-#ifndef CHARSET_EBCDIC
 			if (!(	((buf[j] >= '0') && (buf[j] <= '9')) ||
 				((buf[j] >= 'a') && (buf[j] <= 'f')) ||
 				((buf[j] >= 'A') && (buf[j] <= 'F'))))
-#else
-			/* This #ifdef is not strictly necessary, since
-			 * the characters A...F a...f 0...9 are contiguous
-			 * (yes, even in EBCDIC - but not the whole alphabet).
-			 * Nevertheless, isxdigit() is faster.
-			 */
-			if (!isxdigit(buf[j]))
-#endif
 				{
 				i=j;
 				break;
diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c
index 23efd0a..24fa877 100644
--- a/crypto/pem/pem_lib.c
+++ b/crypto/pem/pem_lib.c
@@ -337,10 +337,6 @@
 				OPENSSL_PUT_ERROR(PEM, PEM_ASN1_write_bio, PEM_R_READ_KEY);
 				goto err;
 				}
-#ifdef CHARSET_EBCDIC
-			/* Convert the pass phrase from EBCDIC */
-			ebcdic2ascii(buf, buf, klen);
-#endif
 			kstr=(unsigned char *)buf;
 			}
 		assert(iv_len <= (int)sizeof(iv));
@@ -412,10 +408,6 @@
 		OPENSSL_PUT_ERROR(PEM, PEM_do_header, PEM_R_BAD_PASSWORD_READ);
 		return(0);
 		}
-#ifdef CHARSET_EBCDIC
-	/* Convert the pass phrase from EBCDIC */
-	ebcdic2ascii(buf, buf, klen);
-#endif
 
 	if (!EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
 		(unsigned char *)buf,klen,1,key,NULL))
@@ -482,15 +474,9 @@
 	for (;;)
 		{
 		c= *header;
-#ifndef CHARSET_EBCDIC
 		if (!(	((c >= 'A') && (c <= 'Z')) || (c == '-') ||
 			((c >= '0') && (c <= '9'))))
 			break;
-#else
-		if (!(	isupper(c) || (c == '-') ||
-			isdigit(c)))
-			break;
-#endif
 		header++;
 		}
 	*header='\0';
diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c
index 91d4ac7..91a52de 100644
--- a/crypto/x509/t_x509.c
+++ b/crypto/x509/t_x509.c
@@ -473,7 +473,6 @@
 	c=s;
 	for (;;)
 		{
-#ifndef CHARSET_EBCDIC
 		if (	((*s == '/') &&
 				((s[1] >= 'A') && (s[1] <= 'Z') && (
 					(s[2] == '=') ||
@@ -481,15 +480,6 @@
 					(s[3] == '='))
 				 ))) ||
 			(*s == '\0'))
-#else
-		if (	((*s == '/') &&
-				(isupper(s[1]) && (
-					(s[2] == '=') ||
-					(isupper(s[2]) &&
-					(s[3] == '='))
-				 ))) ||
-			(*s == '\0'))
-#endif
 			{
 			i=s-c;
 			if (BIO_write(bp,c,i) != i) goto err;
diff --git a/crypto/x509/x509_obj.c b/crypto/x509/x509_obj.c
index 434108c..5f539ab 100644
--- a/crypto/x509/x509_obj.c
+++ b/crypto/x509/x509_obj.c
@@ -75,9 +75,6 @@
 	static const char hex[17]="0123456789ABCDEF";
 	int gs_doit[4];
 	char tmp_buf[80];
-#ifdef CHARSET_EBCDIC
-	char ebcdic_buf[1024];
-#endif
 
 	if (buf == NULL)
 		{
@@ -114,19 +111,6 @@
 		type=ne->value->type;
 		num=ne->value->length;
 		q=ne->value->data;
-#ifdef CHARSET_EBCDIC
-                if (type == V_ASN1_GENERALSTRING ||
-		    type == V_ASN1_VISIBLESTRING ||
-		    type == V_ASN1_PRINTABLESTRING ||
-		    type == V_ASN1_TELETEXSTRING ||
-		    type == V_ASN1_VISIBLESTRING ||
-		    type == V_ASN1_IA5STRING) {
-                        ascii2ebcdic(ebcdic_buf, q,
-				     (num > sizeof ebcdic_buf)
-				     ? sizeof ebcdic_buf : num);
-                        q=ebcdic_buf;
-		}
-#endif
 
 		if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))
 			{
@@ -149,12 +133,7 @@
 			{
 			if (!gs_doit[j&3]) continue;
 			l2++;
-#ifndef CHARSET_EBCDIC
 			if ((q[j] < ' ') || (q[j] > '~')) l2+=3;
-#else
-			if ((os_toascii[q[j]] < os_toascii[' ']) ||
-			    (os_toascii[q[j]] > os_toascii['~'])) l2+=3;
-#endif
 			}
 
 		lold=l;
@@ -174,14 +153,11 @@
 		memcpy(p,s,(unsigned int)l1); p+=l1;
 		*(p++)='=';
 
-#ifndef CHARSET_EBCDIC /* q was assigned above already. */
 		q=ne->value->data;
-#endif
 
 		for (j=0; j<num; j++)
 			{
 			if (!gs_doit[j&3]) continue;
-#ifndef CHARSET_EBCDIC
 			n=q[j];
 			if ((n < ' ') || (n > '~'))
 				{
@@ -192,19 +168,6 @@
 				}
 			else
 				*(p++)=n;
-#else
-			n=os_toascii[q[j]];
-			if ((n < os_toascii[' ']) ||
-			    (n > os_toascii['~']))
-				{
-				*(p++)='\\';
-				*(p++)='x';
-				*(p++)=hex[(n>>4)&0x0f];
-				*(p++)=hex[n&0x0f];
-				}
-			else
-				*(p++)=q[j];
-#endif
 			}
 		*p='\0';
 		}
diff --git a/crypto/x509v3/v3_ia5.c b/crypto/x509v3/v3_ia5.c
index 04ef05c..39d6ef8 100644
--- a/crypto/x509v3/v3_ia5.c
+++ b/crypto/x509v3/v3_ia5.c
@@ -109,9 +109,6 @@
 		M_ASN1_IA5STRING_free(ia5);
 		goto err;
 	}
-#ifdef CHARSET_EBCDIC
-        ebcdic2ascii(ia5->data, ia5->data, ia5->length);
-#endif /*CHARSET_EBCDIC*/
 	return ia5;
 	err:
 	OPENSSL_PUT_ERROR(X509V3, s2i_ASN1_IA5STRING, ERR_R_MALLOC_FAILURE);
diff --git a/crypto/x509v3/v3_prn.c b/crypto/x509v3/v3_prn.c
index 3374600..87aef4d 100644
--- a/crypto/x509v3/v3_prn.c
+++ b/crypto/x509v3/v3_prn.c
@@ -85,22 +85,7 @@
 		nval = sk_CONF_VALUE_value(val, i);
 		if(!nval->name) BIO_puts(out, nval->value);
 		else if(!nval->value) BIO_puts(out, nval->name);
-#ifndef CHARSET_EBCDIC
 		else BIO_printf(out, "%s:%s", nval->name, nval->value);
-#else
-		else {
-			int len;
-			char *tmp;
-			len = strlen(nval->value)+1;
-			tmp = OPENSSL_malloc(len);
-			if (tmp)
-			{
-				ascii2ebcdic(tmp, nval->value, len);
-				BIO_printf(out, "%s:%s", nval->name, tmp);
-				OPENSSL_free(tmp);
-			}
-		}
-#endif
 		if(ml) BIO_puts(out, "\n");
 	}
 }
@@ -129,22 +114,7 @@
 			ok = 0;
 			goto err;
 		}
-#ifndef CHARSET_EBCDIC
 		BIO_printf(out, "%*s%s", indent, "", value);
-#else
-		{
-			int len;
-			char *tmp;
-			len = strlen(value)+1;
-			tmp = OPENSSL_malloc(len);
-			if (tmp)
-			{
-				ascii2ebcdic(tmp, value, len);
-				BIO_printf(out, "%*s%s", indent, "", tmp);
-				OPENSSL_free(tmp);
-			}
-		}
-#endif
 	} else if(method->i2v) {
 		if(!(nval = method->i2v(method, ext_str, NULL))) {
 			ok = 0;
diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c
index 3bbc606..4cd0c0c 100644
--- a/crypto/x509v3/v3_utl.c
+++ b/crypto/x509v3/v3_utl.c
@@ -383,9 +383,6 @@
 		*q++ = ':';
 	}
 	q[-1] = 0;
-#ifdef CHARSET_EBCDIC
-	ebcdic2ascii(tmp, tmp, q - tmp - 1);
-#endif
 
 	return tmp;
 }
@@ -405,14 +402,8 @@
 	if(!(hexbuf = OPENSSL_malloc(strlen(str) >> 1))) goto err;
 	for(p = (unsigned char *)str, q = hexbuf; *p;) {
 		ch = *p++;
-#ifdef CHARSET_EBCDIC
-		ch = os_toebcdic[ch];
-#endif
 		if(ch == ':') continue;
 		cl = *p++;
-#ifdef CHARSET_EBCDIC
-		cl = os_toebcdic[cl];
-#endif
 		if(!cl) {
 			OPENSSL_PUT_ERROR(X509V3, string_to_hex, X509V3_R_ODD_NUMBER_OF_DIGITS);
 			OPENSSL_free(hexbuf);
@@ -1281,21 +1272,13 @@
 		 * multiple instances 
 		 */
 		for(p = type; *p ; p++) 
-#ifndef CHARSET_EBCDIC
 			if ((*p == ':') || (*p == ',') || (*p == '.'))
-#else
-			if ((*p == os_toascii[':']) || (*p == os_toascii[',']) || (*p == os_toascii['.']))
-#endif
 				{
 				p++;
 				if(*p) type = p;
 				break;
 				}
-#ifndef CHARSET_EBCDIC
 		if (*type == '+')
-#else
-		if (*type == os_toascii['+'])
-#endif
 			{
 			mval = -1;
 			type++;
diff --git a/ssl/s3_enc.c b/ssl/s3_enc.c
index 6ab267e..8f6d75b 100644
--- a/ssl/s3_enc.c
+++ b/ssl/s3_enc.c
@@ -169,9 +169,6 @@
 	unsigned char c='A';
 	unsigned int i,j,k;
 
-#ifdef CHARSET_EBCDIC
-	c = os_toascii[c]; /*'A' in ASCII */
-#endif
 	k=0;
 	EVP_MD_CTX_init(&m5);
 	EVP_MD_CTX_init(&s1);
@@ -786,15 +783,9 @@
 	     int len)
 	{
 	static const unsigned char *salt[3]={
-#ifndef CHARSET_EBCDIC
 		(const unsigned char *)"A",
 		(const unsigned char *)"BB",
 		(const unsigned char *)"CCC",
-#else
-		(const unsigned char *)"\x41",
-		(const unsigned char *)"\x42\x42",
-		(const unsigned char *)"\x43\x43\x43",
-#endif
 		};
 	unsigned char buf[EVP_MAX_MD_SIZE];
 	EVP_MD_CTX ctx;
diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c
index 79e52c8..f8238ac 100644
--- a/ssl/ssl_ciph.c
+++ b/ssl/ssl_ciph.c
@@ -1092,14 +1092,10 @@
 			ch = *l;
 			buf = l;
 			buflen = 0;
-#ifndef CHARSET_EBCDIC
 			while (	((ch >= 'A') && (ch <= 'Z')) ||
 				((ch >= '0') && (ch <= '9')) ||
 				((ch >= 'a') && (ch <= 'z')) ||
 				 (ch == '-') || (ch == '.'))
-#else
-			while (	isalnum(ch) || (ch == '-') || (ch == '.'))
-#endif
 				 {
 				 ch = *(++l);
 				 buflen++;
diff --git a/ssl/tls1.h b/ssl/tls1.h
index c26a05a..81daa73 100644
--- a/ssl/tls1.h
+++ b/ssl/tls1.h
@@ -732,24 +732,6 @@
 #define TLS_MD_MASTER_SECRET_CONST		"master secret"
 #define TLS_MD_MASTER_SECRET_CONST_SIZE		13
 
-#ifdef CHARSET_EBCDIC
-#undef TLS_MD_CLIENT_FINISH_CONST
-#define TLS_MD_CLIENT_FINISH_CONST    "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64"  /*client finished*/
-#undef TLS_MD_SERVER_FINISH_CONST
-#define TLS_MD_SERVER_FINISH_CONST    "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64"  /*server finished*/
-#undef TLS_MD_SERVER_WRITE_KEY_CONST
-#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79"  /*server write key*/
-#undef TLS_MD_KEY_EXPANSION_CONST
-#define TLS_MD_KEY_EXPANSION_CONST    "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e"  /*key expansion*/
-#undef TLS_MD_CLIENT_WRITE_KEY_CONST
-#define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79"  /*client write key*/
-#undef TLS_MD_SERVER_WRITE_KEY_CONST
-#define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79"  /*server write key*/
-#undef TLS_MD_IV_BLOCK_CONST
-#define TLS_MD_IV_BLOCK_CONST         "\x49\x56\x20\x62\x6c\x6f\x63\x6b"  /*IV block*/
-#undef TLS_MD_MASTER_SECRET_CONST
-#define TLS_MD_MASTER_SECRET_CONST    "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74"  /*master secret*/
-#endif
 
 /* TLS Session Ticket extension struct */
 struct tls_session_ticket_ext_st