Java 类fr.cryptohash.Shabal256 实例源码

项目:burstcoin    文件:GetMiningInfo.java   
@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;
}
项目:burstcoin    文件:MiningPlot.java   
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]);
    }
}
项目:risecoin    文件:GetMiningInfo.java   
@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;
}
项目:risecoin    文件:MiningPlot.java   
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]);
    }
}
项目:burstcoin-jminer    文件:Round.java   
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;
}
项目:burstcoin    文件:GeneratorImpl.java   
@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();
}
项目:burstcoin    文件:GeneratorImpl.java   
@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();
}
项目:burstcoin    文件:GeneratorImpl.java   
@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]});
}
项目:burstcoin    文件:GeneratorImpl.java   
@Override
public BigInteger calculateHit(long accountId, long nonce, byte[] genSig, byte[] scoopData) {
    Shabal256 md = new Shabal256();
    md.update(genSig);
    md.update(scoopData);
    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]});
}
项目:risecoin    文件:BlockImpl.java   
@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;
  }
项目:risecoin    文件:MineGenerator.java   
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()));
  }
项目:burstcoin-jminer    文件:OCLCheckerTask.java   
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]});
}
项目:burstcoin-jminer    文件:MiningPlot.java   
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]);
  }
}
项目:burstcoin    文件:MiningPlot.java   
public void hashScoop(Shabal256 md, int pos) {
    md.update(data, pos * SCOOP_SIZE, SCOOP_SIZE);
}
项目:risecoin    文件:MiningPlot.java   
public void hashScoop(Shabal256 md, int pos) {
    md.update(data, pos * SCOOP_SIZE, SCOOP_SIZE);
}
项目:burstcoin-jminer    文件:MiningPlot.java   
public void hashScoop(Shabal256 md, int pos)
{
  md.update(data, pos * SCOOP_SIZE, SCOOP_SIZE);
}