From 0005f47381a7ae394e68e1b6f57d95d92736b34d Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Thu, 25 Aug 2011 01:17:46 +0200
Subject: [PATCH 36/39] refactoring of unicode names, update docs, update comments

---
 doc/ENCODINGS                |   54 ++++++++++++++++
 doc/RULES                    |   11 +++-
 doc/UTF8                     |   58 -----------------
 doc/UTF8-DEVEL.txt           |   71 ---------------------
 src/NETLMv2_fmt_plug.c       |   14 ++--
 src/NETNTLMv2_fmt_plug.c     |    4 +-
 src/NT_fmt_plug.c            |   10 ++--
 src/cracker.c                |   10 +--
 src/md5_gen_fmt.c            |   30 +++++-----
 src/mscash1_fmt_plug.c       |   10 ++--
 src/mscash2_fmt_plug.c       |    8 +-
 src/mssql-old_fmt_plug.c     |   14 ++--
 src/mssql05_fmt_plug.c       |    4 +-
 src/oracle_fmt_plug.c        |   17 +++---
 src/rawMD5unicode_fmt_plug.c |    4 +-
 src/sapG_fmt_plug.c          |    4 +-
 src/status.c                 |    8 +-
 src/unicode.c                |  139 ++++++++++++++++++++++--------------------
 src/unicode.h                |   52 +++++++++-------
 19 files changed, 233 insertions(+), 289 deletions(-)
 create mode 100644 doc/ENCODINGS
 delete mode 100644 doc/UTF8
 delete mode 100644 doc/UTF8-DEVEL.txt

diff --git a/doc/ENCODINGS b/doc/ENCODINGS
new file mode 100644
index 0000000..f1e6d7e
--- /dev/null
+++ b/doc/ENCODINGS
@@ -0,0 +1,54 @@
+This version of John is UTF-8 and codepage aware, using a new command line
+argument. In short, this means "my wordlists and input files are encoded in
+UTF-8" (or CP1252 etc). It does NOT mean you can feed John with eg. a UTF-8
+encoded wordlist when cracking LM. It DOES make John recognise vowels, lower
+or upper case characters, etc. when specifying a codepage.
+
+Currently supported encodings: utf-8, iso-8859-1 (or ansi), koi8-r, cp1251,
+cp866, cp1252, iso-8859-15, cp437, cp850, cp858 and cp737. New encodings can
+be added with ease, using automated tools that rely on the Unicode Database.
+
+
+Example usage:
+  john hashes.txt --wordlist:spanish.dic --encoding:iso-8859-1 --rules
+
+
+The behaviour is a little different depending on whether the format use Unicode
+(UTF-16 or UCS-2) internally or not.
+
+ * For Unicode formats (eg. NT, mssql, etc), you can pick any of the encodings
+   and the input candidates will be properly converted to UTF-16.
+
+ * For non-Unicode formats (eg. DES, LM, MD5 etc), no actual conversion will
+   be made so you need to use an encoding that matches what the hashes were
+   made from. But you should still tell John about it so it can handle national
+   characters properly.
+
+You can convert from/to a large number of formats, see iconv(1) man page.
+
+The traditional behavior, and what is still happening if you don't specify an
+encoding, is that John will assume ISO-8859-1 when converting plaintexts or
+salts to UTF-16, and assume ASCII in most other cases (it will use 8-bit
+candidates as-is, but not upper/lower-case them or recognise letters etc).
+
+Some new reject rules and character classes are implemented, see doc/RULES.
+Note that UTF-8 is not handled well in rules. Some wordlist rules may cut
+UTF-8 multibyte sequences in the middle, resulting in garbage. You can reject
+such rules with -U to have them in use only when --encoding=utf8 is not used.
+
+Also, the recognition of non-ASCII characters for upper/lower-casing etc does
+not work with UTF-8 in Rules engine. Formats that internally uppercase
+it's plaintexts, like old MSSQL, will uppercase properly though.
+
+Caveats:
+Beware of UTF-8 BOM's. They will cripple the first word in your wordlist.
+
+
+--
+
+These contributions to John are hereby placed in the public domain. In case
+that is not applicable, they are Copyright 2009, 2010, 2011 by magnum and
+JimF and hereby released to the general public. Redistribution and use in
+source and binary forms, with or without modification, is permitted.
+
+magnum
diff --git a/doc/RULES b/doc/RULES
index 6979000..3a00f7f 100644
--- a/doc/RULES
+++ b/doc/RULES
@@ -70,13 +70,14 @@ example, "?D" matches everything but digits.
 
 NOTE, if running in --encoding=iso-8859-1 (or koi8-r/cp1251/cp866,etc), then the
 high bit characters are added to the respective classes. So in iso-8859-1 mode,
-lower case ?l would be: [a-z]|[\xE0-\xF6]|[\xF8-\xFE] while in 'normal' runs,
-it is only [a-z]. This currently affects all classes except ?v and ?c.
+lower case ?l would include àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþßÿ while in 'normal'
+runs, it is only a-z.
 
 NOTE 2, the rules engine currently have very limited understanding of UTF-8 so
 character classes etc. will only work with ASCII characters, even if using
 --encoding=utf8.
 
+
 	Simple commands.
 
 :	no-op: do nothing to the input word
@@ -94,6 +95,10 @@ f	reflect: "Fred" -> "FredderF"
 $X	append character X to the word
 ^X	prefix the word with character X
 
+NOTE, all of these are encoding-aware. Eg. if you do not specify an encoding,
+the l command will lowercase A-Z only. If you use --encoding=iso-8859-1 it will
+also recognise ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ and lowercase them properly.
+
 
 	String commands.
 
@@ -153,6 +158,8 @@ V	lowercase vowels, uppercase consonants: "Crack96" -> "CRaCK96"
 R	shift each character right, by keyboard: "Crack96" -> "Vtsvl07"
 L	shift each character left, by keyboard: "Crack96" -> "Xeaxj85"
 
+NOTE, of these, only S and V are encoding-aware.
+
 
 	Memory access commands.
 
diff --git a/doc/UTF8 b/doc/UTF8
deleted file mode 100644
index 4f05f49..0000000
--- a/doc/UTF8
+++ /dev/null
@@ -1,58 +0,0 @@
-This version of John is UTF-8 aware, using a new option flag. In short,
-this flag says "my wordlists and input files are encoded in UTF-8" and
-it can be used without knowing if the particular format is affected or
-not.
-
-Without this support, John will assume ISO-8859-1 when converting
-plaintexts or salts to UTF-16. This affects many Microsoft formats
-like NT, mscash and mssql. Other formats, like DES or MD5 are never
-doing such conversion, so you would just use wordlists encoded in the
-same format as the hashes once were generated in. The --encoding=utf8
-flag is supported for such formats too, but will only affect the new
-reject rules, see below.
-
-To enable UTF-8 conversion, just add the --encoding=utf8 flag. This will
-affect not only wordlist files, but also salts, usernames (when used as
-salt) and any info used by --single. You can also test all the UTF-8
-aware formats at once using "john --test --encoding=utf8"
-
-To convert a wordlist to UTF-8, use iconv(1):
-
-$ iconv -f koi8r -t utf-8 cslang >cslang.utf8
-
-You can convert from/to a large number of formats, see iconv's man page.
-
-
-Two new reject rules are implemented:
-
- -u   reject rule unless the --encoding=utf8 flag is used
-
- -U   reject rule if the --encoding=utf8 flag is used
-
-Note that this can be used to enable/disable certain rules even for
-formats that does not use UTF-16 internally (eg. raw md5 of utf-8
-plaintexts).
-
-
-A new character class is also implemented, ?b (b for binary). It matches
-8-bit characters. This can be used with or without the UTF-8 support.
-
-
-Caveats:
-- UTF-8 conversion is often slower than the default ISO-8859-1 one, so
-it's advisable to only use this when you have to. That is, when your
-wordlist contains characters not included in ISO-8859-1.
-- Some wordlist rules may cut UTF-8 multibyte sequences in the middle,
-resulting in garbage. You can reject such rules with -U to have them in
-use only when --encoding=utf8 is not used.
-- Beware of UTF-8 BOM's. Do not use them (they will cripple the first word
-in your wordlist, that's all).
-
---
-
-These contributions to John are hereby placed in the public domain. In
-case that is not applicable, they are Copyright 2009, 2010, 2011 by me and
-hereby released to the general public. Redistribution and use in source
-and binary forms, with or without modification, is permitted.
-
-magnum
diff --git a/doc/UTF8-DEVEL.txt b/doc/UTF8-DEVEL.txt
deleted file mode 100644
index 3a97794..0000000
--- a/doc/UTF8-DEVEL.txt
+++ /dev/null
@@ -1,71 +0,0 @@
-These are "public" functions that can be used for supporting UTF-8 in your
-own formats for JtR. All are put in unicode.c.
-
-If you are not aware of UCS-2, just consider it a synonym to UTF-16. For our
-purposes, they are the same.
-
-
-Convert from ISO-8859-1 or UTF-8 to UTF-16LE:
-=============================================
-Source format depends on --encoding=utf8 flag given to john when running.
-If length is exceeded or malformed data is found, it will return a negative
-number telling you how much of the source that was read. That is, a return
-code of -32 means you have an UNKNOWN number of characters of UCS-2 [use
-strlen16()] in the destination buffer and you should truncate your
-"saved_plain" (if applicable) at 32.
-
-    #include "unicode.h"
-    int plaintowcs(UTF16 *dst, int maxdstlen, const UTF8 *src, int srclen);
-
-
-
-Convert UTF-8 to UTF-16LE:
-==========================
-Always from UTF-8. This is optimised for speed. If length is exceeded or
-malformed data is found, it will return a negative number telling you how much
-of the source that was read. That is, a return code of -32 means you have an
-UNKNOWN number of characters of UCS-2 [use strlen16()] in the destination
-buffer and you should truncate your "saved_plain" at 32.
-
-    #include "unicode.h"
-    int utf8towcs(UTF16 *target, int maxtargetlen,
-           const UTF8 *source, int sourcelen);
-
-
-
-Convert UTF-16LE to UTF-8:
-==========================
-Currently used in NT_fmt.c in order to avoid using a saved_plain buffer.
-
-    #include "unicode.h"
-    extern char * utf16toutf8 (const UTF16* source);
-
-
-
-Return length (in characters) of a UTF16 string:
-================================================
-Number of octets is the result * sizeof(UTF16)
-
-    #include "unicode.h"
-    int strlen16(const UTF16 *str);
-
-
-
-Create an NT hash:
-==================
-This will convert from ISO-8859 or UTF-8 depending on the --encoding=utf8 option.
-The function will use Alain's fast NT hashing if length is <= 27 characters,
-otherwise it will use Solar's MD4. Lengths up to MAX_PLAINTEXT_LENGTH is thus
-supported with no hassle for you. If length is exceeded or malformed data is
-found, it will return a negative number telling you how much of the source
-that was read. That is, a return code of -32 means you should truncate your
-"saved_plain" at 32.
-
-    #include "unicode.h"
-    int E_md4hash(const UTF8 *passwd, int len, unsigned char *p16);
-
-
-
-NOTE that there are more functions available in ConvertUTF.c.original
-(ConvertUTF.h.original) and if we need any of them, we should copy them to
-unicode.c/h and simplify/optimize them.
diff --git a/src/NETLMv2_fmt_plug.c b/src/NETLMv2_fmt_plug.c
index 34df6a2..de77b1c 100644
--- a/src/NETLMv2_fmt_plug.c
+++ b/src/NETLMv2_fmt_plug.c
@@ -343,9 +343,9 @@ static void *netlmv2_get_salt(char *ciphertext)
 {
   static unsigned char *binary_salt;
   unsigned char identity[USERNAME_LENGTH + DOMAIN_LENGTH + 1];
-  UTF16 identity_usc[USERNAME_LENGTH + DOMAIN_LENGTH + 1];
+  UTF16 identity_ucs2[USERNAME_LENGTH + DOMAIN_LENGTH + 1];
   int i, identity_length;
-  int identity_usc_length;
+  int identity_ucs2_length;
   char *pos = NULL;
 
   if (!binary_salt) binary_salt = mem_alloc_tiny(SALT_SIZE, MEM_ALIGN_WORD);
@@ -356,13 +356,13 @@ static void *netlmv2_get_salt(char *ciphertext)
 
   /* Convert identity (username + domain) string to NT unicode */
   strnzcpy((char *)identity, ciphertext + 9, sizeof(identity));
-  identity_usc_length = plaintowcs((UTF16 *)identity_usc, USERNAME_LENGTH + DOMAIN_LENGTH, (UTF8 *)identity, identity_length) * sizeof(int16);
+  identity_ucs2_length = enc_to_utf16((UTF16 *)identity_ucs2, USERNAME_LENGTH + DOMAIN_LENGTH, (UTF8 *)identity, identity_length) * sizeof(int16);
 
-  if (identity_usc_length < 0) // Truncated at Unicode conversion.
-	  identity_usc_length = strlen16((UTF16 *)identity_usc) * sizeof(int16);
+  if (identity_ucs2_length < 0) // Truncated at Unicode conversion.
+	  identity_ucs2_length = strlen16((UTF16 *)identity_ucs2) * sizeof(int16);
 
-  binary_salt[16] = (unsigned char)identity_usc_length;
-  memcpy(&binary_salt[17], (char *)identity_usc, identity_usc_length);
+  binary_salt[16] = (unsigned char)identity_ucs2_length;
+  memcpy(&binary_salt[17], (char *)identity_ucs2, identity_ucs2_length);
 
   /* Set server challenge */
   ciphertext += 10 + identity_length;
diff --git a/src/NETNTLMv2_fmt_plug.c b/src/NETNTLMv2_fmt_plug.c
index cdf5ca7..3c6b576 100644
--- a/src/NETNTLMv2_fmt_plug.c
+++ b/src/NETNTLMv2_fmt_plug.c
@@ -396,12 +396,12 @@ static void *netntlmv2_get_salt(char *ciphertext)
 
   /* Convert identity (username + domain) string to NT unicode */
 #if !ARCH_ALLOWS_UNALIGNED
-  identity_length = plaintowcs((uint16 *)bs2, 2 * (USERNAME_LENGTH + DOMAIN_LENGTH), (uchar *)ciphertext + 11, pos - (ciphertext + 11)) * sizeof(int16);
+  identity_length = enc_to_utf16((uint16 *)bs2, 2 * (USERNAME_LENGTH + DOMAIN_LENGTH), (uchar *)ciphertext + 11, pos - (ciphertext + 11)) * sizeof(int16);
   if (identity_length < 0) // Truncated at Unicode conversion.
 	  identity_length = strlen16((UTF16 *)bs2) * sizeof(int16);
   memcpy(&binary_salt[1], bs2, identity_length);
 #else
-  identity_length = plaintowcs((uint16 *)&binary_salt[1], 2 * (USERNAME_LENGTH + DOMAIN_LENGTH), (uchar *)ciphertext + 11, pos - (ciphertext + 11)) * sizeof(int16);
+  identity_length = enc_to_utf16((uint16 *)&binary_salt[1], 2 * (USERNAME_LENGTH + DOMAIN_LENGTH), (uchar *)ciphertext + 11, pos - (ciphertext + 11)) * sizeof(int16);
   if (identity_length < 0) // Truncated at Unicode conversion.
 	  identity_length = strlen16((UTF16 *)&binary_salt[1]) * sizeof(int16);
 #endif
diff --git a/src/NT_fmt_plug.c b/src/NT_fmt_plug.c
index d8519cc..ba53938 100644
--- a/src/NT_fmt_plug.c
+++ b/src/NT_fmt_plug.c
@@ -791,7 +791,7 @@ static inline void set_key_helper_encoding(unsigned int * keybuffer,
 	unsigned int i=0;
 	int md4_size;
 	if (xBuf == 1) {
-		md4_size = plaintowcs( (UTF16 *)keybuffer, PLAINTEXT_LENGTH, (UTF8 *) key, strlen((char*)key));
+		md4_size = enc_to_utf16( (UTF16 *)keybuffer, PLAINTEXT_LENGTH, (UTF8 *) key, strlen((char*)key));
 		if (md4_size < 0)
 			md4_size = strlen16((UTF16 *)keybuffer);
 #if ARCH_LITTLE_ENDIAN
@@ -879,16 +879,16 @@ static inline UTF16 *get_key_helper(unsigned int * keybuffer, unsigned int xBuf)
 static char *get_key(int index)
 {
 #if defined(NT_X86_64)
-	return (char*)utf16toplain(get_key_helper(&nt_buffer8x[128 * (index >> 3) +
+	return (char*)utf16_to_enc(get_key_helper(&nt_buffer8x[128 * (index >> 3) +
 	                                                index % 8], 8));
 #elif defined(NT_SSE2)
 	if(index < NT_NUM_KEYS4)
-		return (char*)utf16toplain(get_key_helper(&nt_buffer4x[64 * (index >> 2) +
+		return (char*)utf16_to_enc(get_key_helper(&nt_buffer4x[64 * (index >> 2) +
 		                                                index % 4], 4));
 	else
-		return (char*)utf16toplain(get_key_helper(&nt_buffer1x[16 * (index - NT_NUM_KEYS4)], 1));
+		return (char*)utf16_to_enc(get_key_helper(&nt_buffer1x[16 * (index - NT_NUM_KEYS4)], 1));
 #else
-	return (char*)utf16toplain(get_key_helper(&nt_buffer1x[index << 4], 1));
+	return (char*)utf16_to_enc(get_key_helper(&nt_buffer1x[index << 4], 1));
 
 #endif
 }
diff --git a/src/cracker.c b/src/cracker.c
index 72e900e..52d6195 100644
--- a/src/cracker.c
+++ b/src/cracker.c
@@ -96,6 +96,7 @@ static int crk_process_guess(struct db_salt *salt, struct db_password *pw,
 {
 	UTF8 utf8buf_key[PLAINTEXT_BUFFER_SIZE + 1];
 	UTF8 utf8login[PLAINTEXT_BUFFER_SIZE + 1];
+	char tmp8[PLAINTEXT_BUFFER_SIZE + 1];
 	int dupe;
 	char *key, *utf8key, *repkey, *replogin;
 
@@ -109,23 +110,20 @@ static int crk_process_guess(struct db_salt *salt, struct db_password *pw,
 		if (options.utf8)
 			utf8key = key;
 		else {
-			utf8key = (char*)enctoutf8_r(key, utf8buf_key);
-#if 1
+			utf8key = (char*)enc_to_utf8_r(key, utf8buf_key);
 			// Double-check that the conversion was correct. Our
 			// fallback is to log, warn and use the original key instead.
-			char tmp8[PLAINTEXT_BUFFER_SIZE + 1];
-			utf8toenc_r((UTF8*)utf8key, tmp8);
+			utf8_to_enc_r((UTF8*)utf8key, tmp8);
 			if (strcmp(tmp8, key)) {
 				fprintf(stderr, "Warning, conversion failed %s -> %s -> %s - fallback to codepage\n", key, utf8key, tmp8);
 				log_event("Warning, conversion failed %s -> %s -> %s - fallback to codepage", key, utf8key, tmp8);
 				utf8key = key;
 			}
-#endif
 		}
 		if (options.report_utf8) {
 			repkey = utf8key;
 			if (crk_db->options->flags & DB_LOGIN)
-				replogin = (char*)enctoutf8_r(pw->login, utf8login);
+				replogin = (char*)enc_to_utf8_r(pw->login, utf8login);
 		}
 		if (options.store_utf8)
 			key = utf8key;
diff --git a/src/md5_gen_fmt.c b/src/md5_gen_fmt.c
index 61a228b..8d660eb 100644
--- a/src/md5_gen_fmt.c
+++ b/src/md5_gen_fmt.c
@@ -2624,7 +2624,7 @@ static inline void __append_string(char *Str, unsigned len)
 				UTF16 utf16Str[27+1]; // 27 chars is 'max' that fits in SSE without overflow, so that is where we limit it at now
 				int outlen;
 
-				outlen = utf8towcs(utf16Str, 27, (unsigned char*)Str, len) * sizeof(UTF16);
+				outlen = utf8_to_utf16(utf16Str, 27, (unsigned char*)Str, len) * sizeof(UTF16);
 				if (outlen <= 0)
 					outlen = strlen16(utf16Str) * sizeof(UTF16);
 				for (j = 0; j < m_count; ++j) {
@@ -2652,7 +2652,7 @@ static inline void __append_string(char *Str, unsigned len)
 		if (options.utf8) {
 			UTF16 utf16Str[256+1];
 			int outlen;
-			outlen = utf8towcs(utf16Str, 256, (unsigned char*)Str, len) * sizeof(UTF16);
+			outlen = utf8_to_utf16(utf16Str, 256, (unsigned char*)Str, len) * sizeof(UTF16);
 			if (outlen <= 0)
 				outlen = strlen16(utf16Str) * sizeof(UTF16);
 			for (j = 0; j < m_count; ++j) {
@@ -2719,7 +2719,7 @@ static inline void __append2_string(char *Str, unsigned len)
 				UTF16 utf16Str[27+1]; // 27 chars is 'max' that fits in SSE without overflow, so that is where we limit it at now
 				int outlen;
 
-				outlen = utf8towcs(utf16Str, 27, (unsigned char*)Str, len) * sizeof(UTF16);
+				outlen = utf8_to_utf16(utf16Str, 27, (unsigned char*)Str, len) * sizeof(UTF16);
 				if (outlen <= 0)
 					outlen = strlen16(utf16Str) * sizeof(UTF16);
 				for (j = 0; j < m_count; ++j) {
@@ -2747,7 +2747,7 @@ static inline void __append2_string(char *Str, unsigned len)
 		if (options.utf8) {
 			UTF16 utf16Str[256+1];
 			int outlen;
-			outlen = utf8towcs(utf16Str, 256, (unsigned char*)Str, len) * sizeof(UTF16);
+			outlen = utf8_to_utf16(utf16Str, 256, (unsigned char*)Str, len) * sizeof(UTF16);
 			if (outlen <= 0)
 				outlen = strlen16(utf16Str) * sizeof(UTF16);
 			for (j = 0; j < m_count; ++j) {
@@ -2918,7 +2918,7 @@ void MD5GenBaseFunc__append_keys()
 				if (options.utf8) {
 					UTF16 utf16Str[27+1]; // 27 chars is 'max' that fits in SSE without overflow, so that is where we limit it at now
 					int outlen;
-					outlen = utf8towcs(utf16Str, 27, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
+					outlen = utf8_to_utf16(utf16Str, 27, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
 					if (outlen <= 0)
 						outlen = strlen16(utf16Str) * sizeof(UTF16);
 					total_len[idx] += ( outlen << ((32/MMX_COEF)*idx_mod));
@@ -2942,7 +2942,7 @@ void MD5GenBaseFunc__append_keys()
 				unsigned char *cp, *cpi;
 				UTF16 utf16Str[256+1];
 				int outlen;
-				outlen = utf8towcs(utf16Str, 256, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
+				outlen = utf8_to_utf16(utf16Str, 256, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
 				if (outlen <= 0)
 					outlen = strlen16(utf16Str) * sizeof(UTF16);
 #if MD5_X2
@@ -3003,7 +3003,7 @@ void MD5GenBaseFunc__append_keys2()
 				if (options.utf8) {
 					UTF16 utf16Str[27+1]; // 27 chars is 'max' that fits in SSE without overflow, so that is where we limit it at now
 					int outlen;
-					outlen = utf8towcs(utf16Str, 27, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
+					outlen = utf8_to_utf16(utf16Str, 27, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
 					if (outlen <= 0)
 						outlen = strlen16(utf16Str) * sizeof(UTF16);
 					total_len2[idx] += ( outlen << ((32/MMX_COEF)*idx_mod));
@@ -3027,7 +3027,7 @@ void MD5GenBaseFunc__append_keys2()
 				unsigned char *cp, *cpi;
 				UTF16 utf16Str[256+1];
 				int outlen;
-				outlen = utf8towcs(utf16Str, 256, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
+				outlen = utf8_to_utf16(utf16Str, 256, (unsigned char*)saved_key[j], saved_key_len[j]) * sizeof(UTF16);
 				if (outlen <= 0)
 					outlen = strlen16(utf16Str) * sizeof(UTF16);
 #if MD5_X2
@@ -4499,7 +4499,7 @@ void MD5GenBaseFunc__overwrite_salt_to_input1_no_size_fix()
 			if (options.utf8) {
 				UTF16 utf16Str[27+1]; // 27 chars is 'max' that fits in SSE without overflow, so that is where we limit it at now
 				int outlen;
-				outlen = utf8towcs(utf16Str, 27, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
+				outlen = utf8_to_utf16(utf16Str, 27, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
 				if (outlen <= 0)
 					outlen = strlen16(utf16Str) * sizeof(UTF16);
 				for (j = 0; j < m_count; ++j) {
@@ -4520,7 +4520,7 @@ void MD5GenBaseFunc__overwrite_salt_to_input1_no_size_fix()
 		if (options.utf8) {
 			UTF16 utf16Str[256+1];
 			int outlen;
-			outlen = utf8towcs(utf16Str, 256, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
+			outlen = utf8_to_utf16(utf16Str, 256, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
 			if (outlen <= 0)
 				outlen = strlen16(utf16Str) * sizeof(UTF16);
 
@@ -4572,7 +4572,7 @@ void MD5GenBaseFunc__overwrite_salt_to_input2_no_size_fix()
 			if (options.utf8) {
 				UTF16 utf16Str[27+1]; // 27 chars is 'max' that fits in SSE without overflow, so that is where we limit it at now
 				int outlen;
-				outlen = utf8towcs(utf16Str, 27, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
+				outlen = utf8_to_utf16(utf16Str, 27, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
 				if (outlen <= 0)
 					outlen = strlen16(utf16Str) * sizeof(UTF16);
 				for (j = 0; j < m_count; ++j) {
@@ -4593,7 +4593,7 @@ void MD5GenBaseFunc__overwrite_salt_to_input2_no_size_fix()
 		if (options.utf8) {
 			UTF16 utf16Str[256+1];
 			int outlen;
-			outlen = utf8towcs(utf16Str, 256, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
+			outlen = utf8_to_utf16(utf16Str, 256, (unsigned char*)cursalt, saltlen) * sizeof(UTF16);
 			if (outlen <= 0)
 				outlen = strlen16(utf16Str) * sizeof(UTF16);
 
@@ -6806,15 +6806,15 @@ static char *HandleCase(char *cp, int caseType)
 		case 1:
 			return cp;
 		case 2:
-			utf8_uc(dest, sizeof(dest), (unsigned char*)cp, strlen(cp));
+			enc_uc(dest, sizeof(dest), (unsigned char*)cp, strlen(cp));
 			if (!strcmp((char*)dest, cp))
 				return cp;
 			break;
 		case 3:
 		case 4:
-			utf8_lc(dest, sizeof(dest), (unsigned char*)cp, strlen(cp));
+			enc_lc(dest, sizeof(dest), (unsigned char*)cp, strlen(cp));
 			if (caseType == 4)
-				dest[0] = low2up_ascii(dest[0]);
+				dest[0] = low2up_ansi(dest[0]);
 			if (!strcmp((char*)dest, cp))
 				return cp;
 			break;
diff --git a/src/mscash1_fmt_plug.c b/src/mscash1_fmt_plug.c
index 4d978b4..6147d96 100644
--- a/src/mscash1_fmt_plug.c
+++ b/src/mscash1_fmt_plug.c
@@ -191,7 +191,7 @@ static int valid(char *ciphertext, struct fmt_main *pFmt)
 			return 0;
 
 	// This is tricky: Max supported salt length is 19 characters of Unicode
-	saltlen = plaintowcs(realsalt, 20, (UTF8*)strnzcpy(insalt, &ciphertext[2], l - 2), l - 3);
+	saltlen = enc_to_utf16(realsalt, 20, (UTF8*)strnzcpy(insalt, &ciphertext[2], l - 2), l - 3);
 	if (saltlen < 0 || saltlen > 19)
 			return 0;
 
@@ -272,7 +272,7 @@ static void *get_salt_encoding(char *_ciphertext) {
 	}
 	input[md4_size] = 0;
 
-	utf16len = plaintowcs(out, 19, input, md4_size);
+	utf16len = enc_to_utf16(out, 19, input, md4_size);
 	if (utf16len <= 0)
 		utf16len = strlen16(out);
 
@@ -302,7 +302,7 @@ static void * get_salt_utf8(char *_ciphertext)
 	memset(out,0,sizeof(out));
 	ciphertext+=2;
 	len = ((unsigned char*)strchr((char*)ciphertext, '#')) - ciphertext;
-	utf8towcs(ciphertext_utf16, 20, ciphertext, len+1);
+	utf8_to_utf16(ciphertext_utf16, 20, ciphertext, len+1);
 
 	for(;;md4_size++) {
 #if !ARCH_LITTLE_ENDIAN
@@ -825,7 +825,7 @@ static inline void set_key_helper_encoding(unsigned int * keybuffer,
 {
 	unsigned int i=0;
 	int md4_size;
-	md4_size = plaintowcs( (UTF16 *)keybuffer, PLAINTEXT_LENGTH, (UTF8 *) key, strlen((char*)key));
+	md4_size = enc_to_utf16( (UTF16 *)keybuffer, PLAINTEXT_LENGTH, (UTF8 *) key, strlen((char*)key));
 	if (md4_size < 0)
 		md4_size = strlen16((UTF16 *)keybuffer);
 
@@ -895,7 +895,7 @@ static inline UTF16 *get_key_helper(unsigned int * keybuffer, unsigned int xBuf)
 
 static char *get_key(int index)
 {
-	return (char *)utf16toplain(get_key_helper(&ms_buffer1x[index << 4], 1));
+	return (char *)utf16_to_enc(get_key_helper(&ms_buffer1x[index << 4], 1));
 }
 
 // Public domain hash function by DJ Bernstein (salt is a username)
diff --git a/src/mscash2_fmt_plug.c b/src/mscash2_fmt_plug.c
index 4d3bc63..270bdf1 100644
--- a/src/mscash2_fmt_plug.c
+++ b/src/mscash2_fmt_plug.c
@@ -30,7 +30,7 @@
  *	  were more efficient with orinal code, and thus received less of a performance boost.  Others
  *	  got a signicant improvment.
  *	- The utf8 code was greatly simplified.  There was no reason to try to optimized the UTF code as
- *	  the format is so slow that utf8 conversion is a non-issue. Thus the we always call the plaintowcs()
+ *	  the format is so slow that utf8 conversion is a non-issue. Thus the we always call the enc_to_utf16()
  *	  at the proper locations, and let that function deal with being in --encoding=utf8 switch mode or not.
  *	- Fixed code to properly work with BE systems, and alignment required systems.
  *	- Made some 'interface' changes to the SSE2i for SHA1, and to the sha-mmx.S code, to make it work
@@ -276,7 +276,7 @@ static int valid(char *ciphertext, struct fmt_main *pFmt)
 	i = 6;
 	while (ciphertext[i] && ciphertext[i] != '#') ++i;
 	++i;
-	saltlen = plaintowcs(realsalt, 22, (UTF8*)strnzcpy(insalt, &ciphertext[i], l-i), l-(i+1));
+	saltlen = enc_to_utf16(realsalt, 22, (UTF8*)strnzcpy(insalt, &ciphertext[i], l-i), l-(i+1));
 	if (saltlen < 0 || saltlen > 22)
 		return 0;
 
@@ -332,7 +332,7 @@ static void *get_salt(char *_ciphertext)
 	}
 	input[md4_size] = 0;
 
-	utf16len = plaintowcs(&out[2], 22, input, md4_size);
+	utf16len = enc_to_utf16(&out[2], 22, input, md4_size);
 	if (utf16len <= 0)
 		utf16len = strlen16(&out[2]);
 	out[0] = utf16len << 1;
@@ -682,7 +682,7 @@ static void crypt_all(int count)
 			int utf16len;
 			UTF16 pass_unicode[PLAINTEXT_LENGTH+1];
 			MD4_CTX ctx;
-			utf16len = plaintowcs(pass_unicode, PLAINTEXT_LENGTH, &key[PLAIN_KEY_LEN*i], strlen((char*)&key[PLAIN_KEY_LEN*i]));
+			utf16len = enc_to_utf16(pass_unicode, PLAINTEXT_LENGTH, &key[PLAIN_KEY_LEN*i], strlen((char*)&key[PLAIN_KEY_LEN*i]));
 			if (utf16len <= 0) {
 				key[PLAIN_KEY_LEN*i-utf16len] = 0;
 				if (utf16len != 0)
diff --git a/src/mssql-old_fmt_plug.c b/src/mssql-old_fmt_plug.c
index 7e79aa1..54d76f0 100644
--- a/src/mssql-old_fmt_plug.c
+++ b/src/mssql-old_fmt_plug.c
@@ -139,7 +139,7 @@ static void * mssql_get_salt(char * ciphertext)
 	return out2;
 }
 
-static void mssql_set_key_utf8(char *_key, int index);
+static void mssql_set_key_enc(char *_key, int index);
 extern struct fmt_main fmt_mssql;
 
 static void mssql_init(struct fmt_main *pFmt)
@@ -151,7 +151,7 @@ static void mssql_init(struct fmt_main *pFmt)
 	saved_key = mem_alloc_tiny(PLAINTEXT_LENGTH*2 + 1 + SALT_SIZE, MEM_ALIGN_WORD);
 #endif
 	if (options.utf8) {
-		fmt_mssql.methods.set_key = mssql_set_key_utf8;
+		fmt_mssql.methods.set_key = mssql_set_key_enc;
 		fmt_mssql.params.plaintext_length = PLAINTEXT_LENGTH * 3;
 	}
 	else if (options.iso8859_1 || options.encoding_7_bit) {
@@ -159,7 +159,7 @@ static void mssql_init(struct fmt_main *pFmt)
 	}
 	else {
 		// this function made to handle both utf8 and 'codepage' encodings.
-		fmt_mssql.methods.set_key = mssql_set_key_utf8;
+		fmt_mssql.methods.set_key = mssql_set_key_enc;
 	}
 }
 
@@ -173,7 +173,7 @@ static void mssql_set_key(char *key, int index) {
 	plain_keys[index] = key;
 #endif
 	orig_len = strlen(key);
-	utf8len = utf8_uc(utf8, PLAINTEXT_LENGTH, (unsigned char*)key, orig_len);
+	utf8len = enc_uc(utf8, PLAINTEXT_LENGTH, (unsigned char*)key, orig_len);
 	if (utf8len <= 0 && *key)
 		return;
 
@@ -202,7 +202,7 @@ static void mssql_set_key(char *key, int index) {
 #endif
 }
 
-static void mssql_set_key_utf8(char *key, int index) {
+static void mssql_set_key_enc(char *key, int index) {
 	UTF16 utf16key[PLAINTEXT_LENGTH+1], utf16key_tmp[PLAINTEXT_LENGTH+1];
 	int utf8len = strlen(key);
 	int i;
@@ -213,7 +213,7 @@ static void mssql_set_key_utf8(char *key, int index) {
 #else
 	plain_keys[index] = key;
 #endif
-	utf16len = plaintowcs(utf16key_tmp, PLAINTEXT_LENGTH, (unsigned char*)key, utf8len);
+	utf16len = enc_to_utf16(utf16key_tmp, PLAINTEXT_LENGTH, (unsigned char*)key, utf8len);
 	if (utf16len <= 0) {
 		utf8len = -utf16len;
 		if (utf16len != 0)
@@ -269,7 +269,7 @@ static char *mssql_get_key(int index) {
 	// Calling this will ONLY upcase characters 'valid' in the code page. There are MANY
 	// code pages which mssql WILL upcase the letter (in UCS-2), but there is no upper case value
 	// in the code page.  Thus we MUST keep the lower cased letter in this case.
-	utf8_uc(UC_Key, PLAINTEXT_LENGTH*3*3, (UTF8*)plain_keys[index], strlen(plain_keys[index]));
+	enc_uc(UC_Key, PLAINTEXT_LENGTH*3*3, (UTF8*)plain_keys[index], strlen(plain_keys[index]));
 	return (char*)UC_Key;
 }
 
diff --git a/src/mssql05_fmt_plug.c b/src/mssql05_fmt_plug.c
index 2d19c2b..a107283 100644
--- a/src/mssql05_fmt_plug.c
+++ b/src/mssql05_fmt_plug.c
@@ -217,7 +217,7 @@ static void mssql05_set_key_utf8(char *_key, int index) {
 	int utf8len = strlen(_key);
 	int i;
 	UTF16 utf16key[PLAINTEXT_LENGTH+1];
-	int utf16len = utf8towcs(utf16key, PLAINTEXT_LENGTH, key, utf8len);
+	int utf16len = utf8_to_utf16(utf16key, PLAINTEXT_LENGTH, key, utf8len);
 	if (utf16len <= 0) {
 		utf8len = -utf16len;
 		if (utf16len != 0)
@@ -263,7 +263,7 @@ static void mssql05_set_key_encoding(char *_key, int index) {
 	int utf8len = strlen(_key);
 	int i;
 	UTF16 utf16key[PLAINTEXT_LENGTH+1];
-	int utf16len = plaintowcs(utf16key, PLAINTEXT_LENGTH, key, utf8len);
+	int utf16len = enc_to_utf16(utf16key, PLAINTEXT_LENGTH, key, utf8len);
 	if (utf16len <= 0) {
 		utf8len = -utf16len;
 		if (utf16len != 0)
diff --git a/src/oracle_fmt_plug.c b/src/oracle_fmt_plug.c
index ff86d09..73b396e 100644
--- a/src/oracle_fmt_plug.c
+++ b/src/oracle_fmt_plug.c
@@ -134,13 +134,13 @@ static char *prepare(char *split_fields[10], struct fmt_main *pFmt)
 		MEM_FREE(cp);
 
 		// Upcase user name (in --encoding=utf8 mode if requested).
-		utf8len = utf8_uc(tmp8, 16*3, (unsigned char*)split_fields[0], strlen(split_fields[0]));
+		utf8len = enc_uc(tmp8, 16*3, (unsigned char*)split_fields[0], strlen(split_fields[0]));
 
 		if (utf8len <= 0 && split_fields[0][0])
 			return split_fields[1];
 
 		// make sure this 'fits' into 16 unicode's
-		utf16len = plaintowcs(tmp16, 16, tmp8, utf8len);
+		utf16len = enc_to_utf16(tmp16, 16, tmp8, utf8len);
 		if (utf16len <= 0)
 			return split_fields[1];
 
@@ -183,19 +183,19 @@ static void oracle_set_key(char *key, int index) {
 	UTF16 cur_key_mixedcase[PLAINTEXT_LENGTH+1];
 
 	plain_key = key;
-	key_length = plaintowcs((UTF16 *)cur_key_mixedcase, PLAINTEXT_LENGTH, (unsigned char*)key, strlen(key));
+	key_length = enc_to_utf16((UTF16 *)cur_key_mixedcase, PLAINTEXT_LENGTH, (unsigned char*)key, strlen(key));
 
 	if (key_length <= 0)
 		key_length = strlen16(cur_key_mixedcase);
 
+	// We convert and uppercase in one shot
 	key_length = utf16_uc((UTF16 *)cur_key, PLAINTEXT_LENGTH, cur_key_mixedcase, key_length);
 	// we have no way to 'undo' here, since the expansion is due to single-2-multi expansion in the upcase,
 	// and we can not 'fix' our password.  We simply have to 'not' properly decrypt this one, but protect ourselves.
 	if (key_length < 0)
 		key_length *= -1;
 
-	// This must be byte-swapped regardless of arch endianness
-	// We also uppercase here, currently only ASCII
+	// This must be byte-swapped to UTF-16BE
 #if ARCH_LITTLE_ENDIAN
 	for(;i<key_length;i++) {
 		UTF16 *c = &cur_key[i];
@@ -214,7 +214,7 @@ static char *oracle_get_key(int index) {
 	// Calling this will ONLY upcase characters 'valid' in the code page. There are MANY
 	// code pages which mssql WILL upcase the letter (in UCS-2), but there is no upper case value
 	// in the code page.  Thus we MUST keep the lower cased letter in this case.
-	utf8_uc(UC_Key, PLAINTEXT_LENGTH*3*3, (UTF8*)plain_key, strlen(plain_key));
+	enc_uc(UC_Key, PLAINTEXT_LENGTH*3*3, (UTF8*)plain_key, strlen(plain_key));
 	return (char*)UC_Key;
 }
 
@@ -277,13 +277,12 @@ static void * oracle_get_salt(char * ciphertext)
 	salt[l-2] = 0;
 
 	// we now upcase the user name in the prepare() function.
-	// So we are going back to 'simple' utf8->utf16 convert only.
-	l = plaintowcs(&out[1], 16, (UTF8 *)salt, l-2);
+	// So we are going back to 'simple' plain->utf16 convert only.
+	l = enc_to_utf16(&out[1], 16, (UTF8 *)salt, l-2);
 	if (l <= 0)
 		l = strlen16(&out[1]);
 
 	// This must be byte-swapped regardless of arch endianness
-	// We also uppercase here, currently only ASCII
 	for(i=1;i<=l;i++) {
 		out[i] = (out[i] << 8) | (out[i] >> 8);
 	}
diff --git a/src/rawMD5unicode_fmt_plug.c b/src/rawMD5unicode_fmt_plug.c
index 185458b..43e21e7 100644
--- a/src/rawMD5unicode_fmt_plug.c
+++ b/src/rawMD5unicode_fmt_plug.c
@@ -215,7 +215,7 @@ static void rawmd5_set_key_enc(char *_key, int index)
 #endif
 
 	outlen =
-	    plaintowcs(utf16key, PLAINTEXT_LENGTH / 2, key,
+	    enc_to_utf16(utf16key, PLAINTEXT_LENGTH / 2, key,
 	    utf8len) * sizeof(UTF16);
 	if (outlen <= 0) {
 		utf8len = -outlen;
@@ -271,7 +271,7 @@ static char *rawmd5_get_key(int index)
 	}
 #endif
 	key[outlen] = 0;
-	return (char *)utf16toplain(key);
+	return (char *)utf16_to_enc(key);
 }
 
 static int rawmd5_cmp_all(void *binary, int count)
diff --git a/src/sapG_fmt_plug.c b/src/sapG_fmt_plug.c
index 9466003..08e4146 100644
--- a/src/sapG_fmt_plug.c
+++ b/src/sapG_fmt_plug.c
@@ -141,8 +141,8 @@ static void sapcodvng_set_key(char *key, int index)
 		strnzcpy((char*)trPassword, key, PLAINTEXT_LENGTH + 1);
 	else { // convert from codepage -> Unicode -> UTF-8
 		UTF16 tmp16[PLAINTEXT_LENGTH + 1];
-		plaintowcs(tmp16, PLAINTEXT_LENGTH + 1, (UTF8*)key, PLAINTEXT_LENGTH);
-		utf16toutf8_r(trPassword, PLAINTEXT_LENGTH + 1, tmp16);
+		enc_to_utf16(tmp16, PLAINTEXT_LENGTH + 1, (UTF8*)key, PLAINTEXT_LENGTH);
+		utf16_to_utf8_r(trPassword, PLAINTEXT_LENGTH + 1, tmp16);
 	}
 	pwLen=strlen((char*)trPassword);
 }
diff --git a/src/status.c b/src/status.c
index deaee65..267cf37 100644
--- a/src/status.c
+++ b/src/status.c
@@ -442,8 +442,8 @@ static void status_print_cracking(char *percent)
 		UTF8 t2buf[PLAINTEXT_BUFFER_SIZE + 1];
 		char *t1, *t2;
 		if (options.report_utf8 && !options.utf8) {
-			t1 = (char*)enctoutf8_r(crk_get_key1(), t1buf);
-			t2 = (char*)enctoutf8_r(saved_key, t2buf);
+			t1 = (char*)enc_to_utf8_r(crk_get_key1(), t1buf);
+			t2 = (char*)enc_to_utf8_r(saved_key, t2buf);
 		} else {
 			t1 = crk_get_key1();
 			t2 = saved_key;
@@ -490,8 +490,8 @@ static void status_print_cracking(char *percent)
 		UTF8 t2buf[PLAINTEXT_BUFFER_SIZE + 1];
 		char *t1, *t2;
 		if (options.report_utf8 && !options.utf8) {
-			t1 = (char*)enctoutf8_r(crk_get_key1(), t1buf);
-			t2 = (char*)enctoutf8_r(saved_key, t2buf);
+			t1 = (char*)enc_to_utf8_r(crk_get_key1(), t1buf);
+			t2 = (char*)enc_to_utf8_r(saved_key, t2buf);
 		} else {
 			t1 = crk_get_key1();
 			t2 = saved_key;
diff --git a/src/unicode.c b/src/unicode.c
index 1d72193..a6d82a5 100644
--- a/src/unicode.c
+++ b/src/unicode.c
@@ -76,8 +76,8 @@
 #include "UnicodeData.h"
 #include "encoding_data.h"
 
-UTF16 utc2_upcase[0x10000];
-UTF16 utc2_downcase[0x10000];
+UTF16 ucs2_upcase[0x10000];
+UTF16 ucs2_downcase[0x10000];
 
 /* 
  * These are used to convert from an encoding, into unicode.  iso-8859-1 is trivial 
@@ -195,7 +195,7 @@ static const UTF32 halfMask = 0x3FFUL;
 // instead, so we can truncate our saved_plain or whatever accordingly.
 //
 // The original function in ConvertUTF.c is called ConvertUTF8toUTF16()
-inline int utf8towcs(UTF16 * target, unsigned int len, const UTF8 * source,
+inline int utf8_to_utf16(UTF16 * target, unsigned int len, const UTF8 * source,
                      unsigned int sourceLen)
 {
 	const UTF16 *targetStart = target;
@@ -304,7 +304,7 @@ inline int utf8towcs(UTF16 * target, unsigned int len, const UTF8 * source,
 //NOTE, Solaris did not build properly with this function inlined. Thus
 // the inline was removed (for now).
 //inline
-int plaintowcs(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src,
+int enc_to_utf16(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src,
                       unsigned int srclen)
 {
 	if (!(options.utf8)) {
@@ -327,7 +327,7 @@ int plaintowcs(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src,
 		else
 			return i;
 	} else {		// Convert from UTF-8
-		return utf8towcs(dst, maxdstlen, src, srclen);
+		return utf8_to_utf16(dst, maxdstlen, src, srclen);
 	}
 }
 
@@ -366,7 +366,7 @@ int E_md4hash(const UTF8 * passwd, unsigned int len, unsigned char *p16)
 		static MD4_CTX ctx;
 
 		/* Password is converted to UTF-16LE */
-		trunclen = plaintowcs(wpwd, PLAINTEXT_BUFFER_SIZE, passwd, len);
+		trunclen = enc_to_utf16(wpwd, PLAINTEXT_BUFFER_SIZE, passwd, len);
 		if(trunclen < 0)
 			len = strlen16(wpwd); // From UTF-8 you can't know
 		else
@@ -386,7 +386,7 @@ int E_md4hash(const UTF8 * passwd, unsigned int len, unsigned char *p16)
 		unsigned int i = 0, md4_size = 0;
 
 		/* Password is converted to UTF-16LE */
-		trunclen = plaintowcs(wpwd, 27, passwd, len);
+		trunclen = enc_to_utf16(wpwd, 27, passwd, len);
 		// We need to check this because it's not just a matter of truncating
 		// length, it can be malformed UTF-8
 		if (trunclen < 0)
@@ -484,13 +484,13 @@ int E_md4hash(const UTF8 * passwd, unsigned int len, unsigned char *p16)
 // Convert UTF-16LE to UTF-8. This is not optimised as it's
 // only used in get_key() as of now.
 // Non thread-safe version
-UTF8 * utf16toutf8 (const UTF16* source) {
+UTF8 * utf16_to_utf8 (const UTF16* source) {
 	static UTF8 ret_Key[PLAINTEXT_BUFFER_SIZE + 1];
-	return utf16toutf8_r(ret_Key, PLAINTEXT_BUFFER_SIZE, source);
+	return utf16_to_utf8_r(ret_Key, PLAINTEXT_BUFFER_SIZE, source);
 }
 
 // Thread-safe version
-UTF8 * utf16toutf8_r (UTF8 *dst, int dst_len, const UTF16* source) {
+UTF8 * utf16_to_utf8_r (UTF8 *dst, int dst_len, const UTF16* source) {
 	UTF8 *tpt = dst;
 	UTF8 *targetEnd = tpt + dst_len;
 	while (*source) {
@@ -548,37 +548,37 @@ UTF8 * utf16toutf8_r (UTF8 *dst, int dst_len, const UTF16* source) {
 }
 
 /* Thread-safe conversion from codepage to UTF-8 */
-UTF8 * enctoutf8_r (char *src, UTF8* dst)
+UTF8 * enc_to_utf8_r (char *src, UTF8* dst)
 {
 	UTF16 tmp16[PLAINTEXT_BUFFER_SIZE + 1];
-	plaintowcs(tmp16, PLAINTEXT_BUFFER_SIZE, (unsigned char*)src,
+	enc_to_utf16(tmp16, PLAINTEXT_BUFFER_SIZE, (unsigned char*)src,
 	           PLAINTEXT_BUFFER_SIZE);
-	dst = utf16toutf8_r(dst, PLAINTEXT_BUFFER_SIZE, tmp16);
+	dst = utf16_to_utf8_r(dst, PLAINTEXT_BUFFER_SIZE, tmp16);
 	return dst;
 }
 
 /* Thread-safe conversion from UTF-8 to codepage */
-char * utf8toenc_r (UTF8 *src, char* dst)
+char * utf8_to_enc_r (UTF8 *src, char* dst)
 {
 	UTF16 tmp16[PLAINTEXT_BUFFER_SIZE + 1];
-	utf8towcs(tmp16, PLAINTEXT_BUFFER_SIZE, (unsigned char*)src,
+	utf8_to_utf16(tmp16, PLAINTEXT_BUFFER_SIZE, (unsigned char*)src,
 	           PLAINTEXT_BUFFER_SIZE);
-	dst = (char*)utf16toplain_r((UTF8*)dst, PLAINTEXT_BUFFER_SIZE, tmp16);
+	dst = (char*)utf16_to_plain_r((UTF8*)dst, PLAINTEXT_BUFFER_SIZE, tmp16);
 	return dst;
 }
 
 // Convert UTF-16LE to UTF-8 or ISO-8859-1 depending on --encoding=utf8 flag.
 // This is not optimised as it's only used in get_key() as of now.
 // Non thread-safe version
-UTF8 * utf16toplain (const UTF16* source) {
+UTF8 * utf16_to_enc (const UTF16* source) {
 	static UTF8 ret_Key[PLAINTEXT_BUFFER_SIZE + 1];
-	return utf16toplain_r(ret_Key, PLAINTEXT_BUFFER_SIZE, source);
+	return utf16_to_plain_r(ret_Key, PLAINTEXT_BUFFER_SIZE, source);
 }
 
 // Thread-safe version
-UTF8 * utf16toplain_r (UTF8 *dst, int dst_len, const UTF16* source) {
+UTF8 * utf16_to_plain_r (UTF8 *dst, int dst_len, const UTF16* source) {
 	if (options.utf8)
-		return utf16toutf8_r(dst, dst_len, source);
+		return utf16_to_utf8_r(dst, dst_len, source);
 	else {
 		UTF8 *tgt = dst;
 		UTF8 *targetEnd = tgt + dst_len;
@@ -601,8 +601,8 @@ int initUnicode(int type) {
 
 	UnicodeType = type;
 
-	memset(utc2_upcase, 0, sizeof(utc2_upcase));
-	memset(utc2_downcase, 0, sizeof(utc2_downcase));
+	memset(ucs2_upcase, 0, sizeof(ucs2_upcase));
+	memset(ucs2_downcase, 0, sizeof(ucs2_downcase));
 
 	// If we are handling MSSQL format (the old upper case, then we MUST use arTo[UL]CDat_WinXP arrays, 
 	// and NOTE use the multi-char stuff.
@@ -614,30 +614,30 @@ int initUnicode(int type) {
 	// This is still TBD on how best to do it.
 	if (type==UNICODE_MS_OLD) {
 		for (i = 0; arToUCDat_WinXP[i]; i += 2)
-			utc2_upcase[arToUCDat_WinXP[i]] = arToUCDat_WinXP[i+1];
+			ucs2_upcase[arToUCDat_WinXP[i]] = arToUCDat_WinXP[i+1];
 		for (i = 0; arToLCDat_WinXP[i]; i += 2)
-			utc2_downcase[arToLCDat_WinXP[i]] = arToLCDat_WinXP[i+1];
+			ucs2_downcase[arToLCDat_WinXP[i]] = arToLCDat_WinXP[i+1];
 
 		// Required for cp737, MSSQL_old
-		utc2_upcase[0x03C2] = 0x03C2; //U+03C2 -> U+03A3 was not cased
-		utc2_downcase[0x03A3] = 0x03A3; //U+03A3 -> U+03C2  was not cased
+		ucs2_upcase[0x03C2] = 0x03C2; //U+03C2 -> U+03A3 was not cased
+		ucs2_downcase[0x03A3] = 0x03A3; //U+03A3 -> U+03C2  was not cased
 	} else if (type==UNICODE_MS_NEW) {
 		for (i = 0; arToUCDat_WinVista[i]; i += 2)
-			utc2_upcase[arToUCDat_WinVista[i]] = arToUCDat_WinVista[i+1];
+			ucs2_upcase[arToUCDat_WinVista[i]] = arToUCDat_WinVista[i+1];
 		for (i = 0; arToLCDat_WinVista[i]; i += 2)
-			utc2_downcase[arToLCDat_WinVista[i]] = arToLCDat_WinVista[i+1];
+			ucs2_downcase[arToLCDat_WinVista[i]] = arToLCDat_WinVista[i+1];
 	} else {
 		for (i = 0; arToUCDat_UCData_txt[i]; i += 2)
-			utc2_upcase[arToUCDat_UCData_txt[i]] = arToUCDat_UCData_txt[i+1];
+			ucs2_upcase[arToUCDat_UCData_txt[i]] = arToUCDat_UCData_txt[i+1];
 		for (i = 0; arToLCDat_UCData_txt[i]; i += 2)
-			utc2_downcase[arToLCDat_UCData_txt[i]] = arToLCDat_UCData_txt[i+1];
+			ucs2_downcase[arToLCDat_UCData_txt[i]] = arToLCDat_UCData_txt[i+1];
 
 		// set a 1 for any 'multi-char' converts.
 		for (i = 0; uniMultiCase[i].Val; ++i)
 			if (uniMultiCase[i].bIsUp2Low)
-				utc2_downcase[uniMultiCase[i].Val] = 1;
+				ucs2_downcase[uniMultiCase[i].Val] = 1;
 			else
-				utc2_upcase[uniMultiCase[i].Val] = 1;
+				ucs2_upcase[uniMultiCase[i].Val] = 1;
 	}
 
 	// Here we setup the 8-bit codepages we handle, and setup the mapping values into Unicode.
@@ -741,44 +741,46 @@ int initUnicode(int type) {
 	}
 	if (type==UNICODE_MS_OLD && options.cp737) {
 		// Required for cp737, MSSQL_old
-		//utc2_upcase[0x03C2] = 0x03C2; //U+03C2 -> U+03A3 was not cased
+		//ucs2_upcase[0x03C2] = 0x03C2; //U+03C2 -> U+03A3 was not cased
 		CP_up[0xAA] = 0xAA;
 		CP_down[0x91] = 0x91;
 	}
 
+	// CP_isSeparator[c] will return true if c is a separator
 	memset(CP_isSeparator, 0, sizeof(CP_isSeparator));
 
 	// Original separator list from loader.c
-#define issep \
+#define CP_issep \
 	"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\177"
 
 	if (options.koi8_r)
-		encTemp = issep CHARS_PUNCTUATION_KOI8_R CHARS_SPECIALS_KOI8_R CHARS_WHITESPACE_KOI8_R CHARS_CONTROL_KOI8_R CHARS_INVALID_KOI8_R;
+		encTemp = CP_issep CHARS_PUNCTUATION_KOI8_R CHARS_SPECIALS_KOI8_R CHARS_WHITESPACE_KOI8_R CHARS_CONTROL_KOI8_R CHARS_INVALID_KOI8_R;
 	else if (options.cp1251)
-		encTemp = issep CHARS_PUNCTUATION_CP1251 CHARS_SPECIALS_CP1251 CHARS_WHITESPACE_CP1251 CHARS_CONTROL_CP1251 CHARS_INVALID_CP1251;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP1251 CHARS_SPECIALS_CP1251 CHARS_WHITESPACE_CP1251 CHARS_CONTROL_CP1251 CHARS_INVALID_CP1251;
 	else if (options.cp866)
-		encTemp = issep CHARS_PUNCTUATION_CP866 CHARS_SPECIALS_CP866 CHARS_WHITESPACE_CP866 CHARS_CONTROL_CP866 CHARS_INVALID_CP866;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP866 CHARS_SPECIALS_CP866 CHARS_WHITESPACE_CP866 CHARS_CONTROL_CP866 CHARS_INVALID_CP866;
 	else if (options.cp1252)
-		encTemp = issep CHARS_PUNCTUATION_CP1252 CHARS_SPECIALS_CP1252 CHARS_WHITESPACE_CP1252 CHARS_CONTROL_CP1252 CHARS_INVALID_CP1252;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP1252 CHARS_SPECIALS_CP1252 CHARS_WHITESPACE_CP1252 CHARS_CONTROL_CP1252 CHARS_INVALID_CP1252;
 	else if (options.iso8859_15)
-		encTemp = issep CHARS_PUNCTUATION_ISO_8859_15 CHARS_SPECIALS_ISO_8859_15 CHARS_WHITESPACE_ISO_8859_15 CHARS_CONTROL_ISO_8859_15 CHARS_INVALID_ISO_8859_15;
+		encTemp = CP_issep CHARS_PUNCTUATION_ISO_8859_15 CHARS_SPECIALS_ISO_8859_15 CHARS_WHITESPACE_ISO_8859_15 CHARS_CONTROL_ISO_8859_15 CHARS_INVALID_ISO_8859_15;
 	else if (options.cp437)
-		encTemp = issep CHARS_PUNCTUATION_CP437 CHARS_SPECIALS_CP437 CHARS_WHITESPACE_CP437 CHARS_CONTROL_CP437 CHARS_INVALID_CP437;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP437 CHARS_SPECIALS_CP437 CHARS_WHITESPACE_CP437 CHARS_CONTROL_CP437 CHARS_INVALID_CP437;
 	else if (options.cp850)
-		encTemp = issep CHARS_PUNCTUATION_CP850 CHARS_SPECIALS_CP850 CHARS_WHITESPACE_CP850 CHARS_CONTROL_CP850 CHARS_INVALID_CP850;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP850 CHARS_SPECIALS_CP850 CHARS_WHITESPACE_CP850 CHARS_CONTROL_CP850 CHARS_INVALID_CP850;
 	else if (options.cp858)
-		encTemp = issep CHARS_PUNCTUATION_CP858 CHARS_SPECIALS_CP858 CHARS_WHITESPACE_CP858 CHARS_CONTROL_CP858 CHARS_INVALID_CP858;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP858 CHARS_SPECIALS_CP858 CHARS_WHITESPACE_CP858 CHARS_CONTROL_CP858 CHARS_INVALID_CP858;
 	else if (options.cp737)
-		encTemp = issep CHARS_PUNCTUATION_CP737 CHARS_SPECIALS_CP737 CHARS_WHITESPACE_CP737 CHARS_CONTROL_CP737 CHARS_INVALID_CP737;
+		encTemp = CP_issep CHARS_PUNCTUATION_CP737 CHARS_SPECIALS_CP737 CHARS_WHITESPACE_CP737 CHARS_CONTROL_CP737 CHARS_INVALID_CP737;
 	else if (options.iso8859_1)
-		encTemp = issep CHARS_PUNCTUATION_ISO_8859_1 CHARS_SPECIALS_ISO_8859_1 CHARS_WHITESPACE_ISO_8859_1 CHARS_CONTROL_ISO_8859_1 CHARS_INVALID_ISO_8859_1;
+		encTemp = CP_issep CHARS_PUNCTUATION_ISO_8859_1 CHARS_SPECIALS_ISO_8859_1 CHARS_WHITESPACE_ISO_8859_1 CHARS_CONTROL_ISO_8859_1 CHARS_INVALID_ISO_8859_1;
 	else  // old-style ASCII-only
-		encTemp = issep;
+		encTemp = CP_issep;
 
 	memset(CP_isSeparator, 1, 33);
 	for (pos = encTemp; *pos; pos++)
 		CP_isSeparator[ARCH_INDEX(*pos)] = 1;
 
+	// CP_isLetter[c] will return true if c is a letter
 	memset(CP_isLetter, 0, sizeof(CP_isLetter));
 
 	if (options.koi8_r)
@@ -816,21 +818,23 @@ int initUnicode(int type) {
 
 /* single char conversion inlines. Inlines vs macros, so that we get type 'safety'           */
 /* NOTE these functions do NOT return multi UTF16 conversion characters, so they are         */
-/* only 'partly' proper.  The plaintowcs_uc() and  plaintowcs_lc() do full conversions as    */
+/* only 'partly' proper.  The plain_to_utf16_uc() and  plain_to_utf16_lc() do full conversions as    */
 /* does the utf16_lc() and utf16_uc().  Full conversion uses the utc_*case[] arrays, but  it */
 /* also uses the 1 UTC2 to multi UTC2 lookup table to do things 'properly'.                  */
-//_inline unsigned char low2up_ascii(unsigned char c) {if (utc2_upcase[c]) {return utc2_upcase[c]; return c; }
-//_inline unsigned char up2low_ascii(unsigned char c) {if (utc2_downcase[c]) return utc2_downcase[c]; return c; }
-//_inline UTF16 low2up_u16(UTF16 w) {if (utc2_upcase[w]) return utc2_upcase[w]; return w; }
-//_inline UTF16 up2low_u16(UTF16 w) {if (utc2_downcase[w]) return utc2_downcase[w]; return w; }
+//_inline unsigned char low2up_ansi(unsigned char c) {if (ucs2_upcase[c]) {return ucs2_upcase[c]; return c; }
+//_inline unsigned char up2low_ansi(unsigned char c) {if (ucs2_downcase[c]) return ucs2_downcase[c]; return c; }
+//_inline UTF16 low2up_u16(UTF16 w) {if (ucs2_upcase[w]) return ucs2_upcase[w]; return w; }
+//_inline UTF16 up2low_u16(UTF16 w) {if (ucs2_downcase[w]) return ucs2_downcase[w]; return w; }
 
 /* Convert to UTF-16LE from UTF-8 or ISO-8859-1 depending on --encoding=utf8 flag, and upcase/lowcase at same time */
-//int plaintowcs_uc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen) {
+//int plain_to_utf16_uc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen) {
 //	return 0;
 //}
-//int plaintowcs_lc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen) {
+//int plain_to_utf16_lc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen) {
 //	return 0;
 //}
+
+// Lowercase UTF-16
 int utf16_lc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len) {
 	int i, j = 0;
 	UTF16 cur_src;
@@ -840,11 +844,11 @@ int utf16_lc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len) {
 			return -j;
 		}
 		cur_src = BE_FIX(*src);
-		if (utc2_downcase[ cur_src ] == 0)
+		if (ucs2_downcase[ cur_src ] == 0)
 			*dst = cur_src;
 		else {
-			if (utc2_downcase[ cur_src ] & 0xFFFE) {
-				*dst = utc2_downcase[ cur_src ];
+			if (ucs2_downcase[ cur_src ] & 0xFFFE) {
+				*dst = ucs2_downcase[ cur_src ];
 			}
 			else {
 				// multi-byte.
@@ -869,6 +873,7 @@ int utf16_lc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len) {
 	return j;
 }
 
+// Uppercase UTF-16
 int utf16_uc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len) {
 	int i, j = 0;
 	UTF16 cur_src;
@@ -878,11 +883,11 @@ int utf16_uc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len) {
 			return -j;
 		}
 		cur_src = BE_FIX(*src);
-		if (utc2_upcase[ cur_src ] == 0)
+		if (ucs2_upcase[ cur_src ] == 0)
 			*dst = cur_src;
 		else {
-			if (utc2_upcase[ cur_src ] & 0xFFFE) {
-				*dst = utc2_upcase[ cur_src ];
+			if (ucs2_upcase[ cur_src ] & 0xFFFE) {
+				*dst = ucs2_upcase[ cur_src ];
 			}
 			else {
 				// multi-byte.
@@ -907,7 +912,8 @@ int utf16_uc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len) {
 	return j;
 }
 
-int utf8_lc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len) {
+// Lowercase UTF-8 or codepage encoding
+int enc_lc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len) {
 	UTF16 tmp16[512+1], tmp16l[512+1]; // yes, short, but this is 'long enough' for john.
 	int utf16len, i;
 
@@ -920,13 +926,13 @@ int utf8_lc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len) {
 		*dst = 0;
 		return src_len;
 	}
-	utf16len = utf8towcs(tmp16, 512, src, src_len);
+	utf16len = utf8_to_utf16(tmp16, 512, src, src_len);
 	if (utf16len <= 0)
 		goto lcFallback;
 	utf16len = utf16_lc(tmp16l, 512, tmp16, utf16len);
 	if (utf16len <= 0)
 		goto lcFallback;
-	utf16toplain_r(dst, dst_len, tmp16l);
+	utf16_to_plain_r(dst, dst_len, tmp16l);
 	return strlen((char*)dst);
 
 	// Limp-home mode: If we failed doing the right thing (garbage data) we
@@ -943,7 +949,8 @@ lcFallback:
 	return src_len;
 }
 
-int utf8_uc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len) {
+// Uppercase UTF-8 or codepage encoding
+int enc_uc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len) {
 	UTF16 tmp16[512+1], tmp16u[512+1]; // yes, short, but this is 'long enough' for john.
 	int utf16len, i;
 
@@ -977,13 +984,13 @@ int utf8_uc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len) {
 		*dst = 0;
 		return len;
 	}
-	utf16len = utf8towcs(tmp16, 512, src, src_len);
+	utf16len = utf8_to_utf16(tmp16, 512, src, src_len);
 	if (utf16len <= 0)
 		goto ucFallback;
 	utf16len = utf16_uc(tmp16u, 512, tmp16, utf16len);
 	if (utf16len <= 0)
 		goto ucFallback;
-	utf16toplain_r(dst, dst_len, tmp16u);
+	utf16_to_plain_r(dst, dst_len, tmp16u);
 	return strlen((char*)dst);
 
 	// Limp-home mode: If we failed doing the right thing (garbage data) we
@@ -1005,7 +1012,7 @@ char *enc_strlwr(char *s)
 {
 	unsigned char *ptr = (unsigned char *)s;
 	int srclen = strlen(s);
-	utf8_lc(ptr, srclen + 1, ptr, srclen);
+	enc_lc(ptr, srclen + 1, ptr, srclen);
 	return s;
 }
 
@@ -1014,6 +1021,6 @@ char *enc_strupper(char *s)
 {
 	unsigned char *ptr = (unsigned char *)s;
 	int srclen = strlen(s);
-	utf8_uc(ptr, srclen + 1, ptr, srclen);
+	enc_uc(ptr, srclen + 1, ptr, srclen);
 	return s;
 }
diff --git a/src/unicode.h b/src/unicode.h
index 44eeabe..bf26d22 100644
--- a/src/unicode.h
+++ b/src/unicode.h
@@ -64,27 +64,27 @@ extern const UTF32 offsetsFromUTF8[];
 extern const char opt_trailingBytesUTF8[64];
 
 /* Convert UTF-8 to UTF-16LE */
-extern int utf8towcs(UTF16 * target, unsigned int maxtargetlen,
+extern int utf8_to_utf16(UTF16 * target, unsigned int maxtargetlen,
     const UTF8 * source, unsigned int sourcelen);
 
 /* Convert to UTF-16LE from UTF-8 or ISO-8859-1 (or any other 'valid' code page encoding) depending on --encoding=utf8 (or other) flag */
-extern int plaintowcs(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src,
+extern int enc_to_utf16(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src,
     unsigned int srclen);
 
 /* Thread-safe conversion from codepage to UTF-8 */
-UTF8 * enctoutf8_r (char *src, UTF8* dst);
+UTF8 * enc_to_utf8_r (char *src, UTF8* dst);
 
 /* Thread-safe conversion from UTF-8 to codepage */
-char * utf8toenc_r (UTF8 *src, char* dst);
+char * utf8_to_enc_r (UTF8 *src, char* dst);
 
 /* Convert back to UTF-8 (for get_key without a saved_plain) */
-extern UTF8 * utf16toutf8 (const UTF16* source);
-extern UTF8 * utf16toutf8_r (UTF8 *dst, int dst_len, const UTF16* source);
+extern UTF8 * utf16_to_utf8 (const UTF16* source);
+extern UTF8 * utf16_to_utf8_r (UTF8 *dst, int dst_len, const UTF16* source);
 
 /* Convert back to UTF-8 or ISO-8859-1 depending on --encoding= flag
  * (for get_key without a saved_plain) */
-extern UTF8 * utf16toplain (const UTF16* source);
-extern UTF8 * utf16toplain_r (UTF8 *dst, int dst_len, const UTF16* source);
+extern UTF8 * utf16_to_enc (const UTF16* source);
+extern UTF8 * utf16_to_plain_r (UTF8 *dst, int dst_len, const UTF16* source);
 
 /* These were in smbencrypt.c before: */
 
@@ -101,32 +101,40 @@ extern int E_md4hash(const UTF8 * passwd, unsigned int len, unsigned char *p16);
 #define UNICODE_UNICODE	3
 
 extern int initUnicode(int type);
-extern UTF16 utc2_upcase[0x10000];   /* NOTE, for multi-char converts, we put a 1 into these */
-extern UTF16 utc2_downcase[0x10000]; /* array. The 1 is not valid, just an indicator to check the multi-char */
+extern UTF16 ucs2_upcase[0x10000];   /* NOTE, for multi-char converts, we put a 1 into these */
+extern UTF16 ucs2_downcase[0x10000]; /* array. The 1 is not valid, just an indicator to check the multi-char */
 
 /* single char conversion inlines. Inlines vs macros, so that we get type 'safety'           */
 /* NOTE these functions do NOT return multi UTF16 conversion characters, so they are         */
-/* only 'partly' proper.  The plaintowcs_uc() and  plaintowcs_lc() do full conversions as    */
+/* only 'partly' proper.  The plain_to_utf16_uc() and  plain_to_utf16_lc() do full conversions as    */
 /* does the utf16_lc() and utf16_uc().  Full conversion uses the utc_*case[] arrays, but  it */
 /* also uses the 1 UTC2 to multi UTC2 lookup table to do things 'properly'.                  */
-/* NOTE low2up_ascii() does not handle 0xDF to "SS" conversion, since it is 1 to many.       */
-static inline unsigned char low2up_ascii(unsigned char c) {if ((utc2_upcase[c]&0xFFFE)&&utc2_upcase[c]<0x100) return (unsigned char)utc2_upcase[c]; return c; }
-static inline unsigned char up2low_ascii(unsigned char c) {if ((utc2_downcase[c]&0xFFFE)&&utc2_downcase[c]<0x100) return (unsigned char)utc2_downcase[c]; return c; }
-static inline UTF16 low2up_u16(UTF16 w) {if (utc2_upcase[w]&0xFFFE) return utc2_upcase[w]; return w; }
-static inline UTF16 up2low_u16(UTF16 w) {if (utc2_downcase[w]&0xFFFE) return utc2_downcase[w]; return w; }
+/* NOTE low2up_ansi() does not handle 0xDF to "SS" conversion, since it is 1 to many.       */
+static inline unsigned char low2up_ansi(unsigned char c) {if ((ucs2_upcase[c]&0xFFFE)&&ucs2_upcase[c]<0x100) return (unsigned char)ucs2_upcase[c]; return c; }
+static inline unsigned char up2low_ansi(unsigned char c) {if ((ucs2_downcase[c]&0xFFFE)&&ucs2_downcase[c]<0x100) return (unsigned char)ucs2_downcase[c]; return c; }
+static inline UTF16 low2up_u16(UTF16 w) {if (ucs2_upcase[w]&0xFFFE) return ucs2_upcase[w]; return w; }
+static inline UTF16 up2low_u16(UTF16 w) {if (ucs2_downcase[w]&0xFFFE) return ucs2_downcase[w]; return w; }
 
 /* Convert to UTF-16LE from UTF-8 or ISO-8859-1 depending on --encoding= flag, and upcase/lowcase at same time */
-//extern int plaintowcs_uc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen);
-//extern int plaintowcs_lc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen);
+//extern int plain_to_utf16_uc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen);
+//extern int plain_to_utf16_lc(UTF16 * dst, unsigned int maxdstlen, const UTF8 * src, unsigned int srclen);
+
+// Lowercase UTF-16 string
 extern int utf16_lc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len);
+
+// Uppercase UTF-16 string
 extern int utf16_uc(UTF16 *dst, unsigned dst_len, const UTF16 *src, unsigned src_len);
-extern int utf8_lc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len);
-extern int utf8_uc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len);
 
-// Encoding-aware strlwr() (in-place lowercase)
+// Lowercase UTF-8 or codepage string
+extern int enc_lc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len);
+
+// Uppercase UTF-8 or codepage string
+extern int enc_uc(UTF8 *dst, unsigned dst_len, const UTF8 *src, unsigned src_len);
+
+// Encoding-aware strlwr(): in-place lowercase of string
 extern char *enc_strlwr(char *s);
 
-// Encoding-aware in-place uppercase
+// Encoding-aware in-place uppercase of string
 extern char *enc_strupper(char *s);
 
 // Used by NT's inline set_key_helper_encoding()
-- 
1.7.4.1

