コード例 #1
0
  // public constructors
  public digestrandomgenerator(digest digest) {
    this.digest = digest;

    this.seed = new byte[digest.getdigestsize()];
    this.seedcounter = 1;

    this.state = new byte[digest.getdigestsize()];
    this.statecounter = 1;
  }
コード例 #2
0
  protected byte[] enginesign() throws signatureexception {
    byte[] hash = new byte[digest.getdigestsize()];

    digest.dofinal(hash, 0);

    try {
      byte[] sigbytes = new byte[64];
      biginteger[] sig = signer.generatesignature(hash);
      byte[] r = sig[0].tobytearray();
      byte[] s = sig[1].tobytearray();

      if (s[0] != 0) {
        system.arraycopy(s, 0, sigbytes, 32 - s.length, s.length);
      } else {
        system.arraycopy(s, 1, sigbytes, 32 - (s.length - 1), s.length - 1);
      }

      if (r[0] != 0) {
        system.arraycopy(r, 0, sigbytes, 64 - r.length, r.length);
      } else {
        system.arraycopy(r, 1, sigbytes, 64 - (r.length - 1), r.length - 1);
      }

      return sigbytes;
    } catch (exception e) {
      throw new signatureexception(e.tostring());
    }
  }
コード例 #3
0
  protected boolean engineverify(byte[] sigbytes) throws signatureexception {
    byte[] hash = new byte[digest.getdigestsize()];

    digest.dofinal(hash, 0);

    biginteger[] sig;

    try {
      byte[] r = new byte[32];
      byte[] s = new byte[32];

      system.arraycopy(sigbytes, 0, s, 0, 32);

      system.arraycopy(sigbytes, 32, r, 0, 32);

      sig = new biginteger[2];
      sig[0] = new biginteger(1, r);
      sig[1] = new biginteger(1, s);
    } catch (exception e) {
      throw new signatureexception("error decoding signature bytes.");
    }

    return signer.verifysignature(hash, sig[0], sig[1]);
  }
コード例 #4
0
 private static byte[] dofinal(digest d) {
   byte[] bs = new byte[d.getdigestsize()];
   d.dofinal(bs, 0);
   return bs;
 }