/[classpath]/classpath/gnu/javax/crypto/DiffieHellmanImpl.java
ViewVC logotype

Diff of /classpath/gnu/javax/crypto/DiffieHellmanImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.2 by gnu_andrew, Wed Sep 21 21:32:38 2005 UTC revision 1.1.2.3 by gnu_andrew, Wed Nov 2 00:43:28 2005 UTC
# Line 67  public final class DiffieHellmanImpl ext Line 67  public final class DiffieHellmanImpl ext
67    /** The private key being used for this agreement. */    /** The private key being used for this agreement. */
68    private DHPrivateKey key;    private DHPrivateKey key;
69    
   /** The random-number generator used to generate secrets. */  
   private SecureRandom random;  
   
70    /** The current result. */    /** The current result. */
71    private BigInteger result;    private BigInteger result;
72    
# Line 80  public final class DiffieHellmanImpl ext Line 77  public final class DiffieHellmanImpl ext
77    public DiffieHellmanImpl ()    public DiffieHellmanImpl ()
78    {    {
79      key = null;      key = null;
     random = null;  
80      result = null;      result = null;
81      last_phase_done = false;      last_phase_done = false;
82    }    }
# Line 99  public final class DiffieHellmanImpl ext Line 95  public final class DiffieHellmanImpl ext
95        throw new InvalidKeyException ("expecting javax.crypto.interfaces.DHPublicKey");        throw new InvalidKeyException ("expecting javax.crypto.interfaces.DHPublicKey");
96      DHPublicKey pub = (DHPublicKey) incoming;      DHPublicKey pub = (DHPublicKey) incoming;
97      DHParameterSpec s1 = key.getParams();      DHParameterSpec s1 = key.getParams();
98      DHParameterSpec s2 = key.getParams();      DHParameterSpec s2 = pub.getParams();
99      if (!s1.getG().equals (s2.getG())      if (!s1.getG().equals (s2.getG())
100          || !s1.getP().equals (s2.getP())          || !s1.getP().equals (s2.getP())
101          || s1.getL() != s2.getL())          || s1.getL() != s2.getL())
102        throw new InvalidKeyException ("supplied key is not compatible");        throw new InvalidKeyException ("supplied key is not compatible");
103    
104      BigInteger randval = new BigInteger (s1.getL(), random);      result = pub.getY().modPow (key.getX(), s1.getP());
     BigInteger out = s1.getG().modPow (key.getX(), s1.getP());  
     if (result == null)  
       result = s1.getG();  
     result = result.modPow (pub.getY(), s1.getP());  
105      if (lastPhase)      if (lastPhase)
106        {        {
107          last_phase_done = true;          last_phase_done = true;
108          return null;          return null;
109        }        }
110      return new GnuDHPublicKey (s1, out, null);  
111        throw new IllegalArgumentException ("only supports two-party Diffie Hellman");
112    }    }
113    
114    protected byte[] engineGenerateSecret ()    protected byte[] engineGenerateSecret ()
# Line 153  public final class DiffieHellmanImpl ext Line 146  public final class DiffieHellmanImpl ext
146      if (!(key instanceof DHPrivateKey))      if (!(key instanceof DHPrivateKey))
147        throw new InvalidKeyException ("not a javax.crypto.interfaces.DHPrivateKey");        throw new InvalidKeyException ("not a javax.crypto.interfaces.DHPrivateKey");
148      this.key = (DHPrivateKey) key;      this.key = (DHPrivateKey) key;
     if (random != null)  
       this.random = random;  
     else if (this.random == null)  
       this.random = new SecureRandom();  
149      result = null;      result = null;
150      last_phase_done = false;      last_phase_done = false;
151    }    }

Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26