blob: 08737a56b140feb4c264b2894d79161e9aef40e9 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05002 Copyright (C) 2006-2013 Werner Dittmann
Alexandre Lision51140e12013-12-02 10:54:09 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05005 it under the terms of the GNU Lesser General Public License as published by
Alexandre Lision51140e12013-12-02 10:54:09 -05006 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef _ZRTPPACKETDHPART_H_
19#define _ZRTPPACKETDHPART_H_
20
21/**
22 * @file ZrtpPacketDHPart.h
23 * @brief The ZRTP DHPart message
24 *
25 * @ingroup GNU_ZRTP
26 * @{
27 */
28
29#include <libzrtpcpp/ZrtpPacketBase.h>
30
31/**
32 * Implement the DHPart packet.
33 *
34 * The ZRTP message DHPart. The implementation sends this
35 * to exchange the Diffie-Helman public keys and the shared
36 * secrets between the two parties.
37 *
38 * @author Werner Dittmann <Werner.Dittmann@t-online.de>
39 */
40
41class __EXPORT ZrtpPacketDHPart : public ZrtpPacketBase {
42
43 protected:
44 uint8_t *pv; ///< points to public key value inside DH message
45 DHPart_t* DHPartHeader; ///< points to DH message structure
46 int32_t dhLength; ///< length of DH message, DH message has variable length
47
48 public:
49 /// Creates a DHPart packet no data, must use setPubKeyType(...)
50 ZrtpPacketDHPart();
51
52 /// Creates a DHPart packet with default data and a give public key type
53 ZrtpPacketDHPart(const char* pkt);
54
55 /// Creates a DHPart packet from received data
56 ZrtpPacketDHPart(uint8_t* data);
57
58 /// Standard destructor
59 virtual ~ZrtpPacketDHPart();
60
61 /// Get pointer to public key value, variable length byte array
62 uint8_t* getPv() { return pv; }
63
64 /// Get pointer to first retained secretd id, fixed length byte array
65 uint8_t* getRs1Id() { return DHPartHeader->rs1Id; };
66
67 /// Get pointer to second retained secretd id, fixed length byte array
68 uint8_t* getRs2Id() { return DHPartHeader->rs2Id; };
69
70 /// Get pointer to additional retained secretd id, fixed length byte array
71 uint8_t* getAuxSecretId() { return DHPartHeader->auxSecretId; };
72
73 /// Get pointer to PBX retained secretd id, fixed length byte array
74 uint8_t* getPbxSecretId() { return DHPartHeader->pbxSecretId; };
75
76 /// Get pointer to first hash (H1) for hash chain, fixed length byte array
77 uint8_t* getH1() { return DHPartHeader->hashH1; };
78
79 /// Get pointer to HMAC, fixed length byte array
80 uint8_t* getHMAC() { return pv+dhLength; };
81
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050082 /// Check if packet length makes sense. DHPart packets are 29 words at minumum, using E255
83 bool isLengthOk() {return (getLength() >= 29);}
84
Alexandre Lision51140e12013-12-02 10:54:09 -050085 /// Setpublic key value, variable length byte array
86 void setPv(uint8_t* text) { memcpy(pv, text, dhLength); };
87
88 /// Set first retained secretd id, fixed length byte array
89 void setRs1Id(uint8_t* text) { memcpy(DHPartHeader->rs1Id, text, sizeof(DHPartHeader->rs1Id)); };
90
91 /// Set second retained secretd id, fixed length byte array
92 void setRs2Id(uint8_t* text) { memcpy(DHPartHeader->rs2Id, text, sizeof(DHPartHeader->rs2Id)); };
93
94 /// Set additional retained secretd id, fixed length byte array
95 void setAuxSecretId(uint8_t* t) { memcpy(DHPartHeader->auxSecretId, t, sizeof(DHPartHeader->auxSecretId)); };
96
97 /// Set PBX retained secretd id, fixed length byte array
98 void setPbxSecretId(uint8_t* t) { memcpy(DHPartHeader->pbxSecretId,t, sizeof(DHPartHeader->pbxSecretId)); };
99
100 /// Set first hash (H1) of hash chain, fixed length byte array
101 void setH1(uint8_t* t) { memcpy(DHPartHeader->hashH1, t, sizeof(DHPartHeader->hashH1)); };
102
103 /// Set key agreement type, fixed size character array
104 void setPubKeyType(const char* pkt);
105
106 /// Set first MAC, fixed length byte array
107 void setHMAC(uint8_t* t) { memcpy(pv+dhLength, t, 2*ZRTP_WORD_SIZE); };
108
109 private:
110 void initialize();
111 // SupportedPubKeys pktype;
112 // DHPart packet is of variable length. It maximum size is 141 words:
113 // - 13 words fixed sizze
114 // - up to 128 words variable part, depending on DH algorithm
115 // leads to a maximum of 4*141=564 bytes.
116 uint8_t data[768]; // large enough to hold a full blown DHPart packet
117};
118
119/**
120 * @}
121 */
122#endif // ZRTPPACKETDHPART
123