00001 using System; 00002 using Org.Mentalis.Security.Cryptography; //For DiffieHellman usage 00003 00004 00005 namespace Tamir.SharpSsh.jsch.jce 00006 { 00007 /* -*-mode:java; c-basic-offset:2; -*- */ 00008 /* 00009 Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 1. Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in 00019 the documentation and/or other materials provided with the distribution. 00020 00021 3. The names of the authors may not be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 00025 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00026 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, 00027 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00030 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00032 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00033 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 00036 public class DH : Tamir.SharpSsh.jsch.DH 00037 { 00038 internal byte[] p; 00039 internal byte[] g; 00040 internal byte[] e; // my public key 00041 internal byte[] e_array; 00042 internal byte[] f; // your public key 00043 internal byte[] K; // shared secret key 00044 internal byte[] K_array; 00045 00046 private DiffieHellman dh; 00047 public void init() 00048 { 00049 } 00050 public byte[] getE() 00051 { 00052 if(e_array==null) 00053 { 00054 00055 dh = new DiffieHellmanManaged(p , g, 0); 00056 e_array = dh.CreateKeyExchange(); 00057 } 00058 return e_array; 00059 } 00060 public byte[] getK() 00061 { 00062 if(K_array==null) 00063 { 00064 K_array = dh.DecryptKeyExchange( f); 00065 } 00066 return K_array; 00067 } 00068 public void setP(byte[] p){ this.p=p; } 00069 public void setG(byte[] g){ this.g=g; } 00070 public void setF(byte[] f){ this.f=f; } 00071 // void setP(BigInteger p){this.p=p;} 00072 // void setG(BigInteger g){this.g=g;} 00073 // void setF(BigInteger f){this.f=f;} 00074 } 00075 00076 }
1.5.9