Package freenet.crypt

Examples of freenet.crypt.DiffieHellmanLightContext


    byte[] computedExponential;
    if(negType < 8) { // Legacy DH
      NativeBigInteger _hisExponential = new NativeBigInteger(1, initiatorExponential);
      NativeBigInteger _ourExponential = new NativeBigInteger(1, responderExponential);

      DiffieHellmanLightContext ctx = findContextByExponential(_ourExponential);
      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(_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


  public boolean alwaysAllowLocalAddresses() {
    return crypto.config.alwaysAllowLocalAddresses();
  }

  private DiffieHellmanLightContext _genLightDiffieHellmanContext() {
    final DiffieHellmanLightContext ctx = DiffieHellman.generateLightContext(dhGroupToUse);
    if(logDEBUG) Logger.debug(this, "Signing for DiffieHellman: "+HexUtil.bytesToHex(SHA256.digest(assembleDHParams(ctx.getPublicKeyNetworkFormat(), crypto.getCryptoGroup())))+" for "+HexUtil.bytesToHex(assembleDHParams(ctx.getPublicKeyNetworkFormat(), crypto.getCryptoGroup())));
    ctx.setDSASignature(crypto.sign(SHA256.digest(assembleDHParams(ctx.getPublicKeyNetworkFormat(), crypto.getCryptoGroup()))));

    return ctx;
  }
View Full Code Here

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

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

   *
   * @return {@link DiffieHellmanLightContext}
   */
  private DiffieHellmanLightContext getLightDiffieHellmanContext() {
    final long now = System.currentTimeMillis();
    DiffieHellmanLightContext result = null;

    synchronized (dhContextFIFO) {
      result = dhContextFIFO.pollFirst();

      // Shall we replace one element of the queue ?
      if((jfkDHLastGenerationTimestamp + DH_GENERATION_INTERVAL) < now) {
        jfkDHLastGenerationTimestamp = now;
        _fillJFKDHFIFOOffThread();
      }

            // If we didn't get any, generate on-thread
            if(result == null)
                result = _genLightDiffieHellmanContext();
           
      dhContextFIFO.addLast(result);
    }

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

TOP

Related Classes of freenet.crypt.DiffieHellmanLightContext

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.