Package freenet.crypt

Examples of freenet.crypt.DSASignature


        // Verify the DSA signature
        byte[] r = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
        byte[] s = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
        System.arraycopy(sig, 0, r, 0, Node.SIGNATURE_PARAMETER_LENGTH);
        System.arraycopy(sig, Node.SIGNATURE_PARAMETER_LENGTH, s, 0, Node.SIGNATURE_PARAMETER_LENGTH);
        DSASignature remoteSignature = new DSASignature(new NativeBigInteger(1,r), new NativeBigInteger(1,s));
        // At that point we don't know if it's "him"; let's check it out
        byte[] locallyExpectedExponentials =  assembleDHParams(hisExponential, pn.peerCryptoGroup);

        if(!DSA.verify(pn.peerPubKey, remoteSignature, new NativeBigInteger(1, SHA256.digest(locallyExpectedExponentials)), false)) {
            Logger.error(this, "The signature verification has failed in JFK(2)!! "+pn.getPeer());
View Full Code Here


    if(negType < 9) {
        byte[] r = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
        System.arraycopy(sig, 0, r, 0, Node.SIGNATURE_PARAMETER_LENGTH);
            byte[] s = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
            System.arraycopy(sig, Node.SIGNATURE_PARAMETER_LENGTH, s, 0, Node.SIGNATURE_PARAMETER_LENGTH);
        DSASignature remoteSignature = new DSASignature(new NativeBigInteger(1,r), new NativeBigInteger(1,s));
        if(!DSA.verify(pn.peerPubKey, remoteSignature, new NativeBigInteger(1, SHA256.digest(toVerify)), false)) {
            Logger.error(this, "The signature verification has failed!! JFK(3) - "+pn.getPeer());
            return;
        }
    } else {
View Full Code Here

      if(negType < 9) { // DSA sig    
          byte[] r = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
          System.arraycopy(sig, 0, r, 0, Node.SIGNATURE_PARAMETER_LENGTH);
          byte[] s = new byte[Node.SIGNATURE_PARAMETER_LENGTH];
          System.arraycopy(sig, Node.SIGNATURE_PARAMETER_LENGTH, s, 0, Node.SIGNATURE_PARAMETER_LENGTH);
          DSASignature remoteSignature = new DSASignature(new NativeBigInteger(1,r), new NativeBigInteger(1,s));
          byte[] messageHash = SHA256.digest(locallyGeneratedText);
          if(!DSA.verify(pn.peerPubKey, remoteSignature, new NativeBigInteger(1, messageHash), false)) {
              String error = "The signature verification has failed!! JFK(4) -"+pn.getPeer()+" message hash "+HexUtil.bytesToHex(messageHash)+" length "+locallyGeneratedText.length+" hisRef "+hisRef.length+" hash "+Fields.hashCode(hisRef)+" myRef "+pn.jfkMyRef.length+" hash "+Fields.hashCode(pn.jfkMyRef)+" boot ID "+bootID;
              Logger.error(this, error);
              return true;
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);
      System.arraycopy(rBuf, 0, headers, x, rBuf.length);
      x += rBuf.length;
      System.arraycopy(sBuf, 0, headers, x, sBuf.length);
      x += sBuf.length;
      if (x != SSKBlock.TOTAL_HEADERS_LENGTH)
View Full Code Here

      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

                }
               
                // Is there an old DSA sig?
                if(isDSAsigPresent) {
                    fs.putSingle("sig", signature);
                    verifyDSA = DSA.verify(peerPubKey, new DSASignature(signature), new BigInteger(1, SHA256.digest(toVerifyDSA)), false);
                }

                // If there is no signature, FAIL
                // If there is an ECDSA signature, and it doesn't verify, FAIL
                // If there is a DSA signature, and it doesn't verify, FAIL
View Full Code Here

    try{
      byte[] ref = mySignedReference.getBytes("UTF-8");
      BigInteger m = new BigInteger(1, SHA256.digest(ref));
      if(logMINOR) Logger.minor(this, "m = "+m.toString(16));
      DSASignature _signature = DSA.sign(cryptoGroup, privKey, m, random);
      if(logMINOR && !DSA.verify(pubKey, _signature, m, false))
        throw new NodeInitException(NodeInitException.EXIT_EXCEPTION_TO_DEBUG, mySignedReference);
      return _signature;
    } catch(UnsupportedEncodingException e){
      throw new NodeInitException(NodeInitException.EXIT_CRAPPY_JVM, "Impossible: JVM doesn't support UTF-8");
View Full Code Here

  }

  /** Sign a hash */
  byte[] sign(byte[] hash) {
        byte[] sig = new byte[Node.SIGNATURE_PARAMETER_LENGTH*2];
        DSASignature s = DSA.sign(cryptoGroup, privKey, new NativeBigInteger(1, hash), random);
        System.arraycopy(s.getRBytes(Node.SIGNATURE_PARAMETER_LENGTH), 0, sig, 0, Node.SIGNATURE_PARAMETER_LENGTH);
        System.arraycopy(s.getSBytes(Node.SIGNATURE_PARAMETER_LENGTH), 0, sig, Node.SIGNATURE_PARAMETER_LENGTH, Node.SIGNATURE_PARAMETER_LENGTH);
    return sig;
  }
View Full Code Here

TOP

Related Classes of freenet.crypt.DSASignature

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.