Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame^] | 2 | Copyright (C) 2006-2013 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 | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame^] | 5 | it under the terms of the GNU Lesser 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 | /* |
| 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 | |
Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame^] | 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 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 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: |
Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame^] | 56 | typedef enum _commitType { |
| 57 | DhExchange = 1, |
| 58 | MultiStream = 2 |
| 59 | } commitType; |
| 60 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 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 |
| 71 | uint8_t* getHashType() { return commitHeader->hash; }; |
| 72 | |
| 73 | /// Get pointer to cipher algorithm type field, a fixed length character array |
| 74 | uint8_t* getCipherType() { return commitHeader->cipher; }; |
| 75 | |
| 76 | /// Get pointer to SRTP authentication algorithm type field, a fixed length character array |
| 77 | uint8_t* getAuthLen() { return commitHeader->authlengths; }; |
| 78 | |
| 79 | /// Get pointer to key agreement algorithm type field, a fixed length character array |
| 80 | uint8_t* getPubKeysType() { return commitHeader->pubkey; }; |
| 81 | |
| 82 | /// Get pointer to SAS algorithm type field, a fixed length character array |
| 83 | uint8_t* getSasType() { return commitHeader->sas; }; |
| 84 | |
| 85 | /// Get pointer to ZID field, a fixed length byte array |
| 86 | uint8_t* getZid() { return commitHeader->zid; }; |
| 87 | |
| 88 | /// Get pointer to HVI field, a fixed length byte array |
| 89 | uint8_t* getHvi() { return commitHeader->hvi; }; |
| 90 | |
| 91 | /// Get pointer to NONCE field, a fixed length byte array, overlaps HVI field |
| 92 | uint8_t* getNonce() { return commitHeader->hvi; }; |
| 93 | |
| 94 | /// Get pointer to hashH2 field, a fixed length byte array |
| 95 | uint8_t* getH2() { return commitHeader->hashH2; }; |
| 96 | |
| 97 | /// Get pointer to MAC field, a fixed length byte array |
| 98 | uint8_t* getHMAC() { return commitHeader->hmac; }; |
| 99 | |
| 100 | /// Get pointer to MAC field during multi-stream mode, a fixed length byte array |
| 101 | uint8_t* getHMACMulti() { return commitHeader->hmac-4*ZRTP_WORD_SIZE; }; |
| 102 | |
Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame^] | 103 | /// Check if packet length makes sense. |
| 104 | bool isLengthOk(commitType type) {int32_t len = getLength(); |
| 105 | return ((type == DhExchange) ? len == COMMIT_DH_EX : len == COMMIT_MULTI);} |
| 106 | |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 107 | /// Set hash algorithm type field, fixed length character field |
| 108 | void setHashType(uint8_t* text) { memcpy(commitHeader->hash, text, ZRTP_WORD_SIZE); }; |
| 109 | |
| 110 | /// Set cipher algorithm type field, fixed length character field |
| 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 |
| 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 |
| 117 | void setPubKeyType(uint8_t* text) { memcpy(commitHeader->pubkey, text, ZRTP_WORD_SIZE); }; |
| 118 | |
| 119 | /// Set SAS algorithm type field, fixed length character field |
| 120 | void setSasType(uint8_t* text) { memcpy(commitHeader->sas, text, ZRTP_WORD_SIZE); }; |
| 121 | |
| 122 | /// Set ZID field, a fixed length byte array |
| 123 | void setZid(uint8_t* text) { memcpy(commitHeader->zid, text, sizeof(commitHeader->zid)); }; |
| 124 | |
| 125 | /// Set HVI field, a fixed length byte array |
| 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 |
| 132 | void setH2(uint8_t* hash) { memcpy(commitHeader->hashH2, hash, sizeof(commitHeader->hashH2)); }; |
| 133 | |
| 134 | /// Set MAC field, a fixed length byte array |
| 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 |
| 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 | |