Beispiel #1
0
  static byte[] buildDH(DHPublicKey key) {
    DataByteOutputStream out = new DataByteOutputStream();
    BigInteger p = key.getParams().getP();
    BigInteger g = key.getParams().getG();
    BigInteger y = key.getY();

    int pLength, gLength, yLength;
    if (g.equals(TWO) && (p.equals(DHPRIME768) || p.equals(DHPRIME1024))) {
      pLength = 1;
      gLength = 0;
    } else {
      pLength = BigIntegerLength(p);
      gLength = BigIntegerLength(g);
    }
    yLength = BigIntegerLength(y);

    out.writeShort(pLength);
    if (pLength == 1) {
      if (p.bitLength() == 768) out.writeByte((byte) 1);
      else out.writeByte((byte) 2);
    } else out.writeBigInteger(p);
    out.writeShort(gLength);
    if (gLength > 0) out.writeBigInteger(g);
    out.writeShort(yLength);
    out.writeBigInteger(y);

    return out.toByteArray();
  }
Beispiel #2
0
  void rrToWire(DataByteOutputStream out, Compression c, boolean canonical) {
    if (cert == null) return;

    out.writeShort(certType);
    out.writeShort(keyTag);
    out.writeByte(alg);
    out.writeArray(cert);
  }
Beispiel #3
0
 private static void digestSIG(DataByteOutputStream out, SIGRecord sig) {
   out.writeShort(sig.getTypeCovered());
   out.writeByte(sig.getAlgorithm());
   out.writeByte(sig.getLabels());
   out.writeUnsignedInt(sig.getOrigTTL());
   out.writeInt((int) (sig.getExpire().getTime() / 1000));
   out.writeInt((int) (sig.getTimeSigned().getTime() / 1000));
   out.writeShort(sig.getFootprint());
   sig.getSigner().toWireCanonical(out);
 }
Beispiel #4
0
  void rrToWire(DataByteOutputStream out, Compression c, boolean canonical) {
    if (signature == null) return;

    out.writeShort(covered);
    out.writeByte(alg);
    out.writeByte(labels);
    out.writeInt(origttl);
    out.writeInt((int) (expire.getTime() / 1000));
    out.writeInt((int) (timeSigned.getTime() / 1000));
    out.writeShort(footprint);
    signer.toWire(out, null, canonical);
    out.writeArray(signature);
  }
Beispiel #5
0
  void rrToWire(DataByteOutputStream out, Compression c) throws IOException {
    if (key == null && (flags & (FLAG_NOKEY)) != (FLAG_NOKEY)) return;

    out.writeShort(flags);
    out.writeByte(proto);
    out.writeByte(alg);
    if (key != null) out.write(key);
  }
Beispiel #6
0
  static byte[] buildRSA(RSAPublicKey key) {
    DataByteOutputStream out = new DataByteOutputStream();
    BigInteger exponent = key.getPublicExponent();
    BigInteger modulus = key.getModulus();
    int exponentLength = BigIntegerLength(exponent);

    if (exponentLength < 256) out.writeByte(exponentLength);
    else {
      out.writeByte(0);
      out.writeShort(exponentLength);
    }
    out.writeBigInteger(exponent);
    out.writeBigInteger(modulus);

    return out.toByteArray();
  }