00001 /* dh.hpp 00002 * 00003 * Copyright (C) 2003 Sawtooth Consulting Ltd. 00004 * 00005 * This file is part of yaSSL. 00006 * 00007 * yaSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * There are special exceptions to the terms and conditions of the GPL as it 00013 * is applied to yaSSL. View the full text of the exception in the file 00014 * FLOSS-EXCEPTIONS in the directory of this software distribution. 00015 * 00016 * yaSSL is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00024 */ 00025 00026 /* dh.hpp provides Diffie-Hellman support 00027 */ 00028 00029 00030 #ifndef TAO_CRYPT_DH_HPP 00031 #define TAO_CRYPT_DH_HPP 00032 00033 #include "misc.hpp" 00034 #include "integer.hpp" 00035 00036 namespace TaoCrypt { 00037 00038 00039 class Source; 00040 00041 00042 // Diffie-Hellman 00043 class DH { 00044 public: 00045 DH() {} 00046 DH(Integer& p, Integer& g) : p_(p), g_(g) {} 00047 explicit DH(Source&); 00048 00049 DH(const DH& that) : p_(that.p_), g_(that.g_) {} 00050 DH& operator=(const DH& that) 00051 { 00052 DH tmp(that); 00053 Swap(tmp); 00054 return *this; 00055 } 00056 00057 void Swap(DH& other) 00058 { 00059 p_.Swap(other.p_); 00060 g_.Swap(other.g_); 00061 } 00062 00063 void Initialize(Source&); 00064 void Initialize(Integer& p, Integer& g) 00065 { 00066 SetP(p); 00067 SetG(g); 00068 } 00069 00070 void GenerateKeyPair(RandomNumberGenerator&, byte*, byte*); 00071 void Agree(byte*, const byte*, const byte*, word32 otherSz = 0); 00072 00073 void SetP(const Integer& p) { p_ = p; } 00074 void SetG(const Integer& g) { g_ = g; } 00075 00076 Integer& GetP() { return p_; } 00077 Integer& GetG() { return g_; } 00078 00079 // for p and agree 00080 word32 GetByteLength() const { return p_.ByteCount(); } 00081 private: 00082 // group parms 00083 Integer p_; 00084 Integer g_; 00085 00086 void GeneratePrivate(RandomNumberGenerator&, byte*); 00087 void GeneratePublic(const byte*, byte*); 00088 }; 00089 00090 00091 } // namespace 00092 00093 #endif // TAO_CRYPT_DH_HPP
1.4.7

