mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juan Antonio Nazabal Urriza <janaza...@yandex.com>
Subject possible SSHD-704 fix
Date Fri, 23 Mar 2018 14:20:06 GMT

import djb.Curve25519;
import java.security.SecureRandom;
import org.apache.sshd.common.digest.BuiltinDigests;
import org.apache.sshd.common.digest.Digest;
import org.apache.sshd.common.kex.AbstractDH;


public class Curve25519SHA256AbstractDH extends AbstractDH
 {

 private final byte q_s[]=new byte[32]; //server's ephemeral public key octet string
 private final byte q_c[]=new byte[32]; // //client's ephemeral public key octet string
 private final byte privatekeyforkeyagreement[]=new byte[32];
 private final byte k_as_byte_array[]=new byte[32];
 
 public Curve25519SHA256AbstractDH(SecureRandom securerandom) throws Exception
  {
  super();
  //generate public key and private key for key agreement
  securerandom.nextBytes(privatekeyforkeyagreement);
  Curve25519.keygen(q_s, null, privatekeyforkeyagreement);
  }
 
 @Override
 public void setF(byte[] bytes) 
  {
  System.arraycopy(bytes, 0, q_c, 0, bytes.length);
  }

 @Override
 public byte[] getE() throws Exception 
  {
  return q_s;
  }

 @Override
 protected byte[] calculateK() throws Exception 
  {
  //create shared secret
  Curve25519.curve(k_as_byte_array, privatekeyforkeyagreement, q_c);
  //The whole 32 bytes need to be converted into a big integer following the network byte
order
  return stripLeadingZeroes(k_as_byte_array);
  }

 @Override
 public Digest getHash() throws Exception 
  {
  return BuiltinDigests.sha256.create();
  }
 
 }
Mime
View raw message