mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-23 14:40:40 +01:00
CryptoUtils: add digestRipeMd160() method, use it to wrap BouncyCastle
This commit is contained in:
parent
fff3b7e837
commit
7a1c71c319
2 changed files with 18 additions and 11 deletions
|
@ -27,15 +27,26 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class CryptoUtils {
|
||||
/**
|
||||
* Calculates RIPEMD160(SHA256(input)). This is used in Address calculations.
|
||||
* Calculate RIPEMD160(SHA256(input)). This is used in Address calculations.
|
||||
* @param input bytes to hash
|
||||
* @return RIPEMD160(SHA256(input))
|
||||
*/
|
||||
public static byte[] sha256hash160(byte[] input) {
|
||||
byte[] sha256 = Sha256Hash.hash(input);
|
||||
return digestRipeMd160(sha256);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate RIPEMD160(input).
|
||||
* @param input bytes to hash
|
||||
* @return RIPEMD160(input)
|
||||
*/
|
||||
public static byte[] digestRipeMd160(byte[] input) {
|
||||
RIPEMD160Digest digest = new RIPEMD160Digest();
|
||||
digest.update(sha256, 0, sha256.length);
|
||||
byte[] out = new byte[20];
|
||||
digest.doFinal(out, 0);
|
||||
return out;
|
||||
digest.update(input, 0, input.length);
|
||||
byte[] ripmemdHash = new byte[20];
|
||||
digest.doFinal(ripmemdHash, 0);
|
||||
return ripmemdHash;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,6 @@ import org.bitcoinj.core.VerificationException;
|
|||
import org.bitcoinj.base.internal.InternalUtils;
|
||||
import org.bitcoinj.crypto.TransactionSignature;
|
||||
import org.bitcoinj.crypto.internal.CryptoUtils;
|
||||
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -1261,12 +1260,9 @@ public class Script {
|
|||
case OP_RIPEMD160:
|
||||
if (stack.size() < 1)
|
||||
throw new ScriptException(ScriptError.SCRIPT_ERR_INVALID_STACK_OPERATION, "Attempted OP_RIPEMD160 on an empty stack");
|
||||
RIPEMD160Digest digest = new RIPEMD160Digest();
|
||||
byte[] dataToHash = stack.pollLast();
|
||||
digest.update(dataToHash, 0, dataToHash.length);
|
||||
byte[] ripmemdHash = new byte[20];
|
||||
digest.doFinal(ripmemdHash, 0);
|
||||
stack.add(ripmemdHash);
|
||||
byte[] ripmeMdHash = CryptoUtils.digestRipeMd160(dataToHash);
|
||||
stack.add(ripmeMdHash);
|
||||
break;
|
||||
case OP_SHA1:
|
||||
if (stack.size() < 1)
|
||||
|
|
Loading…
Add table
Reference in a new issue