Code Refactor - Whitespace Refactor

This commit is contained in:
Xephi
2014-08-08 23:14:56 +02:00
parent ec7ac60340
commit afc1ea9111
114 changed files with 8277 additions and 7103 deletions
File diff suppressed because it is too large Load Diff
@@ -7,12 +7,14 @@ import java.security.NoSuchAlgorithmException;
public class CRAZYCRYPT1 implements EncryptionMethod {
protected final Charset charset = Charset.forName("UTF-8");
private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name
+ "__+IÄIH§%NK " + password;
try {
final MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(text.getBytes(charset), 0, text.length());
@@ -27,7 +29,7 @@ public class CRAZYCRYPT1 implements EncryptionMethod {
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
public static String byteArrayToHexString(final byte... args) {
final char[] chars = new char[args.length * 2];
for (int i = 0; i < args.length; i++) {
@@ -36,4 +38,4 @@ public class CRAZYCRYPT1 implements EncryptionMethod {
}
return new String(chars);
}
}
}
@@ -5,28 +5,29 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.security.pbkdf2.PBKDF2Engine;
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
public class CryptPBKDF2 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String result = "pbkdf2_sha256$10000$"+salt+"$";
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000);
PBKDF2Engine engine = new PBKDF2Engine(params);
return result + engine.deriveKey(password,64).toString();
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String result = "pbkdf2_sha256$10000$" + salt + "$";
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII",
salt.getBytes(), 10000);
PBKDF2Engine engine = new PBKDF2Engine(params);
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
String salt = line[2];
String derivedKey = line[3];
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000, derivedKey.getBytes());
PBKDF2Engine engine = new PBKDF2Engine(params);
return engine.verifyKey(password);
}
return result + engine.deriveKey(password, 64).toString();
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
String salt = line[2];
String derivedKey = line[3];
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII",
salt.getBytes(), 10000, derivedKey.getBytes());
PBKDF2Engine engine = new PBKDF2Engine(params);
return engine.verifyKey(password);
}
}
@@ -6,24 +6,26 @@ import java.security.NoSuchAlgorithmException;
public class DOUBLEMD5 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password));
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -3,28 +3,38 @@ package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
/**
* <p>Public interface for Custom Password encryption method</p>
* <p>The getHash function is called when we need to crypt the password (/register usually)</p>
* <p>The comparePassword is called when we need to match password (/login usually)</p>
* <p>
* Public interface for Custom Password encryption method
* </p>
* <p>
* The getHash function is called when we need to crypt the password (/register
* usually)
* </p>
* <p>
* The comparePassword is called when we need to match password (/login usually)
* </p>
*/
public interface EncryptionMethod {
/**
* @param password
* @param salt (can be an other data like playerName;salt , playerName, etc...
* for customs methods)
* @return Hashing password
* @throws NoSuchAlgorithmException
*/
String getHash(String password, String salt, String name) throws NoSuchAlgorithmException;
/**
* @param password
* @param salt
* (can be an other data like playerName;salt , playerName,
* etc... for customs methods)
* @return Hashing password
* @throws NoSuchAlgorithmException
*/
String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException;
/**
* @param hash
* @param password
* @param playerName
* @return true if password match, false else
* @throws NoSuchAlgorithmException
*/
boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException;
/**
* @param hash
* @param password
* @param playerName
* @return true if password match, false else
* @throws NoSuchAlgorithmException
*/
boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException;
}
@@ -6,27 +6,29 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
public class IPB3 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt) + getMD5(password));
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt) + getMD5(password));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, playerName));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash.equals(getHash(password, salt, playerName));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,24 +6,26 @@ import java.security.NoSuchAlgorithmException;
public class JOOMLA implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(password + salt) + ":" + salt;
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(password + salt) + ":" + salt;
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = hash.split(":")[1];
return hash.equals(getMD5(password + salt) + ":" + salt);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = hash.split(":")[1];
return hash.equals(getMD5(password + salt) + ":" + salt);
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,21 +6,25 @@ import java.security.NoSuchAlgorithmException;
public class MD5 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(password);
}
}
@Override
public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,25 +6,27 @@ import java.security.NoSuchAlgorithmException;
public class MD5VB implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
return hash.equals(getHash(password, line[2], ""));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
}
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,27 +6,29 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
public class MYBB implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt)+ getMD5(password));
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(salt) + getMD5(password));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, playerName));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash.equals(getHash(password, salt, playerName));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -1,6 +1,6 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package fr.xephi.authme.security.crypts;
@@ -14,151 +14,138 @@ import java.security.NoSuchAlgorithmException;
* @author stefano
*/
public class PHPBB implements EncryptionMethod {
private static final int PHP_VERSION = 4;
private String itoa64 =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static final int PHP_VERSION = 4;
private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public String phpbb_hash(String password, String salt) {
String random_state = salt;
String random = "";
int count = 6;
if (random.length() < count) {
random = "";
for (int i = 0; i < count; i += 16) {
random_state = md5(salt + random_state);
random += pack(md5(random_state));
}
random = random.substring(0, count);
public String phpbb_hash(String password, String salt) {
String random_state = salt;
String random = "";
int count = 6;
if (random.length() < count) {
random = "";
for (int i = 0; i < count; i += 16) {
random_state = md5(salt + random_state);
random += pack(md5(random_state));
}
random = random.substring(0, count);
}
String hash = _hash_crypt_private(password,
_hash_gensalt_private(random, itoa64));
if (hash.length() == 34) return hash;
return md5(password);
}
String hash = _hash_crypt_private(
password, _hash_gensalt_private(random, itoa64));
if (hash.length() == 34)
return hash;
return md5(password);
}
private String _hash_gensalt_private(String input, String itoa64) {
return _hash_gensalt_private(input, itoa64, 6);
}
@SuppressWarnings("unused")
private String _hash_gensalt_private(
String input, String itoa64, int iteration_count_log2) {
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
iteration_count_log2 = 8;
private String _hash_gensalt_private(String input, String itoa64) {
return _hash_gensalt_private(input, itoa64, 6);
}
String output = "$H$";
output += itoa64.charAt(
Math.min(iteration_count_log2 +
((PHP_VERSION >= 5) ? 5 : 3), 30));
output += _hash_encode64(input, 6);
return output;
}
/**
* Encode hash
*/
private String _hash_encode64(String input, int count) {
String output = "";
int i = 0;
do {
int value = input.charAt(i++);
output += itoa64.charAt(value & 0x3f);
if (i < count)
value |= input.charAt(i) << 8;
output += itoa64.charAt((value >> 6) & 0x3f);
if (i++ >= count)
break;
if (i < count)
value |= input.charAt(i) << 16;
output += itoa64.charAt((value >> 12) & 0x3f);
if (i++ >= count)
break;
output += itoa64.charAt((value >> 18) & 0x3f);
} while (i < count);
return output;
}
String _hash_crypt_private(String password, String setting) {
String output = "*";
if (!setting.substring(0, 3).equals("$H$"))
@SuppressWarnings("unused")
private String _hash_gensalt_private(String input, String itoa64,
int iteration_count_log2) {
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
iteration_count_log2 = 8;
}
String output = "$H$";
output += itoa64.charAt(Math.min(iteration_count_log2
+ ((PHP_VERSION >= 5) ? 5 : 3), 30));
output += _hash_encode64(input, 6);
return output;
int count_log2 = itoa64.indexOf(setting.charAt(3));
if (count_log2 < 7 || count_log2 > 30)
}
/**
* Encode hash
*/
private String _hash_encode64(String input, int count) {
String output = "";
int i = 0;
do {
int value = input.charAt(i++);
output += itoa64.charAt(value & 0x3f);
if (i < count) value |= input.charAt(i) << 8;
output += itoa64.charAt((value >> 6) & 0x3f);
if (i++ >= count) break;
if (i < count) value |= input.charAt(i) << 16;
output += itoa64.charAt((value >> 12) & 0x3f);
if (i++ >= count) break;
output += itoa64.charAt((value >> 18) & 0x3f);
} while (i < count);
return output;
int count = 1 << count_log2;
String salt = setting.substring(4, 12);
if (salt.length() != 8)
}
String _hash_crypt_private(String password, String setting) {
String output = "*";
if (!setting.substring(0, 3).equals("$H$")) return output;
int count_log2 = itoa64.indexOf(setting.charAt(3));
if (count_log2 < 7 || count_log2 > 30) return output;
int count = 1 << count_log2;
String salt = setting.substring(4, 12);
if (salt.length() != 8) return output;
String m1 = md5(salt + password);
String hash = pack(m1);
do {
hash = pack(md5(hash + password));
} while (--count > 0);
output = setting.substring(0, 12);
output += _hash_encode64(hash, 16);
return output;
String m1 = md5(salt + password);
String hash = pack(m1);
do {
hash = pack(md5(hash + password));
} while (--count > 0);
output = setting.substring(0, 12);
output += _hash_encode64(hash, 16);
return output;
}
public boolean phpbb_check_hash( String password, String hash) {
if (hash.length() == 34)
return _hash_crypt_private(password, hash).equals(hash);
else
return md5(password).equals(hash);
}
public static String md5(String data) {
try {
byte[] bytes = data.getBytes("ISO-8859-1");
MessageDigest md5er = MessageDigest.getInstance("MD5");
byte[] hash = md5er.digest(bytes);
return bytes2hex(hash);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
static int hexToInt(char ch) {
if(ch >= '0' && ch <= '9')
return ch - '0';
ch = Character.toUpperCase(ch);
if(ch >= 'A' && ch <= 'F')
return ch - 'A' + 0xA;
throw new IllegalArgumentException("Not a hex character: " + ch);
}
private static String bytes2hex(byte[] bytes) {
StringBuffer r = new StringBuffer(32);
for (int i = 0; i < bytes.length; i++) {
String x = Integer.toHexString(bytes[i] & 0xff);
if (x.length() < 2)
r.append("0");
r.append(x);
public boolean phpbb_check_hash(String password, String hash) {
if (hash.length() == 34) return _hash_crypt_private(password, hash)
.equals(hash);
else return md5(password).equals(hash);
}
return r.toString();
}
static String pack(String hex) {
StringBuffer buf = new StringBuffer();
for(int i = 0; i < hex.length(); i += 2) {
char c1 = hex.charAt(i);
char c2 = hex.charAt(i+1);
char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
buf.append(packed);
public static String md5(String data) {
try {
byte[] bytes = data.getBytes("ISO-8859-1");
MessageDigest md5er = MessageDigest.getInstance("MD5");
byte[] hash = md5er.digest(bytes);
return bytes2hex(hash);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
return buf.toString();
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return phpbb_hash(password, salt);
}
static int hexToInt(char ch) {
if (ch >= '0' && ch <= '9') return ch - '0';
ch = Character.toUpperCase(ch);
if (ch >= 'A' && ch <= 'F') return ch - 'A' + 0xA;
throw new IllegalArgumentException("Not a hex character: " + ch);
}
@Override
public boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException {
return phpbb_check_hash(password, hash);
}
private static String bytes2hex(byte[] bytes) {
StringBuffer r = new StringBuffer(32);
for (int i = 0; i < bytes.length; i++) {
String x = Integer.toHexString(bytes[i] & 0xff);
if (x.length() < 2) r.append("0");
r.append(x);
}
return r.toString();
}
static String pack(String hex) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < hex.length(); i += 2) {
char c1 = hex.charAt(i);
char c2 = hex.charAt(i + 1);
char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
buf.append(packed);
}
return buf.toString();
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return phpbb_hash(password, salt);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return phpbb_check_hash(password, hash);
}
}
@@ -11,49 +11,52 @@ import javax.crypto.spec.SecretKeySpec;
import fr.xephi.authme.AuthMe;
public class PHPFUSION implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String digest = null;
String algo = "HmacSHA256";
String keyString = getSHA1(salt);
try {
SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), algo);
Mac mac = Mac.getInstance(algo);
mac.init(key);
byte[] bytes = mac.doFinal(password.getBytes("ASCII"));
StringBuffer hash = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
hash.append('0');
SecretKeySpec key = new SecretKeySpec(
(keyString).getBytes("UTF-8"), algo);
Mac mac = Mac.getInstance(algo);
mac.init(key);
byte[] bytes = mac.doFinal(password.getBytes("ASCII"));
StringBuffer hash = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
hash.append('0');
}
hash.append(hex);
}
hash.append(hex);
}
digest = hash.toString();
digest = hash.toString();
} catch (UnsupportedEncodingException e) {
} catch (InvalidKeyException e) {
} catch (NoSuchAlgorithmException e) {
}
return digest;
}
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, ""));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash.equals(getHash(password, salt, ""));
}
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -4,16 +4,16 @@ import java.security.NoSuchAlgorithmException;
public class PLAINTEXT implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return password;
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return password;
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(password);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(password);
}
}
@@ -5,26 +5,30 @@ import java.security.NoSuchAlgorithmException;
public class ROYALAUTH implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
for (int i = 0; i < 25; i++)
password = hash(password, salt);
return password;
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
for (int i = 0; i < 25; i++)
password = hash(password, salt);
return password;
}
public String hash(String password, String salt) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(password.getBytes());
byte byteData[] = md.digest();
StringBuilder sb = new StringBuilder();
for (byte aByteData : byteData)
sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16).substring(1));
return sb.toString();
}
public String hash(String password, String salt)
throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(password.getBytes());
byte byteData[] = md.digest();
StringBuilder sb = new StringBuilder();
for (byte aByteData : byteData)
sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16)
.substring(1));
return sb.toString();
}
@Override
public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException {
return hash.equalsIgnoreCase(getHash(password, "", ""));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equalsIgnoreCase(getHash(password, "", ""));
}
}
@@ -6,27 +6,29 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
public class SALTED2MD5 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password) + salt);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getMD5(getMD5(password) + salt);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getMD5(getMD5(password) + salt));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash.equals(getMD5(getMD5(password) + salt));
}
private static String getMD5(String message) throws NoSuchAlgorithmException {
private static String getMD5(String message)
throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,23 +6,26 @@ import java.security.NoSuchAlgorithmException;
public class SHA1 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
return getSHA1(password);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(password);
}
@Override
public boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,24 +6,27 @@ import java.security.NoSuchAlgorithmException;
public class SHA256 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return "$SHA$" + salt + "$" + getSHA256(getSHA256(password) + salt);
}
@Override
public boolean comparePassword(String hash, String password, String playerName)
throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
return hash.equals(getHash(password, line[2], ""));
}
private static String getSHA256(String message) throws NoSuchAlgorithmException {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String[] line = hash.split("\\$");
return hash.equals(getHash(password, line[2], ""));
}
private static String getSHA256(String message)
throws NoSuchAlgorithmException {
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
sha256.reset();
sha256.update(message.getBytes());
byte[] digest = sha256.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,23 +6,25 @@ import java.security.NoSuchAlgorithmException;
public class SHA512 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA512(password);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA512(password);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
private static String getSHA512(String message) throws NoSuchAlgorithmException {
private static String getSHA512(String message)
throws NoSuchAlgorithmException {
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
sha512.reset();
sha512.update(message.getBytes());
byte[] digest = sha512.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,23 +6,25 @@ import java.security.NoSuchAlgorithmException;
public class SMF implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(name.toLowerCase() + password);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(name.toLowerCase() + password);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, null, playerName));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -6,27 +6,29 @@ import java.security.NoSuchAlgorithmException;
import fr.xephi.authme.AuthMe;
public class WBB3 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password)))));
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password)))));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, ""));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash.equals(getHash(password, salt, ""));
}
private static String getSHA1(String message) throws NoSuchAlgorithmException {
private static String getSHA1(String message)
throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
}
}
@@ -4,16 +4,16 @@ import java.security.NoSuchAlgorithmException;
public class WBB4 implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return BCRYPT.getDoubleHash(password, salt);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return BCRYPT.getDoubleHash(password, salt);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return BCRYPT.checkpw(password, hash, 2);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return BCRYPT.checkpw(password, hash, 2);
}
}
@@ -7,53 +7,57 @@ package fr.xephi.authme.security.crypts;
* <b>References</b>
*
* <P>
* The Whirlpool algorithm was developed by
* <a href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and
* <a href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>.
* The Whirlpool algorithm was developed by <a
* href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and <a
* href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>.
*
* See
* P.S.L.M. Barreto, V. Rijmen,
* ``The Whirlpool hashing function,''
* First NESSIE workshop, 2000 (tweaked version, 2003),
* <https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip>
* See P.S.L.M. Barreto, V. Rijmen, ``The Whirlpool hashing function,'' First
* NESSIE workshop, 2000 (tweaked version, 2003),
* <https://www.cosic.esat.kuleuven
* .ac.be/nessie/workshop/submissions/whirlpool.zip>
*
* @author Paulo S.L.M. Barreto
* @author Vincent Rijmen.
* @author Paulo S.L.M. Barreto
* @author Vincent Rijmen.
*
* @version 3.0 (2003.03.12)
*
* =============================================================================
* ====================================================================
* =========
*
* Differences from version 2.1:
* Differences from version 2.1:
*
* - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2, 9).
* - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2,
* 9).
*
* =============================================================================
* ====================================================================
* =========
*
* Differences from version 2.0:
* Differences from version 2.0:
*
* - Generation of ISO/IEC 10118-3 test vectors.
* - Bug fix: nonzero carry was ignored when tallying the data length
* (this bug apparently only manifested itself when feeding data
* in pieces rather than in a single chunk at once).
* - Generation of ISO/IEC 10118-3 test vectors. - Bug fix: nonzero
* carry was ignored when tallying the data length (this bug apparently
* only manifested itself when feeding data in pieces rather than in a
* single chunk at once).
*
* Differences from version 1.0:
* Differences from version 1.0:
*
* - Original S-box replaced by the tweaked, hardware-efficient version.
* - Original S-box replaced by the tweaked, hardware-efficient
* version.
*
* =============================================================================
* ====================================================================
* =========
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
@@ -80,30 +84,29 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* The substitution box.
*/
private static final String sbox =
"\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152" +
"\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57" +
"\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85" +
"\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8" +
"\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333" +
"\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0" +
"\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE" +
"\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d" +
"\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF" +
"\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A" +
"\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c" +
"\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04" +
"\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB" +
"\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9" +
"\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1" +
"\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";
private static final String sbox = "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152"
+ "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57"
+ "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85"
+ "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8"
+ "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333"
+ "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0"
+ "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE"
+ "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d"
+ "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF"
+ "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A"
+ "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c"
+ "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04"
+ "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB"
+ "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9"
+ "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1"
+ "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";
private static long[][] C = new long[8][256];
private static long[] rc = new long[R + 1];
private static long[] rc = new long[R + 1];
static {
for (int x = 0; x < 256; x++) {
char c = sbox.charAt(x/2);
char c = sbox.charAt(x / 2);
long v1 = ((x & 1) == 0) ? c >>> 8 : c & 0xff;
long v2 = v1 << 1;
if (v2 >= 0x100L) {
@@ -120,11 +123,11 @@ public class WHIRLPOOL implements EncryptionMethod {
}
long v9 = v8 ^ v1;
/*
* build the circulant table C[0][x] = S[x].[1, 1, 4, 1, 8, 5, 2, 9]:
* build the circulant table C[0][x] = S[x].[1, 1, 4, 1, 8, 5, 2,
* 9]:
*/
C[0][x] =
(v1 << 56) | (v1 << 48) | (v4 << 40) | (v1 << 32) |
(v8 << 24) | (v5 << 16) | (v2 << 8) | (v9 );
C[0][x] = (v1 << 56) | (v1 << 48) | (v4 << 40) | (v1 << 32)
| (v8 << 24) | (v5 << 16) | (v2 << 8) | (v9);
/*
* build the remaining circulant tables C[t][x] = C[0][x] rotr t
*/
@@ -135,18 +138,20 @@ public class WHIRLPOOL implements EncryptionMethod {
/*
* build the round constants:
*/
rc[0] = 0L; /* not used (assigment kept only to properly initialize all variables) */
rc[0] = 0L; /*
* not used (assigment kept only to properly initialize all
* variables)
*/
for (int r = 1; r <= R; r++) {
int i = 8*(r - 1);
rc[r] =
(C[0][i ] & 0xff00000000000000L) ^
(C[1][i + 1] & 0x00ff000000000000L) ^
(C[2][i + 2] & 0x0000ff0000000000L) ^
(C[3][i + 3] & 0x000000ff00000000L) ^
(C[4][i + 4] & 0x00000000ff000000L) ^
(C[5][i + 5] & 0x0000000000ff0000L) ^
(C[6][i + 6] & 0x000000000000ff00L) ^
(C[7][i + 7] & 0x00000000000000ffL);
int i = 8 * (r - 1);
rc[r] = (C[0][i] & 0xff00000000000000L)
^ (C[1][i + 1] & 0x00ff000000000000L)
^ (C[2][i + 2] & 0x0000ff0000000000L)
^ (C[3][i + 3] & 0x000000ff00000000L)
^ (C[4][i + 4] & 0x00000000ff000000L)
^ (C[5][i + 5] & 0x0000000000ff0000L)
^ (C[6][i + 6] & 0x000000000000ff00L)
^ (C[7][i + 7] & 0x00000000000000ffL);
}
}
@@ -173,9 +178,9 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* The hashing state.
*/
protected long[] hash = new long[8];
protected long[] K = new long[8];
protected long[] L = new long[8];
protected long[] hash = new long[8];
protected long[] K = new long[8];
protected long[] L = new long[8];
protected long[] block = new long[8];
protected long[] state = new long[8];
@@ -190,15 +195,14 @@ public class WHIRLPOOL implements EncryptionMethod {
* map the buffer to a block:
*/
for (int i = 0, j = 0; i < 8; i++, j += 8) {
block[i] =
(((long)buffer[j ] ) << 56) ^
(((long)buffer[j + 1] & 0xffL) << 48) ^
(((long)buffer[j + 2] & 0xffL) << 40) ^
(((long)buffer[j + 3] & 0xffL) << 32) ^
(((long)buffer[j + 4] & 0xffL) << 24) ^
(((long)buffer[j + 5] & 0xffL) << 16) ^
(((long)buffer[j + 6] & 0xffL) << 8) ^
(((long)buffer[j + 7] & 0xffL) );
block[i] = (((long) buffer[j]) << 56)
^ (((long) buffer[j + 1] & 0xffL) << 48)
^ (((long) buffer[j + 2] & 0xffL) << 40)
^ (((long) buffer[j + 3] & 0xffL) << 32)
^ (((long) buffer[j + 4] & 0xffL) << 24)
^ (((long) buffer[j + 5] & 0xffL) << 16)
^ (((long) buffer[j + 6] & 0xffL) << 8)
^ (((long) buffer[j + 7] & 0xffL));
}
/*
* compute and apply K^0 to the cipher state:
@@ -216,7 +220,7 @@ public class WHIRLPOOL implements EncryptionMethod {
for (int i = 0; i < 8; i++) {
L[i] = 0L;
for (int t = 0, s = 56; t < 8; t++, s -= 8) {
L[i] ^= C[t][(int)(K[(i - t) & 7] >>> s) & 0xff];
L[i] ^= C[t][(int) (K[(i - t) & 7] >>> s) & 0xff];
}
}
for (int i = 0; i < 8; i++) {
@@ -229,7 +233,7 @@ public class WHIRLPOOL implements EncryptionMethod {
for (int i = 0; i < 8; i++) {
L[i] = K[i];
for (int t = 0, s = 56; t < 8; t++, s -= 8) {
L[i] ^= C[t][(int)(state[(i - t) & 7] >>> s) & 0xff];
L[i] ^= C[t][(int) (state[(i - t) & 7] >>> s) & 0xff];
}
}
for (int i = 0; i < 8; i++) {
@@ -248,7 +252,7 @@ public class WHIRLPOOL implements EncryptionMethod {
* Initialize the hashing state.
*/
public void NESSIEinit() {
Arrays.fill(bitLength, (byte)0);
Arrays.fill(bitLength, (byte) 0);
bufferBits = bufferPos = 0;
buffer[0] = 0;
Arrays.fill(hash, 0L);
@@ -257,41 +261,41 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* Delivers input data to the hashing algorithm.
*
* @param source plaintext data to hash.
* @param sourceBits how many bits of plaintext to process.
* @param source
* plaintext data to hash.
* @param sourceBits
* how many bits of plaintext to process.
*
* This method maintains the invariant: bufferBits < 512
* This method maintains the invariant: bufferBits < 512
*/
public void NESSIEadd(byte[] source, long sourceBits) {
/*
sourcePos
|
+-------+-------+-------
||||||||||||||||||||| source
+-------+-------+-------
+-------+-------+-------+-------+-------+-------
|||||||||||||||||||||| buffer
+-------+-------+-------+-------+-------+-------
|
bufferPos
*/
int sourcePos = 0; // index of leftmost source byte containing data (1 to 8 bits).
int sourceGap = (8 - ((int)sourceBits & 7)) & 7; // space on source[sourcePos].
* sourcePos | +-------+-------+------- ||||||||||||||||||||| source
* +-------+-------+-------
* +-------+-------+-------+-------+-------+-------
* |||||||||||||||||||||| buffer
* +-------+-------+-------+-------+-------+------- | bufferPos
*/
int sourcePos = 0; // index of leftmost source byte containing data (1
// to 8 bits).
int sourceGap = (8 - ((int) sourceBits & 7)) & 7; // space on
// source[sourcePos].
int bufferRem = bufferBits & 7; // occupied bits on buffer[bufferPos].
int b;
// tally the length of the added data:
long value = sourceBits;
for (int i = 31, carry = 0; i >= 0; i--) {
carry += (bitLength[i] & 0xff) + ((int)value & 0xff);
bitLength[i] = (byte)carry;
carry += (bitLength[i] & 0xff) + ((int) value & 0xff);
bitLength[i] = (byte) carry;
carry >>>= 8;
value >>>= 8;
}
// process data in chunks of 8 bits:
while (sourceBits > 8) { // at least source[sourcePos] and source[sourcePos+1] contain data.
while (sourceBits > 8) { // at least source[sourcePos] and
// source[sourcePos+1] contain data.
// take a byte from the source:
b = ((source[sourcePos] << sourceGap) & 0xff) |
((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap));
b = ((source[sourcePos] << sourceGap) & 0xff)
| ((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap));
if (b < 0 || b >= 256) {
throw new RuntimeException("LOGIC ERROR");
}
@@ -304,7 +308,7 @@ public class WHIRLPOOL implements EncryptionMethod {
// reset buffer:
bufferBits = bufferPos = 0;
}
buffer[bufferPos] = (byte)((b << (8 - bufferRem)) & 0xff);
buffer[bufferPos] = (byte) ((b << (8 - bufferRem)) & 0xff);
bufferBits += bufferRem;
// proceed to remaining data:
sourceBits -= 8;
@@ -313,29 +317,32 @@ public class WHIRLPOOL implements EncryptionMethod {
// now 0 <= sourceBits <= 8;
// furthermore, all data (if any is left) is in source[sourcePos].
if (sourceBits > 0) {
b = (source[sourcePos] << sourceGap) & 0xff; // bits are left-justified on b.
b = (source[sourcePos] << sourceGap) & 0xff; // bits are
// left-justified on b.
// process the remaining bits:
buffer[bufferPos] |= b >>> bufferRem;
} else {
b = 0;
}
if (bufferRem + sourceBits < 8) {
// all remaining data fits on buffer[bufferPos], and there still remains some space.
// all remaining data fits on buffer[bufferPos], and there still
// remains some space.
bufferBits += sourceBits;
} else {
// buffer[bufferPos] is full:
bufferPos++;
bufferBits += 8 - bufferRem; // bufferBits = 8*bufferPos;
sourceBits -= 8 - bufferRem;
// now 0 <= sourceBits < 8; furthermore, all data is in source[sourcePos].
// now 0 <= sourceBits < 8; furthermore, all data is in
// source[sourcePos].
if (bufferBits == 512) {
// process data block:
processBuffer();
// reset buffer:
bufferBits = bufferPos = 0;
}
buffer[bufferPos] = (byte)((b << (8 - bufferRem)) & 0xff);
bufferBits += (int)sourceBits;
buffer[bufferPos] = (byte) ((b << (8 - bufferRem)) & 0xff);
bufferBits += (int) sourceBits;
}
}
@@ -368,58 +375,59 @@ public class WHIRLPOOL implements EncryptionMethod {
// return the completed message digest:
for (int i = 0, j = 0; i < 8; i++, j += 8) {
long h = hash[i];
digest[j ] = (byte)(h >>> 56);
digest[j + 1] = (byte)(h >>> 48);
digest[j + 2] = (byte)(h >>> 40);
digest[j + 3] = (byte)(h >>> 32);
digest[j + 4] = (byte)(h >>> 24);
digest[j + 5] = (byte)(h >>> 16);
digest[j + 6] = (byte)(h >>> 8);
digest[j + 7] = (byte)(h );
digest[j] = (byte) (h >>> 56);
digest[j + 1] = (byte) (h >>> 48);
digest[j + 2] = (byte) (h >>> 40);
digest[j + 3] = (byte) (h >>> 32);
digest[j + 4] = (byte) (h >>> 24);
digest[j + 5] = (byte) (h >>> 16);
digest[j + 6] = (byte) (h >>> 8);
digest[j + 7] = (byte) (h);
}
}
/**
* Delivers string input data to the hashing algorithm.
*
* @param source plaintext data to hash (ASCII text string).
* @param source
* plaintext data to hash (ASCII text string).
*
* This method maintains the invariant: bufferBits < 512
* This method maintains the invariant: bufferBits < 512
*/
public void NESSIEadd(String source) {
if (source.length() > 0) {
byte[] data = new byte[source.length()];
for (int i = 0; i < source.length(); i++) {
data[i] = (byte)source.charAt(i);
data[i] = (byte) source.charAt(i);
}
NESSIEadd(data, 8*data.length);
NESSIEadd(data, 8 * data.length);
}
}
protected static String display(byte[] array) {
char[] val = new char[2*array.length];
char[] val = new char[2 * array.length];
String hex = "0123456789ABCDEF";
for (int i = 0; i < array.length; i++) {
int b = array[i] & 0xff;
val[2*i] = hex.charAt(b >>> 4);
val[2*i + 1] = hex.charAt(b & 15);
val[2 * i] = hex.charAt(b >>> 4);
val[2 * i + 1] = hex.charAt(b & 15);
}
return String.valueOf(val);
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
byte[] digest = new byte[DIGESTBYTES];
NESSIEinit();
NESSIEadd(password);
NESSIEfinalize(digest);
return display(digest);
}
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
return hash.equals(getHash(password, "", ""));
}
}
@@ -47,7 +47,8 @@ public class WORDPRESS implements EncryptionMethod {
private String crypt(String password, String setting) {
String output = "*0";
if (((setting.length() < 2) ? setting : setting.substring(0, 2)).equalsIgnoreCase(output)) {
if (((setting.length() < 2) ? setting : setting.substring(0, 2))
.equalsIgnoreCase(output)) {
output = "*1";
}
String id = (setting.length() < 3) ? setting : setting.substring(0, 3);
@@ -94,22 +95,24 @@ public class WORDPRESS implements EncryptionMethod {
try {
return string.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException("This system doesn't support UTF-8!", e);
throw new UnsupportedOperationException(
"This system doesn't support UTF-8!", e);
}
}
@Override
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException {
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
byte random[] = new byte[6];
this.randomGen.nextBytes(random);
return crypt(password, gensaltPrivate(stringToUtf8(new String(random))));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String comparedHash = crypt(password, hash);
return comparedHash.equals(hash);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String comparedHash = crypt(password, hash);
return comparedHash.equals(hash);
}
}
@@ -4,29 +4,31 @@ import java.security.NoSuchAlgorithmException;
public class XAUTH implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String hash = getWhirlpool(salt + password).toLowerCase();
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
int saltPos = (password.length() >= hash.length() ? hash.length() - 1
: password.length());
return hash.substring(0, saltPos) + salt + hash.substring(saltPos);
}
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
int saltPos = (password.length() >= hash.length() ? hash.length() - 1
: password.length());
String salt = hash.substring(saltPos, saltPos + 12);
return hash.equals(getHash(password, salt, ""));
}
}
public static String getWhirlpool(String message) {
public static String getWhirlpool(String message) {
WHIRLPOOL w = new WHIRLPOOL();
byte[] digest = new byte[WHIRLPOOL.DIGESTBYTES];
w.NESSIEinit();
w.NESSIEadd(message);
w.NESSIEfinalize(digest);
return WHIRLPOOL.display(digest);
}
}
}
@@ -9,51 +9,48 @@ import java.util.regex.Pattern;
import fr.xephi.authme.AuthMe;
public class XF implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA256(getSHA256(password) + regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt));
}
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA256(getSHA256(password)
+ regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash
.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt));
}
public String getSHA256(String password) throws NoSuchAlgorithmException
{
public String getSHA256(String password) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(password.getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (byte element : byteData)
{
sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(1));
for (byte element : byteData) {
sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(
1));
}
StringBuffer hexString = new StringBuffer();
for (byte element : byteData)
{
for (byte element : byteData) {
String hex = Integer.toHexString(0xff & element);
if (hex.length() == 1)
{
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
public String regmatch(String pattern, String line)
{
public String regmatch(String pattern, String line) {
List<String> allMatches = new ArrayList<String>();
Matcher m = Pattern.compile(pattern).matcher(line);
while (m.find())
{
while (m.find()) {
allMatches.add(m.group(1));
}
return allMatches.get(0);