本文整理汇总了Java中fr.cryptohash.Shabal256类的典型用法代码示例。如果您正苦于以下问题:Java Shabal256类的具体用法?Java Shabal256怎么用?Java Shabal256使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Shabal256类属于fr.cryptohash包,在下文中一共展示了Shabal256类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRequest
import fr.cryptohash.Shabal256; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("height", Long.toString(Nxt.getBlockchain().getHeight() + 1));
Block lastBlock = Nxt.getBlockchain().getLastBlock();
byte[] lastGenSig = lastBlock.getGenerationSignature();
Long lastGenerator = lastBlock.getGeneratorId();
ByteBuffer buf = ByteBuffer.allocate(32 + 8);
buf.put(lastGenSig);
buf.putLong(lastGenerator);
Shabal256 md = new Shabal256();
md.update(buf.array());
byte[] newGenSig = md.digest();
response.put("generationSignature", Convert.toHexString(newGenSig));
response.put("baseTarget", Long.toString(lastBlock.getBaseTarget()));
return response;
}
示例2: MiningPlot
import fr.cryptohash.Shabal256; //导入依赖的package包/类
public MiningPlot(long addr, long nonce) {
ByteBuffer base_buffer = ByteBuffer.allocate(16);
base_buffer.putLong(addr);
base_buffer.putLong(nonce);
byte[] base = base_buffer.array();
Shabal256 md = new Shabal256();
byte[] gendata = new byte[PLOT_SIZE + base.length];
System.arraycopy(base, 0, gendata, PLOT_SIZE, base.length);
for(int i = PLOT_SIZE; i > 0; i -= HASH_SIZE) {
md.reset();
int len = PLOT_SIZE + base.length - i;
if(len > HASH_CAP) {
len = HASH_CAP;
}
md.update(gendata, i, len);
md.digest(gendata, i - HASH_SIZE, HASH_SIZE);
}
md.reset();
md.update(gendata);
byte[] finalhash = md.digest();
for(int i = 0; i < PLOT_SIZE; i++) {
data[i] = (byte) (gendata[i] ^ finalhash[i % HASH_SIZE]);
}
}
示例3: processRequest
import fr.cryptohash.Shabal256; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
JSONObject response = new JSONObject();
response.put("height", Long.toString(Rise.getBlockchain().getLastHDDBlock().getHeight() + 1));
Block lastBlock = Rise.getBlockchain().getLastHDDBlock();
byte[] lastGenSig = lastBlock.getGenerationSignature();
Long lastGenerator = lastBlock.getGeneratorId();
ByteBuffer buf = ByteBuffer.allocate(32 + 8);
buf.put(lastGenSig);
buf.putLong(lastGenerator);
Shabal256 md = new Shabal256();
md.update(buf.array());
byte[] newGenSig = md.digest();
response.put("generationSignature", Convert.toHexString(newGenSig));
response.put("baseTarget", Long.toString(lastBlock.getBaseTarget()));
return response;
}
示例4: calcScoopNumber
import fr.cryptohash.Shabal256; //导入依赖的package包/类
private static int calcScoopNumber(long blockNumber, byte[] generationSignature)
{
if(blockNumber > 0 && generationSignature != null)
{
ByteBuffer buf = ByteBuffer.allocate(32 + 8);
buf.put(generationSignature);
buf.putLong(blockNumber);
// generate new scoop number
Shabal256 md = new Shabal256();
md.update(buf.array());
BigInteger hashnum = new BigInteger(1, md.digest());
return hashnum.mod(BigInteger.valueOf(MiningPlot.SCOOPS_PER_PLOT)).intValue();
}
return 0;
}
示例5: calculateGenerationSignature
import fr.cryptohash.Shabal256; //导入依赖的package包/类
@Override
public byte[] calculateGenerationSignature(byte[] lastGenSig, long lastGenId) {
ByteBuffer gensigbuf = ByteBuffer.allocate(32 + 8);
gensigbuf.put(lastGenSig);
gensigbuf.putLong(lastGenId);
Shabal256 md = new Shabal256();
md.update(gensigbuf.array());
return md.digest();
}
示例6: calculateScoop
import fr.cryptohash.Shabal256; //导入依赖的package包/类
@Override
public int calculateScoop(byte[] genSig, long height) {
ByteBuffer posbuf = ByteBuffer.allocate(32 + 8);
posbuf.put(genSig);
posbuf.putLong(height);
Shabal256 md = new Shabal256();
md.update(posbuf.array());
BigInteger hashnum = new BigInteger(1, md.digest());
return hashnum.mod(BigInteger.valueOf(MiningPlot.SCOOPS_PER_PLOT)).intValue();
}
示例7: calculateHit
import fr.cryptohash.Shabal256; //导入依赖的package包/类
@Override
public BigInteger calculateHit(long accountId, long nonce, byte[] genSig, int scoop) {
MiningPlot plot = new MiningPlot(accountId, nonce);
Shabal256 md = new Shabal256();
md.update(genSig);
plot.hashScoop(md, scoop);
byte[] hash = md.digest();
return new BigInteger(1, new byte[] {hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0]});
}
示例8: getScoopNum
import fr.cryptohash.Shabal256; //导入依赖的package包/类
@Override
public int getScoopNum() {
ByteBuffer posbuf = ByteBuffer.allocate(32 + 8);
posbuf.put(generationSignature);
posbuf.putLong(getHeight());
Shabal256 md = new Shabal256();
md.update(posbuf.array());
BigInteger hashnum = new BigInteger(1, md.digest());
int scoopNum = hashnum.mod(BigInteger.valueOf(MiningPlot.SCOOPS_PER_PLOT)).intValue();
return scoopNum;
}
示例9: MineGenerator
import fr.cryptohash.Shabal256; //导入依赖的package包/类
private MineGenerator(String secretPhrase, Long nonce, byte[] publicKey, Long account) {
this.secretPhrase = secretPhrase;
this.publicKey = publicKey;
// need to store publicKey in addition to accountId, because the account may not have had its publicKey set yet
this.accountId = account;
this.nonce = nonce;
this.block = Rise.getBlockchain().getLastHDDBlock().getHeight() + 1;
// get new generation signature
Block lastBlock = Rise.getBlockchain().getLastHDDBlock();
byte[] lastGenSig = lastBlock.getGenerationSignature();
Long lastGenerator = lastBlock.getGeneratorId();
ByteBuffer gensigbuf = ByteBuffer.allocate(32 + 8);
gensigbuf.put(lastGenSig);
gensigbuf.putLong(lastGenerator);
Shabal256 md = new Shabal256();
md.update(gensigbuf.array());
byte[] newGenSig = md.digest();
// calculate deadline
MiningPlot plot = new MiningPlot(accountId, nonce);
ByteBuffer posbuf = ByteBuffer.allocate(32 + 8);
posbuf.put(newGenSig);
posbuf.putLong(lastBlock.getHeight() + 1);
md.reset();
md.update(posbuf.array());
BigInteger hashnum = new BigInteger(1, md.digest());
int scoopNum = hashnum.mod(BigInteger.valueOf(MiningPlot.SCOOPS_PER_PLOT)).intValue();
md.reset();
md.update(newGenSig);
plot.hashScoop(md, scoopNum);
byte[] hash = md.digest();
BigInteger hit = new BigInteger(1, new byte[] {hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0]});
deadline = hit.divide(BigInteger.valueOf(lastBlock.getBaseTarget()));
}
示例10: calculateResult
import fr.cryptohash.Shabal256; //导入依赖的package包/类
private BigInteger calculateResult(byte[] scoops, byte[] generationSignature, int nonce)
{
Shabal256 md = new Shabal256();
md.reset();
md.update(generationSignature);
md.update(scoops, nonce * MiningPlot.SCOOP_SIZE, MiningPlot.SCOOP_SIZE);
byte[] hash = md.digest();
return new BigInteger(1, new byte[]{hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0]});
}
示例11: MiningPlot
import fr.cryptohash.Shabal256; //导入依赖的package包/类
public MiningPlot(long addr, long nonce)
{
ByteBuffer base_buffer = ByteBuffer.allocate(16);
base_buffer.putLong(addr);
base_buffer.putLong(nonce);
byte[] base = base_buffer.array();
Shabal256 md = new Shabal256();
byte[] gendata = new byte[PLOT_SIZE + base.length];
System.arraycopy(base, 0, gendata, PLOT_SIZE, base.length);
for(int i = PLOT_SIZE; i > 0; i -= HASH_SIZE)
{
md.reset();
int len = PLOT_SIZE + base.length - i;
if(len > HASH_CAP)
{
len = HASH_CAP;
}
md.update(gendata, i, len);
md.digest(gendata, i - HASH_SIZE, HASH_SIZE);
}
md.reset();
md.update(gendata);
byte[] finalhash = md.digest();
for(int i = 0; i < PLOT_SIZE; i++)
{
data[i] = (byte) (gendata[i] ^ finalhash[i % HASH_SIZE]);
}
}
示例12: hashScoop
import fr.cryptohash.Shabal256; //导入依赖的package包/类
public void hashScoop(Shabal256 md, int pos) {
md.update(data, pos * SCOOP_SIZE, SCOOP_SIZE);
}
示例13: hashScoop
import fr.cryptohash.Shabal256; //导入依赖的package包/类
public void hashScoop(Shabal256 md, int pos)
{
md.update(data, pos * SCOOP_SIZE, SCOOP_SIZE);
}