mirror of
https://github.com/Geprivilegieerde-Anonimiteit-BV/XACrypto.git
synced 2026-08-21 21:46:23 -04:00
SHA1 fully tested + working
This commit is contained in:
@@ -4,13 +4,16 @@ import de.caydenno1.xacrypto.misc.Constants;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static de.caydenno1.xacrypto.hash.sha.Shared.INT2BYTE;
|
||||
import static de.caydenno1.xacrypto.hash.sha.Shared.hex;
|
||||
|
||||
public class SHA0 {
|
||||
// we really only need one file. very simple code
|
||||
public static byte[] hash(byte[] data){
|
||||
System.out.println("Beware, SHA0 is deprecated and cryptographically broken. Use at your own risk.");
|
||||
byte[] padded = pad(data);
|
||||
byte[] padded = Shared.pad(data);
|
||||
|
||||
int a0 = Constants.SHA0_H[0], a1 = Constants.SHA0_H[1], a2 = Constants.SHA0_H[2], a3 = Constants.SHA0_H[3], a4 = Constants.SHA0_H[4];
|
||||
int a0 = Constants.SHA_H[0], a1 = Constants.SHA_H[1], a2 = Constants.SHA_H[2], a3 = Constants.SHA_H[3], a4 = Constants.SHA_H[4];
|
||||
|
||||
int[] w = new int[80];
|
||||
|
||||
@@ -69,48 +72,8 @@ public class SHA0 {
|
||||
|
||||
return INT2BYTE(a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
public static String hash(String data) {
|
||||
byte[] result = hash(data.getBytes(StandardCharsets.UTF_8));
|
||||
return hex(result);
|
||||
}
|
||||
|
||||
public static String hex(byte[] data) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (byte b : data) builder.append(String.format("%02x", b));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static byte[] pad(byte[] mesg) {
|
||||
int len = mesg.length;
|
||||
long bit = (long) len * 8;
|
||||
|
||||
int padL = (64 - ((len + 9) % 64)) % 64;
|
||||
byte[] o = new byte[len+padL+9];
|
||||
|
||||
System.arraycopy(mesg,0,o,0,len);
|
||||
o[len] = (byte) 0x80;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
o[o.length - (i+1)] = (byte) (bit >>> (8*i));
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
private static byte[] INT2BYTE(int a,int b,int c,int d,int e) {
|
||||
byte[] out = new byte[20];
|
||||
write(a, out, 0);
|
||||
write(b, out, 4);
|
||||
write(c, out, 8);
|
||||
write(d, out, 12);
|
||||
write(e, out, 16);
|
||||
return out;
|
||||
}
|
||||
|
||||
private static void write(int v, byte[] o, int i) {
|
||||
o[i ] = (byte)(v >>> 24);
|
||||
o[i+1] = (byte)(v >>> 16);
|
||||
o[i+2] = (byte)(v >>> 8);
|
||||
o[i+3] = (byte)(v );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user