00001 /* dsa.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 /* dsa.hpp provides Digitial Signautre Algorithm see FIPS 186-2 00027 */ 00028 00029 #ifndef TAO_CRYPT_DSA_HPP 00030 #define TAO_CRYPT_DSA_HPP 00031 00032 #include "integer.hpp" 00033 00034 00035 namespace TaoCrypt { 00036 00037 class Source; 00038 00039 00040 class DSA_PublicKey { 00041 protected: 00042 Integer p_; 00043 Integer q_; 00044 Integer g_; 00045 Integer y_; 00046 public: 00047 DSA_PublicKey() {} 00048 explicit DSA_PublicKey(Source&); 00049 00050 void Initialize(Source&); 00051 void Initialize(const Integer& p, const Integer& q, const Integer& g, 00052 const Integer& y); 00053 00054 const Integer& GetModulus() const; 00055 const Integer& GetSubGroupOrder() const; 00056 const Integer& GetSubGroupGenerator() const; 00057 const Integer& GetPublicPart() const; 00058 00059 void SetModulus(const Integer&); 00060 void SetSubGroupOrder(const Integer&); 00061 void SetSubGroupGenerator(const Integer&); 00062 void SetPublicPart(const Integer&); 00063 00064 word32 SignatureLength() const; 00065 00066 DSA_PublicKey(const DSA_PublicKey&); 00067 DSA_PublicKey& operator=(const DSA_PublicKey&); 00068 00069 void Swap(DSA_PublicKey& other); 00070 }; 00071 00072 00073 00074 class DSA_PrivateKey : public DSA_PublicKey { 00075 Integer x_; 00076 public: 00077 DSA_PrivateKey() {} 00078 explicit DSA_PrivateKey(Source&); 00079 00080 void Initialize(Source&); 00081 void Initialize(const Integer& p, const Integer& q, const Integer& g, 00082 const Integer& y, const Integer& x); 00083 00084 const Integer& GetPrivatePart() const; 00085 00086 void SetPrivatePart(const Integer&); 00087 private: 00088 DSA_PrivateKey(const DSA_PrivateKey&); // hide copy 00089 DSA_PrivateKey& operator=(const DSA_PrivateKey&); // and assign 00090 }; 00091 00092 00093 00094 class DSA_Signer { 00095 const DSA_PrivateKey& key_; 00096 Integer r_; 00097 Integer s_; 00098 public: 00099 explicit DSA_Signer(const DSA_PrivateKey&); 00100 00101 word32 Sign(const byte* sha_digest, byte* sig, RandomNumberGenerator&); 00102 00103 const Integer& GetR() const; 00104 const Integer& GetS() const; 00105 private: 00106 DSA_Signer(const DSA_Signer&); // hide copy 00107 DSA_Signer& operator=(DSA_Signer&); // and assign 00108 }; 00109 00110 00111 class DSA_Verifier { 00112 const DSA_PublicKey& key_; 00113 Integer r_; 00114 Integer s_; 00115 public: 00116 explicit DSA_Verifier(const DSA_PublicKey&); 00117 00118 bool Verify(const byte* sha_digest, const byte* sig); 00119 00120 const Integer& GetR() const; 00121 const Integer& GetS() const; 00122 private: 00123 DSA_Verifier(const DSA_Verifier&); // hide copy 00124 DSA_Verifier& operator=(const DSA_Verifier&); // and assign 00125 }; 00126 00127 00128 00129 00130 00131 } // namespace 00132 00133 #endif // TAO_CRYPT_DSA_HPP
1.4.7

