Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 2 | Copyright (C) 2006-2007 Werner Dittmann |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
Alexandre Lision | e24852d | 2014-02-04 13:13:02 -0500 | [diff] [blame] | 5 | it under the terms of the GNU General Public License as published by |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 6 | 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 | |
| 41 | class __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 Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 82 | /// Setpublic key value, variable length byte array |
| 83 | void setPv(uint8_t* text) { memcpy(pv, text, dhLength); }; |
| 84 | |
| 85 | /// Set first retained secretd id, fixed length byte array |
| 86 | void setRs1Id(uint8_t* text) { memcpy(DHPartHeader->rs1Id, text, sizeof(DHPartHeader->rs1Id)); }; |
| 87 | |
| 88 | /// Set second retained secretd id, fixed length byte array |
| 89 | void setRs2Id(uint8_t* text) { memcpy(DHPartHeader->rs2Id, text, sizeof(DHPartHeader->rs2Id)); }; |
| 90 | |
| 91 | /// Set additional retained secretd id, fixed length byte array |
| 92 | void setAuxSecretId(uint8_t* t) { memcpy(DHPartHeader->auxSecretId, t, sizeof(DHPartHeader->auxSecretId)); }; |
| 93 | |
| 94 | /// Set PBX retained secretd id, fixed length byte array |
| 95 | void setPbxSecretId(uint8_t* t) { memcpy(DHPartHeader->pbxSecretId,t, sizeof(DHPartHeader->pbxSecretId)); }; |
| 96 | |
| 97 | /// Set first hash (H1) of hash chain, fixed length byte array |
| 98 | void setH1(uint8_t* t) { memcpy(DHPartHeader->hashH1, t, sizeof(DHPartHeader->hashH1)); }; |
| 99 | |
| 100 | /// Set key agreement type, fixed size character array |
| 101 | void setPubKeyType(const char* pkt); |
| 102 | |
| 103 | /// Set first MAC, fixed length byte array |
| 104 | void setHMAC(uint8_t* t) { memcpy(pv+dhLength, t, 2*ZRTP_WORD_SIZE); }; |
| 105 | |
| 106 | private: |
| 107 | void initialize(); |
| 108 | // SupportedPubKeys pktype; |
| 109 | // DHPart packet is of variable length. It maximum size is 141 words: |
| 110 | // - 13 words fixed sizze |
| 111 | // - up to 128 words variable part, depending on DH algorithm |
| 112 | // leads to a maximum of 4*141=564 bytes. |
| 113 | uint8_t data[768]; // large enough to hold a full blown DHPart packet |
| 114 | }; |
| 115 | |
| 116 | /** |
| 117 | * @} |
| 118 | */ |
| 119 | #endif // ZRTPPACKETDHPART |
| 120 | |