MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dh.hpp
1 /*
2  Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to the
15  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
16  MA 02110-1301 USA.
17 */
18 
19 /* dh.hpp provides Diffie-Hellman support
20 */
21 
22 
23 #ifndef TAO_CRYPT_DH_HPP
24 #define TAO_CRYPT_DH_HPP
25 
26 #include "misc.hpp"
27 #include "integer.hpp"
28 
29 namespace TaoCrypt {
30 
31 
32 class Source;
33 
34 
35 // Diffie-Hellman
36 class DH {
37 public:
38  DH() {}
39  DH(Integer& p, Integer& g) : p_(p), g_(g) {}
40  explicit DH(Source&);
41 
42  DH(const DH& that) : p_(that.p_), g_(that.g_) {}
43  DH& operator=(const DH& that)
44  {
45  DH tmp(that);
46  Swap(tmp);
47  return *this;
48  }
49 
50  void Swap(DH& other)
51  {
52  p_.Swap(other.p_);
53  g_.Swap(other.g_);
54  }
55 
56  void Initialize(Source&);
57  void Initialize(Integer& p, Integer& g)
58  {
59  SetP(p);
60  SetG(g);
61  }
62 
63  void GenerateKeyPair(RandomNumberGenerator&, byte*, byte*);
64  void Agree(byte*, const byte*, const byte*, word32 otherSz = 0);
65 
66  void SetP(const Integer& p) { p_ = p; }
67  void SetG(const Integer& g) { g_ = g; }
68 
69  Integer& GetP() { return p_; }
70  Integer& GetG() { return g_; }
71 
72  // for p and agree
73  word32 GetByteLength() const { return p_.ByteCount(); }
74 private:
75  // group parms
76  Integer p_;
77  Integer g_;
78 
79  void GeneratePrivate(RandomNumberGenerator&, byte*);
80  void GeneratePublic(const byte*, byte*);
81 };
82 
83 
84 } // namespace
85 
86 #endif // TAO_CRYPT_DH_HPP