mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
Add Groestl hash support
This commit is contained in:
parent
93d494fcde
commit
0e2736a270
2 changed files with 71 additions and 0 deletions
|
|
@ -60,6 +60,7 @@ dependencies {
|
|||
exclude group: 'org.hamcrest', module: 'hamcrest-core'
|
||||
}
|
||||
testImplementation group: 'org.hamcrest', name: 'hamcrest-core', version: '2.2'
|
||||
implementation 'de.sfuhrm:saphir-hash-core:3.0.5'
|
||||
}
|
||||
|
||||
task(runDrongo, dependsOn: 'classes', type: JavaExec) {
|
||||
|
|
|
|||
70
src/main/java/com/sparrowwallet/drongo/crypto/Groestl.java
Normal file
70
src/main/java/com/sparrowwallet/drongo/crypto/Groestl.java
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package com.sparrowwallet.drongo.crypto;
|
||||
|
||||
import fr.cryptohash.Groestl512;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* Created by Hash Engineering on 12/24/14 for the Groestl algorithm
|
||||
*/
|
||||
public class Groestl {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Groestl.class);
|
||||
private static boolean native_library_loaded = false;
|
||||
private static final Groestl512 digestGroestl = new Groestl512();
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("groestld");
|
||||
native_library_loaded = true;
|
||||
} catch(UnsatisfiedLinkError x) {
|
||||
native_library_loaded = false;
|
||||
} catch(Exception e) {
|
||||
native_library_loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] digest(byte[] input, int offset, int length) {
|
||||
try {
|
||||
return native_library_loaded ? groestld_native(input, offset, length) : groestl(input, offset, length);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] digest(byte[] input) {
|
||||
try {
|
||||
return native_library_loaded ? groestld_native(input, 0, input.length) : groestl(input);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static native byte [] groestld_native(byte [] input, int offset, int len);
|
||||
|
||||
static byte [] groestl(byte header[]) {
|
||||
Groestl512 hasher1 = new Groestl512();
|
||||
Groestl512 hasher2 = new Groestl512();
|
||||
|
||||
byte [] hash1 = hasher1.digest(header);
|
||||
byte [] hash2 = hasher2.digest(hash1);
|
||||
|
||||
byte [] hash = new byte [32];
|
||||
System.arraycopy(hash2, 0, hash, 0, 32);
|
||||
return hash;
|
||||
}
|
||||
|
||||
static byte [] groestl(byte header[], int offset, int length) {
|
||||
digestGroestl.reset();
|
||||
digestGroestl.update(header, offset, length);
|
||||
byte [] hash1 = digestGroestl.digest();
|
||||
byte [] hash2 = digestGroestl.digest(hash1);
|
||||
|
||||
byte [] hash = new byte [32];
|
||||
System.arraycopy(hash2, 0, hash, 0, 32);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue