Main Page | Class Hierarchy | Class List | File List | Class Members

/Users/baford/proj/netsteria/sst/lib/dh.h

00001 #ifndef SST_DH_H
00002 #define SST_DH_H
00003 
00004 #include <QObject>
00005 #include <QHash>
00006 
00007 #include <openssl/dh.h>
00008 
00009 #include "timer.h"
00010 
00011 
00012 namespace SST {
00013 
00014 
00015 #define HOSTKEY_TIMEOUT         (60*60) // Host key timeout in seconds - 1 hr
00016 
00017 #define KEYGROUP_JFDH_1024      0x01
00018 #define KEYGROUP_JFDH_2048      0x02
00019 #define KEYGROUP_JFDH_3072      0x03
00020 #define KEYGROUP_JFDH_MAX       0x03
00021 #define KEYGROUP_JFDH_DEFAULT   KEYGROUP_JFDH_1024
00022 
00023 class Host;
00024 
00025 class DHKey : public QObject
00026 {
00027         friend class DHHostState;
00028         friend class KeyInitiator;      // XX
00029         friend class KeyResponder;      // XX
00030 
00031         Q_OBJECT
00032 
00033 private:
00034         Host *const host;       
00035         Timer exptimer;         
00036 
00037         quint8 dhgroup;
00038         DH *dh;
00039         QByteArray pubkey;
00040         quint8 hkr[256/8];      // HMAC key for responder's challenge
00041 
00042         // Hash table of cached R2 responses made using this key,
00043         // for replay protection.
00044         QHash<QByteArray, QByteArray> r2cache;
00045 
00046 
00047 public:
00048         // Compute a shared master secret from our private key and otherPubKey.
00049         QByteArray calcKey(const QByteArray &otherPubKey);
00050 
00051 private:
00052         DHKey(Host *host, quint8 dhgroup, DH *dh,
00053                 int timeoutSecs = HOSTKEY_TIMEOUT);
00054 
00055 private slots:
00056         void timeout();
00057 };
00058 
00059 
00060 // Per-host state for the DH key agreement module.
00061 class DHHostState
00062 {
00063         friend class DHKey;
00064 
00065 private:
00066         DHKey *dhkeys[KEYGROUP_JFDH_MAX];
00067 
00068         DHKey *gen(quint8 dhgroup, DH *(*groupfunc)());
00069 
00070 public:
00071         DHHostState();
00072         virtual ~DHHostState();
00073 
00074         DHKey *getDHKey(quint8 dhgroup);
00075 
00076         virtual Host *host() = 0;
00077 };
00078 
00079 
00080 QDataStream &operator<<(QDataStream &ds, DH *dh);
00081 QDataStream &operator>>(QDataStream &ds, DH *dh);
00082 
00083 
00084 } // namespace SST
00085 
00086 #endif  // SST_DH_H

Generated on Wed Mar 28 11:48:05 2007 for SST by doxygen 1.3.4