Package freenet.crypt

Examples of freenet.crypt.ECDHLightContext


      }
      computedExponential = ctx.getHMACKey(_hisExponential);
        } else {
            ECPublicKey initiatorKey = ECDH.getPublicKey(initiatorExponential, ecdhCurveToUse);
            ECPublicKey responderKey = ECDH.getPublicKey(responderExponential, ecdhCurveToUse);
            ECDHLightContext ctx = findECDHContextByPubKey(responderKey);
            if (ctx == null) {
                Logger.error(this, "WTF? the HMAC verified but we don't know about that exponential! SHOULDN'T HAPPEN! - JFK3 - "+pn);
                // Possible this is a replay or severely delayed? We don't keep
                // every exponential we ever use.
                return;
            }
            computedExponential = ctx.getHMACKey(initiatorKey);
        }
    if(logDEBUG) Logger.debug(this, "The shared Master secret is : "+HexUtil.bytesToHex(computedExponential) +" for " + pn);
   
    /* 0 is the outgoing key for the initiator, 7 for the responder */
    byte[] outgoingKey = computeJFKSharedKey(computedExponential, nonceInitiatorHashed, nonceResponder, "7");
View Full Code Here


    return ctx;
  }
   
  private ECDHLightContext _genECDHLightContext() {
        final ECDHLightContext ctx = new ECDHLightContext(ecdhCurveToUse);
        ctx.setECDSASignature(crypto.ecdsaSign(ctx.getPublicKeyNetworkFormat()));
        ctx.setDSASignature(crypto.sign(SHA256.digest(assembleDHParams(ctx.getPublicKeyNetworkFormat(), crypto.getCryptoGroup()))));
        if(logDEBUG) Logger.debug(this, "ECDSA Signature: "+HexUtil.bytesToHex(ctx.ecdsaSig)+" for "+HexUtil.bytesToHex(ctx.getPublicKeyNetworkFormat()));
        return ctx;
    }
View Full Code Here

   
  private void _fillJFKECDHFIFO() {
        synchronized (ecdhContextFIFO) {
            int size = ecdhContextFIFO.size();
            if((size > 0) && (size + 1 > DH_CONTEXT_BUFFER_SIZE)) {
                ECDHLightContext result = null;
                long oldestSeen = Long.MAX_VALUE;

                for (ECDHLightContext tmp: ecdhContextFIFO) {
                    if(tmp.lifetime < oldestSeen) {
                        oldestSeen = tmp.lifetime;
View Full Code Here

     * @return {@link ECDHLightContext}
     * @throws NoContextsException
     */
    private ECDHLightContext getECDHLightContext() throws NoContextsException {
        final long now = System.currentTimeMillis();
        ECDHLightContext result = null;

        synchronized (ecdhContextFIFO) {
            result = ecdhContextFIFO.pollFirst();
           
            // Shall we replace one element of the queue ?
            if((jfkECDHLastGenerationTimestamp + DH_GENERATION_INTERVAL) < now) {
                jfkECDHLastGenerationTimestamp = now;
                _fillJFKECDHFIFOOffThread();
            }
           
            // Don't generate on-thread as it might block.
            if(result == null)
                throw new NoContextsException();

            ecdhContextFIFO.addLast(result);
        }

        if(logMINOR) Logger.minor(this, "getECDHLightContext() is serving "+result.hashCode());
        return result;
    }
View Full Code Here

TOP

Related Classes of freenet.crypt.ECDHLightContext

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.