Package net.i2p.util

Examples of net.i2p.util.NativeBigInteger


  public static DSAGroup create(SimpleFieldSet fs) throws IllegalBase64Exception, FSParseException {
    String myP = fs.get("p");
    String myQ = fs.get("q");
    String myG = fs.get("g");
    if(myP == null || myQ == null || myG == null) throw new FSParseException("The given SFS doesn't contain required fields!");
    BigInteger p = new NativeBigInteger(1, Base64.decode(myP));
    BigInteger q = new NativeBigInteger(1, Base64.decode(myQ));
    BigInteger g = new NativeBigInteger(1, Base64.decode(myG));
    DSAGroup dg = new DSAGroup(p, q, g);
    if(dg.equals(Global.DSAgroupBigA)) return Global.DSAgroupBigA;
    return dg;
  }
View Full Code Here


      throw new EOFException();
    byte[] data = new byte[(((b1 << 8) + b2) + 8) >> 3];
    readFully(in, data, 0, data.length);
    //(new DataInputStream(in)).readFully(data, 0, data.length);
    // REDFLAG: This can't possibly be negative, right?
    return new NativeBigInteger(1, data);
  }
View Full Code Here

    if(uri.getDocName() == null)
      throw new MalformedURLException("SSK URIs must have a document name (to avoid ambiguity)");
    DSAGroup g = Global.DSAgroupBigA;
    DSAPrivateKey privKey;
    try {
      privKey = new DSAPrivateKey(new NativeBigInteger(1, uri.getRoutingKey()), g);
    } catch(IllegalArgumentException e) {
      // DSAPrivateKey is invalid
      Logger.error(InsertableClientSSK.class, "Caught "+e, e);
      throw new MalformedURLException("SSK private key (routing key) is invalid: " + e);
    }
View Full Code Here

      // Generate implicit overall hash.
      md256.update(headers, 0, x);
      md256.update(encryptedDataHash);
      byte[] overallHash = md256.digest();
      // Now sign it
      DSASignature sig = DSA.sign(pubKey.getGroup(), privKey, new NativeBigInteger(1, overallHash), r);
      // Pack R and S into 32 bytes each, and copy to headers.

      // Then create and return the ClientSSKBlock.
      byte[] rBuf = truncate(sig.getR().toByteArray(), SSKBlock.SIG_R_LENGTH);
      byte[] sBuf = truncate(sig.getS().toByteArray(), SSKBlock.SIG_S_LENGTH);
View Full Code Here

      // Makes the implicit overall hash
      byte[] overallHash = md.digest();
      SHA256.returnMessageDigest(md);
     
      // Now verify it
      NativeBigInteger r = new NativeBigInteger(1, bufR);
      NativeBigInteger s = new NativeBigInteger(1, bufS);
      if(!(DSA.verify(pubKey, new DSASignature(r, s), new NativeBigInteger(1, overallHash), false) ||
          (DSA.verify(pubKey, new DSASignature(r, s), new NativeBigInteger(1, overallHash), true)))) {
        if (dontVerify)
          Logger.error(this, "DSA verification failed with dontVerify!!!!");
        throw new SSKVerifyException("Signature verification failed for node-level SSK");
      }
    } // x isn't verified otherwise so no need to += SIG_R_LENGTH + SIG_S_LENGTH
View Full Code Here

    //}

    public DSAPrivateKey(DSAGroup g, Random r) {
        BigInteger tempX;
        do {
            tempX = new NativeBigInteger(256, r);
        } while (tempX.compareTo(g.getQ()) > -1 || tempX.compareTo(BigInteger.ZERO) < 1);
        this.x = tempX;
    }
View Full Code Here

    fs.putSingle("x", Base64.encode(x.toByteArray()));
    return fs;
  }

  public static DSAPrivateKey create(SimpleFieldSet fs, DSAGroup group) throws IllegalBase64Exception {
    NativeBigInteger y = new NativeBigInteger(1, Base64.decode(fs.get("x")));
    if(y.bitLength() > 512)
      throw new IllegalBase64Exception("Probably a pubkey");
    return new DSAPrivateKey(y, group);
  }
View Full Code Here

     */
    public DSASignature(String sig) throws NumberFormatException {
    int x=sig.indexOf(',');
    if (x <= 0)
        throw new NumberFormatException("DSA Signatures have two values");
    r = new NativeBigInteger(sig.substring(0,x), 16);
    s = new NativeBigInteger(sig.substring(x+1), 16);
    if(r.signum() != 1 || s.signum() != 1) throw new IllegalArgumentException();
    }
View Full Code Here

  /**
   * Use this constructor if you have a Hex:ed version of y already
   * available, will save some conversions and string allocations.
   */
  public DSAPublicKey(DSAGroup g, String yAsHexString) throws NumberFormatException {
    this.y = new NativeBigInteger(yAsHexString, 16);
    if(y.signum() != 1)
      throw new IllegalArgumentException();
    if(g == Global.DSAgroupBigA) g = null;
    this.group = g;
  }
View Full Code Here

    this(new ByteArrayInputStream(pubkeyBytes));
  }

  private DSAPublicKey(DSAPublicKey key) {
    fingerprint = null; // regen when needed
    this.y = new NativeBigInteger(1, key.y.toByteArray());
    DSAGroup g = key.group;
    if(g != null) g = g.cloneKey();
    this.group = g;
  }
View Full Code Here

TOP

Related Classes of net.i2p.util.NativeBigInteger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.