1 /* 2 Copyright (C) 2006-2013 Werner Dittmann 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as published by 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 /* 19 * Authors: Werner Dittmann <Werner.Dittmann@t-online.de> 20 */ 21 #ifndef _ZRTPPACKETCOMMIT_H_ 22 #define _ZRTPPACKETCOMMIT_H_ 23 24 /** 25 * @file ZrtpPacketCommit.h 26 * @brief The ZRTP Commit message 27 * 28 * @ingroup GNU_ZRTP 29 * @{ 30 */ 31 32 #include <libzrtpcpp/ZrtpPacketBase.h> 33 34 // PRSH here only for completeness. We don't support PRSH in the other ZRTP parts. 35 #define COMMIT_DH_EX 29 36 #define COMMIT_MULTI 25 37 #define COMMIT_PRSH 27 38 39 /** 40 * Implement the Commit packet. 41 * 42 * The ZRTP message Commit. The ZRTP implementation sends or receives 43 * this message to commit the crypto parameters offered during a Hello 44 * message. 45 * 46 * 47 * @author Werner Dittmann <Werner.Dittmann@t-online.de> 48 */ 49 50 class __EXPORT ZrtpPacketCommit : public ZrtpPacketBase { 51 52 protected: 53 Commit_t* commitHeader; ///< Points to Commit message part 54 55 public: 56 typedef enum _commitType { 57 DhExchange = 1, 58 MultiStream = 2 59 } commitType; 60 61 /// Creates a Commit packet with default data 62 ZrtpPacketCommit(); 63 64 /// Creates a Commit packet from received data 65 ZrtpPacketCommit(uint8_t* data); 66 67 /// Normal destructor 68 virtual ~ZrtpPacketCommit(); 69 70 /// Get pointer to hash algorithm type field, a fixed length character array getHashType()71 uint8_t* getHashType() { return commitHeader->hash; }; 72 73 /// Get pointer to cipher algorithm type field, a fixed length character array getCipherType()74 uint8_t* getCipherType() { return commitHeader->cipher; }; 75 76 /// Get pointer to SRTP authentication algorithm type field, a fixed length character array getAuthLen()77 uint8_t* getAuthLen() { return commitHeader->authlengths; }; 78 79 /// Get pointer to key agreement algorithm type field, a fixed length character array getPubKeysType()80 uint8_t* getPubKeysType() { return commitHeader->pubkey; }; 81 82 /// Get pointer to SAS algorithm type field, a fixed length character array getSasType()83 uint8_t* getSasType() { return commitHeader->sas; }; 84 85 /// Get pointer to ZID field, a fixed length byte array getZid()86 uint8_t* getZid() { return commitHeader->zid; }; 87 88 /// Get pointer to HVI field, a fixed length byte array getHvi()89 uint8_t* getHvi() { return commitHeader->hvi; }; 90 91 /// Get pointer to NONCE field, a fixed length byte array, overlaps HVI field getNonce()92 uint8_t* getNonce() { return commitHeader->hvi; }; 93 94 /// Get pointer to hashH2 field, a fixed length byte array getH2()95 uint8_t* getH2() { return commitHeader->hashH2; }; 96 97 /// Get pointer to MAC field, a fixed length byte array getHMAC()98 uint8_t* getHMAC() { return commitHeader->hmac; }; 99 100 /// Get pointer to MAC field during multi-stream mode, a fixed length byte array getHMACMulti()101 uint8_t* getHMACMulti() { return commitHeader->hmac-4*ZRTP_WORD_SIZE; }; 102 103 /// Check if packet length makes sense. isLengthOk(commitType type)104 bool isLengthOk(commitType type) {int32_t len = getLength(); 105 return ((type == DhExchange) ? len == COMMIT_DH_EX : len == COMMIT_MULTI);} 106 107 /// Set hash algorithm type field, fixed length character field setHashType(uint8_t * text)108 void setHashType(uint8_t* text) { memcpy(commitHeader->hash, text, ZRTP_WORD_SIZE); }; 109 110 /// Set cipher algorithm type field, fixed length character field setCipherType(uint8_t * text)111 void setCipherType(uint8_t* text) { memcpy(commitHeader->cipher, text, ZRTP_WORD_SIZE); }; 112 113 /// Set SRTP authentication algorithm algorithm type field, fixed length character field setAuthLen(uint8_t * text)114 void setAuthLen(uint8_t* text) { memcpy(commitHeader->authlengths, text, ZRTP_WORD_SIZE); }; 115 116 /// Set key agreement algorithm type field, fixed length character field setPubKeyType(uint8_t * text)117 void setPubKeyType(uint8_t* text) { memcpy(commitHeader->pubkey, text, ZRTP_WORD_SIZE); }; 118 119 /// Set SAS algorithm type field, fixed length character field setSasType(uint8_t * text)120 void setSasType(uint8_t* text) { memcpy(commitHeader->sas, text, ZRTP_WORD_SIZE); }; 121 122 /// Set ZID field, a fixed length byte array setZid(uint8_t * text)123 void setZid(uint8_t* text) { memcpy(commitHeader->zid, text, sizeof(commitHeader->zid)); }; 124 125 /// Set HVI field, a fixed length byte array setHvi(uint8_t * text)126 void setHvi(uint8_t* text) { memcpy(commitHeader->hvi, text, sizeof(commitHeader->hvi)); }; 127 128 /// Set conce field, a fixed length byte array, overlapping HVI field 129 void setNonce(uint8_t* text); 130 131 /// Set hashH2 field, a fixed length byte array setH2(uint8_t * hash)132 void setH2(uint8_t* hash) { memcpy(commitHeader->hashH2, hash, sizeof(commitHeader->hashH2)); }; 133 134 /// Set MAC field, a fixed length byte array setHMAC(uint8_t * hash)135 void setHMAC(uint8_t* hash) { memcpy(commitHeader->hmac, hash, sizeof(commitHeader->hmac)); }; 136 137 /// Set MAC field during multi-stream mode, a fixed length byte array setHMACMulti(uint8_t * hash)138 void setHMACMulti(uint8_t* hash) { memcpy(commitHeader->hmac-4*ZRTP_WORD_SIZE, hash, sizeof(commitHeader->hmac)); }; 139 140 private: 141 CommitPacket_t data; 142 }; 143 144 /** 145 * @} 146 */ 147 #endif // ZRTPPACKETCOMMIT 148 149