Ensure we use a non-zero time for tickets in early data
[openssl.git] / crypto / ctype.c
index f90ef19e79aafc187925555d3443b77423179672..d46aeac6ec0427d845d8a3ba3e7e5fe3b5b134f3 100644 (file)
 #include "crypto/ctype.h"
 #include <openssl/ebcdic.h>
 
-#include "internal/e_os.h"
-#include "internal/core.h"
-#ifndef OPENSSL_NO_LOCALE
-# include <locale.h>
-# ifdef OPENSSL_SYS_MACOSX
-#  include <xlocale.h>
-# endif
-#endif
 /*
  * Define the character classes for each character in the seven bit ASCII
  * character set.  This is independent of the host's character set, characters
@@ -265,81 +257,57 @@ int ossl_ctype_check(int c, unsigned int mask)
     return a >= 0 && a < max && (ctype_char_map[a] & mask) != 0;
 }
 
-#if defined(CHARSET_EBCDIC) && !defined(CHARSET_EBCDIC_TEST)
-static const int case_change = 0x40;
-#else
-static const int case_change = 0x20;
-#endif
+/*
+ * Implement some of the simpler functions directly to avoid the overhead of
+ * accessing memory via ctype_char_map[].
+ */
 
-int ossl_tolower(int c)
-{
-    return ossl_isupper(c) ? c ^ case_change : c;
-}
+#define ASCII_IS_DIGIT(c)   (c >= 0x30 && c <= 0x39)
+#define ASCII_IS_UPPER(c)   (c >= 0x41 && c <= 0x5A)
+#define ASCII_IS_LOWER(c)   (c >= 0x61 && c <= 0x7A)
 
-int ossl_toupper(int c)
+int ossl_isdigit(int c)
 {
-    return ossl_islower(c) ? c ^ case_change : c;
-}
-
-int ossl_ascii_isdigit(const char inchar) {
-    if (inchar > 0x2F && inchar < 0x3A)
-        return 1;
-    return 0;
-}
-
-#ifndef OPENSSL_NO_LOCALE
-# ifndef FIPS_MODULE
-static locale_t loc;
-
+    int a = ossl_toascii(c);
 
-void *ossl_c_locale() {
-    return (void *)loc;
+    return ASCII_IS_DIGIT(a);
 }
 
-int ossl_init_casecmp_int() {
-# ifdef OPENSSL_SYS_WINDOWS
-    loc = _create_locale(LC_COLLATE, "C");
-# else
-    loc = newlocale(LC_COLLATE_MASK, "C", (locale_t) 0);
-# endif
-    return (loc == (locale_t) 0) ? 0 : 1;
-}
+int ossl_isupper(int c)
+{
+    int a = ossl_toascii(c);
 
-void ossl_deinit_casecmp() {
-    freelocale(loc);
+    return ASCII_IS_UPPER(a);
 }
-# endif
 
-int OPENSSL_strcasecmp(const char *s1, const char *s2)
+int ossl_islower(int c)
 {
-    return strcasecmp_l(s1, s2, (locale_t)ossl_c_locale());
-}
+    int a = ossl_toascii(c);
 
-int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n)
-{
-    return strncasecmp_l(s1, s2, n, (locale_t)ossl_c_locale());
+    return ASCII_IS_LOWER(a);
 }
+
+#if defined(CHARSET_EBCDIC) && !defined(CHARSET_EBCDIC_TEST)
+static const int case_change = 0x40;
 #else
-# ifndef FIPS_MODULE
-void *ossl_c_locale() {
-    return NULL;
-}
-# endif
+static const int case_change = 0x20;
+#endif
 
-int ossl_init_casecmp_int() {
-    return 1;
-}
+int ossl_tolower(int c)
+{
+    int a = ossl_toascii(c);
 
-void ossl_deinit_casecmp() {
+    return ASCII_IS_UPPER(a) ? c ^ case_change : c;
 }
 
-int OPENSSL_strcasecmp(const char *s1, const char *s2)
+int ossl_toupper(int c)
 {
-    return strcasecmp(s1, s2);
+    int a = ossl_toascii(c);
+
+    return ASCII_IS_LOWER(a) ? c ^ case_change : c;
 }
 
-int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n)
+int ossl_ascii_isdigit(int c)
 {
-    return strncasecmp(s1, s2, n);
+    return ASCII_IS_DIGIT(c);
 }
-#endif