blob: 417a892c5c0f135df2447b4fce2bea2dbd9783f2 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002 Copyright (C) 2006-2012 Werner Dittmann
Alexandre Lision51140e12013-12-02 10:54:09 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lisionddd731e2014-01-31 11:50:08 -05005 it under the terms of the GNU 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 _ZRTP_H_
19#define _ZRTP_H_
20/**
21 * @file ZRtp.h
22 * @brief The ZRTP main engine
23 * @defgroup GNU_ZRTP The GNU ZRTP C++ implementation
24 * @{
25 */
26
27#include <cstdlib>
28
29#include <libzrtpcpp/ZrtpPacketHello.h>
30#include <libzrtpcpp/ZrtpPacketHelloAck.h>
31#include <libzrtpcpp/ZrtpPacketCommit.h>
32#include <libzrtpcpp/ZrtpPacketDHPart.h>
33#include <libzrtpcpp/ZrtpPacketConfirm.h>
34#include <libzrtpcpp/ZrtpPacketConf2Ack.h>
35#include <libzrtpcpp/ZrtpPacketGoClear.h>
36#include <libzrtpcpp/ZrtpPacketClearAck.h>
37#include <libzrtpcpp/ZrtpPacketError.h>
38#include <libzrtpcpp/ZrtpPacketErrorAck.h>
39#include <libzrtpcpp/ZrtpPacketPing.h>
40#include <libzrtpcpp/ZrtpPacketPingAck.h>
41#include <libzrtpcpp/ZrtpPacketSASrelay.h>
42#include <libzrtpcpp/ZrtpPacketRelayAck.h>
43#include <libzrtpcpp/ZrtpCallback.h>
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050044#include <libzrtpcpp/ZIDCache.h>
Alexandre Lision51140e12013-12-02 10:54:09 -050045
46#ifndef SHA256_DIGEST_LENGTH
47#define SHA256_DIGEST_LENGTH 32
48#endif
49
50// Prepare to support digest algorithms up to 512 bit (64 bytes)
51#define MAX_DIGEST_LENGTH 64
52#define IMPL_MAX_DIGEST_LENGTH 64
53
54class __EXPORT ZrtpStateClass;
55class ZrtpDH;
56
57/**
58 * The main ZRTP class.
59 *
60 * This is the main class of the RTP/SRTP independent part of the GNU
61 * ZRTP. It handles the ZRTP HMAC, DH, and other data management. The
62 * user of this class needs to know only a few methods and needs to
63 * provide only a few external functions to connect to a Timer
64 * mechanism and to send data via RTP and SRTP. Refer to the
65 * ZrtpCallback class to get detailed information regading the
66 * callback methods required by GNU RTP.
67 *
68 * The class ZrtpQueue is the GNU ccRTP specific implementation that
69 * extends standard ccRTP RTP provide ZRTP support. Refer to the
70 * documentation of ZrtpQueue to get more information about the usage
71 * of ZRtp and associated classes.
72 *
73 * The main entry into the ZRTP class is the processExtensionHeader()
74 * method.
75 *
76 * This class does not directly handle the protocol states, timers,
77 * and packet resend. The protocol state engine is responsible for
78 * these actions.
79 *
80 * Example how to use ZRtp:
81 *<pre>
82 * zrtpEngine = new ZRtp((uint8_t*)ownZid, (ZrtpCallback*)this, idString);
83 * zrtpEngine->startZrtpEngine();
84 *</pre>
85 * @see ZrtpCallback
86 *
87 * @author Werner Dittmann <Werner.Dittmann@t-online.de>
88 */
89class __EXPORT ZRtp {
90
91 public:
92
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050093 typedef enum _secrets {
94 Rs1 = 1,
95 Rs2 = 2,
96 Pbx = 4,
97 Aux = 8
98 } secrets;
99
100 typedef struct _zrtpInfo {
101 int32_t secretsCached;
102 int32_t secretsMatched;
103 int32_t secretsMatchedDH;
104 const char *hash;
105 const char *cipher;
106 const char *pubKey;
107 const char *sasType;
108 const char *authLength;
109 } zrtpInfo;
110
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500111
Alexandre Lision51140e12013-12-02 10:54:09 -0500112 /**
113 * Constructor intializes all relevant data but does not start the
114 * engine.
115 */
116 ZRtp(uint8_t* myZid, ZrtpCallback* cb, std::string id,
117 ZrtpConfigure* config, bool mitmm= false, bool sasSignSupport= false);
118
119 /**
120 * Destructor cleans up.
121 */
122 ~ZRtp();
123
124 /**
125 * Kick off the ZRTP protocol engine.
126 *
127 * This method calls the ZrtpStateClass#evInitial() state of the state
128 * engine. After this call we are able to process ZRTP packets
129 * from our peer and to process them.
130 */
131 void startZrtpEngine();
132
133 /**
134 * Stop ZRTP security.
135 *
136 */
137 void stopZrtp();
138
139 /**
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500140 * Process ZRTP message.
Alexandre Lision51140e12013-12-02 10:54:09 -0500141 *
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500142 * The method takes the data and forwards it to the ZRTP state engine for further
143 * processing. It's the caller's duty to check the ZRTP CRC and the ZRTP magic
144 * cookie before calling this function.
Alexandre Lision51140e12013-12-02 10:54:09 -0500145 *
146 * @param extHeader
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500147 * A pointer to the first byte of the ZRTP message. Refer to RFC6189.
Alexandre Lision51140e12013-12-02 10:54:09 -0500148 * @param peerSSRC
149 * The peer's SSRC.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500150 * @param length
151 * of the received data packet, this includes the RTP like header
152 * and the ZRTP CRC field - used to do santity checks.
153 *
Alexandre Lision51140e12013-12-02 10:54:09 -0500154 * @return
155 * Code indicating further packet handling, see description above.
156 */
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500157 void processZrtpMessage(uint8_t *extHeader, uint32_t peerSSRC, size_t length);
Alexandre Lision51140e12013-12-02 10:54:09 -0500158
159 /**
160 * Process a timeout event.
161 *
162 * We got a timeout from the timeout provider. Forward it to the
163 * protocol state engine.
164 *
165 */
166 void processTimeout();
167
168 /**
169 * Check for and handle GoClear ZRTP packet header.
170 *
171 * This method checks if this is a GoClear packet. If not, just return
172 * false. Otherwise handle it according to the specification.
173 *
174 * @param extHeader
175 * A pointer to the first byte of the extension header. Refer to
176 * RFC3550.
177 * @return
178 * False if not a GoClear, true otherwise.
179 */
180 bool handleGoClear(uint8_t *extHeader);
181
182 /**
183 * Set the auxilliary secret.
184 *
185 * Use this method to set the auxilliary secret data. Refer to ZRTP
186 * specification, chapter 4.3 ff
187 *
188 * @param data
189 * Points to the secret data.
190 * @param length
191 * Length of the auxilliary secrect in bytes
192 */
193 void setAuxSecret(uint8_t* data, int32_t length);
194
195 /**
196 * Check current state of the ZRTP state engine
197 *
198 * @param state
199 * The state to check.
200 * @return
201 * Returns true id ZRTP engine is in the given state, false otherwise.
202 */
203 bool inState(int32_t state);
204
205 /**
206 * Set SAS as verified.
207 *
208 * Call this method if the user confirmed (verfied) the SAS. ZRTP
209 * remembers this together with the retained secrets data.
210 */
211 void SASVerified();
212
213 /**
214 * Reset the SAS verfied flag for the current active user's retained secrets.
215 *
216 */
217 void resetSASVerified();
218
219 /**
220 * Get the ZRTP Hello Hash data.
221 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500222 * Use this method to get the ZRTP Hello Hash data. The method
Alexandre Lision51140e12013-12-02 10:54:09 -0500223 * returns the data as a string containing the ZRTP protocol version and
224 * hex-digits.
225 *
226 * Refer to ZRTP specification, chapter 8.
227 *
228 * @return
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500229 * a std:string containing the Hello hash value as hex-digits. The
230 * hello hash is available immediately after class instantiation.
Alexandre Lision51140e12013-12-02 10:54:09 -0500231 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500232 std::string getHelloHash();
Alexandre Lision51140e12013-12-02 10:54:09 -0500233
234 /**
235 * Get the peer's ZRTP Hello Hash data.
236 *
237 * Use this method to get the peer's ZRTP Hello Hash data. The method
238 * returns the data as a string containing the ZRTP protocol version and
239 * hex-digits.
240 *
241 * The peer's hello hash is available only after ZRTP received a hello. If
242 * no data is available the function returns an empty string.
243 *
244 * Refer to ZRTP specification, chapter 8.
245 *
246 * @return
247 * a std:string containing the Hello version and the hello hash as hex digits.
248 */
249 std::string getPeerHelloHash();
250
251 /**
252 * Get Multi-stream parameters.
253 *
254 * Use this method to get the Multi-stream that were computed during
255 * the ZRTP handshake. An application may use these parameters to
256 * enable multi-stream processing for an associated SRTP session.
257 *
258 * Refer to chapter 4.4.2 in the ZRTP specification for further details
259 * and restriction how and when to use multi-stream mode.
260 *
261 * @return
262 * a string that contains the multi-stream parameters. The application
263 * must not modify the contents of this string, it is opaque data. The
264 * application may hand over this string to a new ZrtpQueue instance
265 * to enable multi-stream processing for this ZrtpQueue.
266 * If ZRTP was not started or ZRTP is not yet in secure state the method
267 * returns an empty string.
268 */
269 std::string getMultiStrParams();
270
271 /**
272 * Set Multi-stream parameters.
273 *
274 * Use this method to set the parameters required to enable Multi-stream
275 * processing of ZRTP. The multi-stream parameters must be set before the
276 * application starts the ZRTP protocol engine.
277 *
278 * Refer to chapter 4.4.2 in the ZRTP specification for further details
279 * of multi-stream mode.
280 *
281 * @param parameters
282 * A string that contains the multi-stream parameters that this
283 * new ZrtpQueue instanace shall use. See also
284 * <code>getMultiStrParams()</code>
285 */
286 void setMultiStrParams(std::string parameters);
287
288 /**
289 * Check if this ZRTP session is a Multi-stream session.
290 *
291 * Use this method to check if this ZRTP instance uses multi-stream.
292 * Refer to chapters 4.2 and 4.4.2 in the ZRTP.
293 *
294 * @return
295 * True if multi-stream is used, false otherwise.
296 */
297 bool isMultiStream();
298
299 /**
300 * Check if the other ZRTP client supports Multi-stream.
301 *
302 * Use this method to check if the other ZRTP client supports
303 * Multi-stream mode.
304 *
305 * @return
306 * True if multi-stream is available, false otherwise.
307 */
308 bool isMultiStreamAvailable();
309
310 /**
311 * Accept a PBX enrollment request.
312 *
313 * If a PBX service asks to enroll the PBX trusted MitM key and the user
314 * accepts this request, for example by pressing an OK button, the client
315 * application shall call this method and set the parameter
316 * <code>accepted</code> to true. If the user does not accept the request
317 * set the parameter to false.
318 *
319 * @param accepted
320 * True if the enrollment request is accepted, false otherwise.
321 */
322 void acceptEnrollment(bool accepted);
323
324 /**
325 * Check the state of the enrollment mode.
326 *
327 * If true then we will set the enrollment flag (E) in the confirm
328 * packets and perform the enrollment actions. A MitM (PBX) enrollment service
329 * started this ZRTP session. Can be set to true only if mitmMode is also true.
330 *
331 * @return status of the enrollmentMode flag.
332 */
333 bool isEnrollmentMode();
334
335 /**
336 * Set the state of the enrollment mode.
337 *
338 * If true then we will set the enrollment flag (E) in the confirm
339 * packets and perform the enrollment actions. A MitM (PBX) enrollment
340 * service must sets this mode to true.
341 *
342 * Can be set to true only if mitmMode is also true.
343 *
344 * @param enrollmentMode defines the new state of the enrollmentMode flag
345 */
346 void setEnrollmentMode(bool enrollmentMode);
347
348 /**
349 * Check if a peer's cache entry has a vaild MitM key.
350 *
351 * If true then the other peer ha a valid MtiM key, i.e. the peer has performed
352 * the enrollment procedure. A PBX ZRTP Back-2-Back application can use this function
353 * to check which of the peers is enrolled.
354 *
355 * @return True if the other peer has a valid Mitm key (is enrolled).
356 */
357 bool isPeerEnrolled();
358
359 /**
360 * Send the SAS relay packet.
361 *
362 * The method creates and sends a SAS relay packet according to the ZRTP
363 * specifications. Usually only a MitM capable user agent (PBX) uses this
364 * function.
365 *
366 * @param sh the full SAS hash value, 32 bytes
367 * @param render the SAS rendering algorithm
368 */
369 bool sendSASRelayPacket(uint8_t* sh, std::string render);
370
371 /**
372 * Get the commited SAS rendering algorithm for this ZRTP session.
373 *
374 * @return the commited SAS rendering algorithm
375 */
376 std::string getSasType();
377
378 /**
379 * Get the computed SAS hash for this ZRTP session.
380 *
381 * A PBX ZRTP back-to-Back function uses this function to get the SAS
382 * hash of an enrolled client to construct the SAS relay packet for
383 * the other client.
384 *
385 * @return a pointer to the byte array that contains the full
386 * SAS hash.
387 */
388 uint8_t* getSasHash();
389
390 /**
391 * Set signature data.
392 *
393 * This functions stores signature data and transmitts it during ZRTP
394 * processing to the other party as part of the Confirm packets. Refer to
395 * chapters 5.7 and 7.2.
396 *
397 * The signature data must be set before ZRTP the application calls
398 * <code>start()</code>.
399 *
400 * @param data
401 * The signature data including the signature type block. The method
402 * copies this data into the Confirm packet at signature type block.
403 * @param length
404 * The length of the signature data in bytes. This length must be
405 * multiple of 4.
406 * @return
407 * True if the method stored the data, false otherwise.
408 */
409 bool setSignatureData(uint8_t* data, int32_t length);
410
411 /**
412 * Get signature data.
413 *
414 * This functions returns a pointer to the signature data that was receivied
415 * during ZRTP processing. Refer to chapters 5.7 and 7.2.
416 *
417 * The returned pointer points to volatile data that is valid only during the
418 * <code>checkSASSignature()</code> callback funtion. The application must copy
419 * the signature data if it will be used after the callback function returns.
420 *
421 * The signature data can be retrieved after ZRTP enters secure state.
422 * <code>start()</code>.
423 *
424 * @return
425 * Pointer to signature data.
426 */
427 const uint8_t* getSignatureData();
428
429 /**
430 * Get length of signature data in number of bytes.
431 *
432 * This functions returns the length of signature data that was receivied
433 * during ZRTP processing. Refer to chapters 5.7 and 7.2.
434 *
435 * @return
436 * Length in bytes of the received signature data. The method returns
437 * zero if no signature data is avilable.
438 */
439 int32_t getSignatureLength();
440
441 /**
442 * Emulate a Conf2Ack packet.
443 *
444 * This method emulates a Conf2Ack packet. According to ZRTP specification
445 * the first valid SRTP packet that the Initiator receives must switch
446 * on secure mode. Refer to chapter 4 in the specificaton
447 *
448 */
449 void conf2AckSecure();
450
451 /**
452 * Get other party's ZID (ZRTP Identifier) data
453 *
454 * This functions returns the other party's ZID that was receivied
455 * during ZRTP processing.
456 *
457 * The ZID data can be retrieved after ZRTP receive the first Hello
458 * packet from the other party. The application may call this method
459 * for example during SAS processing in showSAS(...) user callback
460 * method.
461 *
462 * @param data
463 * Pointer to a data buffer. This buffer must have a size of
464 * at least 12 bytes (96 bit) (ZRTP Identifier, see chap. 4.9)
465 * @return
466 * Number of bytes copied into the data buffer - must be equivalent
467 * to 96 bit, usually 12 bytes.
468 */
469 int32_t getPeerZid(uint8_t* data);
470
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500471 /**
472 * Returns a pointer to the gather detailed information structure.
473 *
474 * This structure contains some detailed information about the negotiated
475 * algorithms, the chached and matched shared secrets.
476 */
477 const zrtpInfo *getDetailInfo();
478
479 /**
480 * Get peer's client id.
481 *
482 * @return the peer's client id or an empty @c string if not set.
483 */
484 std::string getPeerClientId();
485
486 /**
487 * Get peer's protocl version string.
488 *
489 * @return the peer's protocol version or an empty @c string if not set.
490 */
491 std::string getPeerProtcolVersion();
492
Alexandre Lision51140e12013-12-02 10:54:09 -0500493private:
494 friend class ZrtpStateClass;
495
496 /**
497 * The state engine takes care of protocol processing.
498 */
499 ZrtpStateClass* stateEngine;
500
501 /**
502 * This is my ZID that I send to the peer.
503 */
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500504 uint8_t ownZid[IDENTIFIER_LEN];
Alexandre Lision51140e12013-12-02 10:54:09 -0500505
506 /**
507 * The peer's ZID
508 */
509 uint8_t peerZid[IDENTIFIER_LEN];
510
511 /**
512 * The callback class provides me with the interface to send
513 * data and to deal with timer management of the hosting system.
514 */
515 ZrtpCallback* callback;
516
517 /**
518 * My active Diffie-Helman context
519 */
520 ZrtpDH* dhContext;
521
522 /**
523 * The computed DH shared secret
524 */
525 uint8_t* DHss;
526
527 /**
528 * My computed public key
529 */
530 uint8_t pubKeyBytes[400];
531 /**
532 * Length off public key
533 */
534// int32_t pubKeyLen;
535 /**
536 * My Role in the game
537 */
538 Role myRole;
539
540 /**
541 * The human readable SAS value
542 */
543 std::string SAS;
544
545 /**
546 * The SAS hash for signaling and alike. Refer to chapters
547 * 4.5 and 7 how sasHash, sasValue and the SAS string are derived.
548 */
549 uint8_t sasHash[MAX_DIGEST_LENGTH];
550 /**
551 * The ids for the retained and other shared secrets
552 */
553 uint8_t rs1IDr[MAX_DIGEST_LENGTH];
554 uint8_t rs2IDr[MAX_DIGEST_LENGTH];
555 uint8_t auxSecretIDr[MAX_DIGEST_LENGTH];
556 uint8_t pbxSecretIDr[MAX_DIGEST_LENGTH];
557
558 uint8_t rs1IDi[MAX_DIGEST_LENGTH];
559 uint8_t rs2IDi[MAX_DIGEST_LENGTH];
560 uint8_t auxSecretIDi[MAX_DIGEST_LENGTH];
561 uint8_t pbxSecretIDi[MAX_DIGEST_LENGTH];
562
563 /**
564 * pointers to aux secret storage and length of aux secret
565 */
566 uint8_t* auxSecret;
567 int32_t auxSecretLength;
568
569 /**
570 * Record if valid rs1 and/or rs1 were found in the
571 * retaind secret cache.
572 */
573 bool rs1Valid;
574 bool rs2Valid;
575 /**
576 * My hvi
577 */
578 uint8_t hvi[MAX_DIGEST_LENGTH];
579
580 /**
581 * The peer's hvi
582 */
583 uint8_t peerHvi[8*ZRTP_WORD_SIZE];
584
585 /**
586 * Context to compute the SHA256 hash of selected messages.
587 * Used to compute the s0, refer to chapter 4.4.1.4
588 */
589 void* msgShaContext;
590 /**
591 * Commited Hash, Cipher, and public key algorithms
592 */
593 AlgorithmEnum* hash;
594 AlgorithmEnum* cipher;
595 AlgorithmEnum* pubKey;
596 /**
597 * The selected SAS type.
598 */
599 AlgorithmEnum* sasType;
600
601 /**
602 * The selected SAS type.
603 */
604 AlgorithmEnum* authLength;
605
606 /**
607 * The Hash images as defined in chapter 5.1.1 (H0 is a random value,
608 * not stored here). Need full SHA 256 lenght to store hash value but
609 * only the leftmost 128 bits are used in computations and comparisons.
610 */
611 uint8_t H0[IMPL_MAX_DIGEST_LENGTH];
612 uint8_t H1[IMPL_MAX_DIGEST_LENGTH];
613 uint8_t H2[IMPL_MAX_DIGEST_LENGTH];
614 uint8_t H3[IMPL_MAX_DIGEST_LENGTH];
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500615 uint8_t helloHash[IMPL_MAX_DIGEST_LENGTH];
Alexandre Lision51140e12013-12-02 10:54:09 -0500616
617 uint8_t peerHelloHash[IMPL_MAX_DIGEST_LENGTH];
618 uint8_t peerHelloVersion[ZRTP_WORD_SIZE + 1]; // +1 for nul byte
619
620 // We get the peer's H? from the message where length is defined as 8 words
621 uint8_t peerH0[8*ZRTP_WORD_SIZE];
622 uint8_t peerH1[8*ZRTP_WORD_SIZE];
623 uint8_t peerH2[8*ZRTP_WORD_SIZE];
624 uint8_t peerH3[8*ZRTP_WORD_SIZE];
625
626 /**
627 * The SHA256 hash over selected messages
628 */
629 uint8_t messageHash[MAX_DIGEST_LENGTH];
630
631 /**
632 * The s0
633 */
634 uint8_t s0[MAX_DIGEST_LENGTH];
635
636 /**
637 * The new Retained Secret
638 */
639 uint8_t newRs1[MAX_DIGEST_LENGTH];
640
641 /**
642 * The GoClear HMAC keys and confirm HMAC key
643 */
644 uint8_t hmacKeyI[MAX_DIGEST_LENGTH];
645 uint8_t hmacKeyR[MAX_DIGEST_LENGTH];
646
647 /**
648 * The Initiator's srtp key and salt
649 */
650 uint8_t srtpKeyI[MAX_DIGEST_LENGTH];
651 uint8_t srtpSaltI[MAX_DIGEST_LENGTH];
652
653 /**
654 * The Responder's srtp key and salt
655 */
656 uint8_t srtpKeyR[MAX_DIGEST_LENGTH];
657 uint8_t srtpSaltR[MAX_DIGEST_LENGTH];
658
659 /**
660 * The keys used to encrypt/decrypt the confirm message
661 */
662 uint8_t zrtpKeyI[MAX_DIGEST_LENGTH];
663 uint8_t zrtpKeyR[MAX_DIGEST_LENGTH];
664
665 /**
666 * Pointers to negotiated hash and HMAC functions
667 */
668 void (*hashFunction)(unsigned char *data,
669 unsigned int data_length,
670 unsigned char *digest);
671
672 void (*hashListFunction)(unsigned char *data[],
673 unsigned int data_length[],
674 unsigned char *digest);
675
676 void (*hmacFunction)(uint8_t* key, uint32_t key_length,
677 uint8_t* data, int32_t data_length,
678 uint8_t* mac, uint32_t* mac_length);
679
680 void (*hmacListFunction)( uint8_t* key, uint32_t key_length,
681 uint8_t* data[], uint32_t data_length[],
682 uint8_t* mac, uint32_t* mac_length );
683
684 void* (*createHashCtx)();
685
686 void (*closeHashCtx)(void* ctx, unsigned char* digest);
687
688 void (*hashCtxFunction)(void* ctx, unsigned char* data,
689 unsigned int dataLength);
690
691 void (*hashCtxListFunction)(void* ctx, unsigned char* dataChunks[],
692 unsigned int dataChunkLength[]);
693
694 int32_t hashLength;
695
696 // Funtion pointers to implicit hash and hmac functions
697 void (*hashFunctionImpl)(unsigned char *data,
698 unsigned int data_length,
699 unsigned char *digest);
700
701 void (*hashListFunctionImpl)(unsigned char *data[],
702 unsigned int data_length[],
703 unsigned char *digest);
704
705 void (*hmacFunctionImpl)(uint8_t* key, uint32_t key_length,
706 uint8_t* data, int32_t data_length,
707 uint8_t* mac, uint32_t* mac_length);
708
709 void (*hmacListFunctionImpl)( uint8_t* key, uint32_t key_length,
710 uint8_t* data[], uint32_t data_length[],
711 uint8_t* mac, uint32_t* mac_length );
712
713 int32_t hashLengthImpl;
714
715 /**
716 * The ZRTP Session Key
717 * Refer to chapter 5.4.1.4
718 */
719 uint8_t zrtpSession[MAX_DIGEST_LENGTH];
720
721 /**
722 * True if this ZRTP instance uses multi-stream mode.
723 */
724 bool multiStream;
725
726 /**
727 * True if the other ZRTP client supports multi-stream mode.
728 */
729 bool multiStreamAvailable;
730
731 /**
732 * Enable MitM (PBX) enrollment
733 *
734 * If set to true then ZRTP honors the PBX enrollment flag in
735 * Commit packets and calls the appropriate user callback
736 * methods. If the parameter is set to false ZRTP ignores the PBX
737 * enrollment flags.
738 */
739 bool enableMitmEnrollment;
740
741 /**
742 * True if a valid trusted MitM key of the other peer is available, i.e. enrolled.
743 */
744 bool peerIsEnrolled;
745
746 /**
747 * Set to true if the Hello packet contained the M-flag (MitM flag).
748 * We use this later to check some stuff for SAS Relay processing
749 */
750 bool mitmSeen;
751
752 /**
753 * Temporarily store computed pbxSecret, if user accepts enrollment then
754 * it will copied to our ZID record of the PBX (MitM)
755 */
756 uint8_t* pbxSecretTmp;
757 uint8_t pbxSecretTmpBuffer[MAX_DIGEST_LENGTH];
758
759 /**
760 * If true then we will set the enrollment flag (E) in the confirm
761 * packets. Set to true if the PBX enrollment service started this ZRTP
762 * session. Can be set to true only if mitmMode is also true.
763 */
764 bool enrollmentMode;
765
766 /**
767 * Configuration data which algorithms to use.
768 */
769 ZrtpConfigure configureAlgos;
770 /**
771 * Pre-initialized packets.
772 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500773 ZrtpPacketHello zrtpHello;
Alexandre Lision51140e12013-12-02 10:54:09 -0500774 ZrtpPacketHelloAck zrtpHelloAck;
775 ZrtpPacketConf2Ack zrtpConf2Ack;
776 ZrtpPacketClearAck zrtpClearAck;
777 ZrtpPacketGoClear zrtpGoClear;
778 ZrtpPacketError zrtpError;
779 ZrtpPacketErrorAck zrtpErrorAck;
780 ZrtpPacketDHPart zrtpDH1;
781 ZrtpPacketDHPart zrtpDH2;
782 ZrtpPacketCommit zrtpCommit;
783 ZrtpPacketConfirm zrtpConfirm1;
784 ZrtpPacketConfirm zrtpConfirm2;
785 ZrtpPacketPingAck zrtpPingAck;
786 ZrtpPacketSASrelay zrtpSasRelay;
787 ZrtpPacketRelayAck zrtpRelayAck;
788
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500789 /**
790 * ZID cache record
791 */
792 ZIDRecord *zidRec;
793
794 /**
Alexandre Lision51140e12013-12-02 10:54:09 -0500795 * Random IV data to encrypt the confirm data, 128 bit for AES
796 */
797 uint8_t randomIV[16];
798
799 uint8_t tempMsgBuffer[1024];
800 int32_t lengthOfMsgData;
801
802 /**
803 * Variables to store signature data. Includes the signature type block
804 */
805 const uint8_t* signatureData; // will be set when needed
806 int32_t signatureLength; // overall length in bytes
807
808 /**
809 * Is true if the other peer signaled SAS signature support in its Hello packet.
810 */
811 bool signSasSeen;
812
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500813 uint32_t peerSSRC; // peer's SSRC, required to setup PingAck packet
814
815 zrtpInfo detailInfo; // filled with some more detailded information if application would like to know
816
817 std::string peerClientId; // store the peer's client Id
Alexandre Lision51140e12013-12-02 10:54:09 -0500818
819 /**
820 * Enable or disable paranoid mode.
821 *
822 * The Paranoid mode controls the behaviour and handling of the SAS verify flag. If
823 * Panaoid mode is set to flase then ZRtp applies the normal handling. If Paranoid
824 * mode is set to true then the handling is:
825 *
826 * <ul>
827 * <li> Force the SAS verify flag to be false at srtpSecretsOn() callback. This gives
828 * the user interface (UI) the indication to handle the SAS as <b>not verified</b>.
829 * See implementation note below.</li>
830 * <li> Don't set the SAS verify flag in the <code>Confirm</code> packets, thus the other
831 * also must report the SAS as <b>not verified</b>.</li>
832 * <li> ignore the <code>SASVerified()</code> function, thus do not set the SAS to verified
833 * in the ZRTP cache. </li>
834 * <li> Disable the <b>Trusted PBX MitM</b> feature. Just send the <code>SASRelay</code> packet
835 * but do not process the relayed data. This protects the user from a malicious
836 * "trusted PBX".</li>
837 * </ul>
838 * ZRtp performs alls other steps during the ZRTP negotiations as usual, in particular it
839 * computes, compares, uses, and stores the retained secrets. This avoids unnecessary warning
840 * messages. The user may enable or disable the Paranoid mode on a call-by-call basis without
841 * breaking the key continuity data.
842 *
843 * <b>Implementation note:</b></br>
844 * An application shall always display the SAS code if the SAS verify flag is <code>false</code>.
845 * The application shall also use mechanisms to remind the user to compare the SAS code, for
846 * example useing larger fonts, different colours and other display features.
847 */
848 bool paranoidMode;
849
850 /**
851 * Find the best Hash algorithm that is offered in Hello.
852 *
853 * Find the best, that is the strongest, Hash algorithm that our peer
854 * offers in its Hello packet.
855 *
856 * @param hello
857 * The Hello packet.
858 * @return
859 * The Enum that identifies the best offered Hash algortihm. Return
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500860 * mandatory algorithm if no match was found.
861 */
Alexandre Lision51140e12013-12-02 10:54:09 -0500862 AlgorithmEnum* findBestHash(ZrtpPacketHello *hello);
863
864 /**
865 * Find the best symmetric cipher algorithm that is offered in Hello.
866 *
867 * Find the best, that is the strongest, cipher algorithm that our peer
868 * offers in its Hello packet.
869 *
870 * @param hello
871 * The Hello packet.
872 * @param pk
873 * The id of the selected public key algorithm
874 * @return
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500875 * The Enum that identifies the best offered Cipher algorithm. Return
876 * mandatory algorithm if no match was found.
Alexandre Lision51140e12013-12-02 10:54:09 -0500877 */
878 AlgorithmEnum* findBestCipher(ZrtpPacketHello *hello, AlgorithmEnum* pk);
879
880 /**
881 * Find the best Public Key algorithm that is offered in Hello.
882 *
883 * Find the best, that is the strongest, public key algorithm that our peer
884 * offers in its Hello packet.
885 *
886 * @param hello
887 * The Hello packet.
888 * @return
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500889 * The Enum that identifies the best offered Public Key algorithm. Return
890 * mandatory algorithm if no match was found.
Alexandre Lision51140e12013-12-02 10:54:09 -0500891 */
892 AlgorithmEnum* findBestPubkey(ZrtpPacketHello *hello);
893
894 /**
895 * Find the best SAS algorithm that is offered in Hello.
896 *
897 * Find the best, that is the strongest, SAS algorithm that our peer
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500898 * offers in its Hello packet. The method works as definied in RFC 6189,
899 * chapter 4.1.2.
900 *
901 * The list of own supported public key algorithms must follow the rules
902 * defined in RFC 6189, chapter 4.1.2, thus the order in the list must go
903 * from fastest to slowest.
Alexandre Lision51140e12013-12-02 10:54:09 -0500904 *
905 * @param hello
906 * The Hello packet.
907 * @return
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500908 * The Enum that identifies the best offered SAS algorithm. Return
909 * mandatory algorithm if no match was found.
Alexandre Lision51140e12013-12-02 10:54:09 -0500910 */
911 AlgorithmEnum* findBestSASType(ZrtpPacketHello* hello);
912
913 /**
914 * Find the best authentication length that is offered in Hello.
915 *
916 * Find the best, that is the strongest, authentication length that our peer
917 * offers in its Hello packet.
918 *
919 * @param hello
920 * The Hello packet.
921 * @return
922 * The Enum that identifies the best offered authentication length. Return
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500923 * mandatory algorithm if no match was found.
Alexandre Lision51140e12013-12-02 10:54:09 -0500924 */
925 AlgorithmEnum* findBestAuthLen(ZrtpPacketHello* hello);
926
927 /**
928 * Check if MultiStream mode is offered in Hello.
929 *
930 * Find the best, that is the strongest, authentication length that our peer
931 * offers in its Hello packet.
932 *
933 * @param hello
934 * The Hello packet.
935 * @return
936 * True if multi stream mode is available, false otherwise.
937 */
938 bool checkMultiStream(ZrtpPacketHello* hello);
939
940 /**
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500941 * Checks if Hello packet contains a strong (384bit) hash and returns it.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500942 *
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500943 * @return @c hash algorithm if found in Hello packet, @c NULL otherwise.
944 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500945 AlgorithmEnum* getStrongHashOffered(ZrtpPacketHello *hello);
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500946
947 /**
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500948 * Checks if Hello packet offers a strong (256bit) symmetric cipher.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500949 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500950 * The method returns the first strong cipher offered in the Hello packet.
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500951 *
952 * @return @c cipher algorithm if found in Hello packet, @c NULL otherwise.
953 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500954 AlgorithmEnum* getStrongCipherOffered(ZrtpPacketHello *hello);
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500955
956 /**
Alexandre Lision51140e12013-12-02 10:54:09 -0500957 * Save the computed MitM secret to the ZID record of the peer
958 */
959 void writeEnrollmentPBX();
960
961 /**
962 * Compute my hvi value according to ZRTP specification.
963 */
964 void computeHvi(ZrtpPacketDHPart* dh, ZrtpPacketHello *hello);
965
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500966 void computeSharedSecretSet(ZIDRecord *zidRec);
967
Alexandre Lision51140e12013-12-02 10:54:09 -0500968 void computeSRTPKeys();
969
970 void KDF(uint8_t* key, uint32_t keyLength, uint8_t* label, int32_t labelLength,
971 uint8_t* context, int32_t contextLength, int32_t L, uint8_t* output);
972
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500973 void generateKeysInitiator(ZrtpPacketDHPart *dhPart, ZIDRecord *zidRec);
Alexandre Lision51140e12013-12-02 10:54:09 -0500974
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -0500975 void generateKeysResponder(ZrtpPacketDHPart *dhPart, ZIDRecord *zidRec);
Alexandre Lision51140e12013-12-02 10:54:09 -0500976
977 void generateKeysMultiStream();
978
979 void computePBXSecret();
980
981 void setNegotiatedHash(AlgorithmEnum* hash);
982
983 /*
984 * The following methods are helper functions for ZrtpStateClass.
985 * ZrtpStateClass calls them to prepare packets, send data, report
986 * problems, etc.
987 */
988 /**
989 * Send a ZRTP packet.
990 *
991 * The state engines calls this method to send a packet via the RTP
992 * stack.
993 *
994 * @param packet
995 * Points to the ZRTP packet.
996 * @return
997 * zero if sending failed, one if packet was send
998 */
999 int32_t sendPacketZRTP(ZrtpPacketBase *packet);
1000
1001 /**
1002 * Activate a Timer using the host callback.
1003 *
1004 * @param tm
1005 * The time in milliseconds.
1006 * @return
1007 * zero if activation failed, one if timer was activated
1008 */
1009 int32_t activateTimer(int32_t tm);
1010
1011 /**
1012 * Cancel the active Timer using the host callback.
1013 *
1014 * @return
1015 * zero if activation failed, one if timer was activated
1016 */
1017 int32_t cancelTimer();
1018
1019 /**
1020 * Prepare a Hello packet.
1021 *
1022 * Just take the preinitialized Hello packet and return it. No
1023 * further processing required.
1024 *
1025 * @return
1026 * A pointer to the initialized Hello packet.
1027 */
1028 ZrtpPacketHello* prepareHello();
1029
1030 /**
1031 * Prepare a HelloAck packet.
1032 *
1033 * Just take the preinitialized HelloAck packet and return it. No
1034 * further processing required.
1035 *
1036 * @return
1037 * A pointer to the initialized HelloAck packet.
1038 */
1039 ZrtpPacketHelloAck* prepareHelloAck();
1040
1041 /**
1042 * Prepare a Commit packet.
1043 *
1044 * We have received a Hello packet from our peer. Check the offers
1045 * it makes to us and select the most appropriate. Using the
1046 * selected values prepare a Commit packet and return it to protocol
1047 * state engine.
1048 *
1049 * @param hello
1050 * Points to the received Hello packet
1051 * @param errMsg
1052 * Points to an integer that can hold a ZRTP error code.
1053 * @return
1054 * A pointer to the prepared Commit packet
1055 */
1056 ZrtpPacketCommit* prepareCommit(ZrtpPacketHello *hello, uint32_t* errMsg);
1057
1058 /**
1059 * Prepare a Commit packet for Multi Stream mode.
1060 *
1061 * Using the selected values prepare a Commit packet and return it to protocol
1062 * state engine.
1063 *
1064 * @param hello
1065 * Points to the received Hello packet
1066 * @return
1067 * A pointer to the prepared Commit packet for multi stream mode
1068 */
1069 ZrtpPacketCommit* prepareCommitMultiStream(ZrtpPacketHello *hello);
1070
1071 /**
1072 * Prepare the DHPart1 packet.
1073 *
1074 * This method prepares a DHPart1 packet. The input to the method is always
1075 * a Commit packet received from the peer. Also we a in the role of the
1076 * Responder.
1077 *
1078 * When we receive a Commit packet we get the selected ciphers, hashes, etc
1079 * and cross-check if this is ok. Then we need to initialize a set of DH
1080 * keys according to the selected cipher. Using this data we prepare our DHPart1
1081 * packet.
1082 */
1083 ZrtpPacketDHPart* prepareDHPart1(ZrtpPacketCommit *commit, uint32_t* errMsg);
1084
1085 /**
1086 * Prepare the DHPart2 packet.
1087 *
1088 * This method prepares a DHPart2 packet. The input to the method is always
1089 * a DHPart1 packet received from the peer. Our peer sends the DH1Part as
1090 * response to our Commit packet. Thus we are in the role of the
1091 * Initiator.
1092 *
1093 */
1094 ZrtpPacketDHPart* prepareDHPart2(ZrtpPacketDHPart* dhPart1, uint32_t* errMsg);
1095
1096 /**
1097 * Prepare the Confirm1 packet.
1098 *
1099 * This method prepare the Confirm1 packet. The input to this method is the
1100 * DHPart2 packect received from our peer. The peer sends the DHPart2 packet
1101 * as response of our DHPart1. Here we are in the role of the Responder
1102 *
1103 */
1104 ZrtpPacketConfirm* prepareConfirm1(ZrtpPacketDHPart* dhPart2, uint32_t* errMsg);
1105
1106 /**
1107 * Prepare the Confirm1 packet in multi stream mode.
1108 *
1109 * This method prepares the Confirm1 packet. The state engine call this method
1110 * if multi stream mode is selected and a Commit packet was received. The input to
1111 * this method is the Commit.
1112 * Here we are in the role of the Responder
1113 *
1114 */
1115 ZrtpPacketConfirm* prepareConfirm1MultiStream(ZrtpPacketCommit* commit, uint32_t* errMsg);
1116
1117 /**
1118 * Prepare the Confirm2 packet.
1119 *
1120 * This method prepare the Confirm2 packet. The input to this method is the
1121 * Confirm1 packet received from our peer. The peer sends the Confirm1 packet
1122 * as response of our DHPart2. Here we are in the role of the Initiator
1123 */
1124 ZrtpPacketConfirm* prepareConfirm2(ZrtpPacketConfirm* confirm1, uint32_t* errMsg);
1125
1126 /**
1127 * Prepare the Confirm2 packet in multi stream mode.
1128 *
1129 * This method prepares the Confirm2 packet. The state engine call this method if
1130 * multi stream mode is active and in state CommitSent. The input to this method is
1131 * the Confirm1 packet received from our peer. The peer sends the Confirm1 packet
1132 * as response of our Commit packet in multi stream mode.
1133 * Here we are in the role of the Initiator
1134 */
1135 ZrtpPacketConfirm* prepareConfirm2MultiStream(ZrtpPacketConfirm* confirm1, uint32_t* errMsg);
1136
1137 /**
1138 * Prepare the Conf2Ack packet.
1139 *
1140 * This method prepare the Conf2Ack packet. The input to this method is the
1141 * Confirm2 packet received from our peer. The peer sends the Confirm2 packet
1142 * as response of our Confirm1. Here we are in the role of the Initiator
1143 */
1144 ZrtpPacketConf2Ack* prepareConf2Ack(ZrtpPacketConfirm* confirm2, uint32_t* errMsg);
1145
1146 /**
1147 * Prepare the ErrorAck packet.
1148 *
1149 * This method prepares the ErrorAck packet. The input to this method is the
1150 * Error packet received from the peer.
1151 */
1152 ZrtpPacketErrorAck* prepareErrorAck(ZrtpPacketError* epkt);
1153
1154 /**
1155 * Prepare the Error packet.
1156 *
1157 * This method prepares the Error packet. The input to this method is the
1158 * error code to be included into the message.
1159 */
1160 ZrtpPacketError* prepareError(uint32_t errMsg);
1161
1162 /**
1163 * Prepare a ClearAck packet.
1164 *
1165 * This method checks if the GoClear message is valid. If yes then switch
1166 * off SRTP processing, stop sending of RTP packets (pause transmit) and
1167 * inform the user about the fact. Only if user confirms the GoClear message
1168 * normal RTP processing is resumed.
1169 *
1170 * @return
1171 * NULL if GoClear could not be authenticated, a ClearAck packet
1172 * otherwise.
1173 */
1174 ZrtpPacketClearAck* prepareClearAck(ZrtpPacketGoClear* gpkt);
1175
1176 /**
1177 * Prepare the ErrorAck packet.
1178 *
1179 * This method prepares the ErrorAck packet. The input to this method is the
1180 * Error packet received from the peer.
1181 */
1182 ZrtpPacketPingAck* preparePingAck(ZrtpPacketPing* ppkt);
1183
1184 /**
1185 * Prepare the RelayAck packet.
1186 *
1187 * This method prepares the RelayAck packet. The input to this method is the
1188 * SASrelay packet received from the peer.
1189 */
1190 ZrtpPacketRelayAck* prepareRelayAck(ZrtpPacketSASrelay* srly, uint32_t* errMsg);
1191
1192 /**
1193 * Prepare a GoClearAck packet w/o HMAC
1194 *
1195 * Prepare a GoCLear packet without a HMAC but with a short error message.
1196 * This type of GoClear is used if something went wrong during the ZRTP
1197 * negotiation phase.
1198 *
1199 * @return
1200 * A goClear packet without HMAC
1201 */
1202 ZrtpPacketGoClear* prepareGoClear(uint32_t errMsg = 0);
1203
1204 /**
1205 * Compare the hvi values.
1206 *
1207 * Compare a received Commit packet with our Commit packet and returns
1208 * which Commit packt is "more important". See chapter 5.2 to get further
1209 * information how to compare Commit packets.
1210 *
1211 * @param commit
1212 * Pointer to the peer's commit packet we just received.
1213 * @return
1214 * <0 if our Commit packet is "less important"
1215 * >0 if our Commit is "more important"
1216 * 0 shouldn't happen because we compare crypto hashes
1217 */
1218 int32_t compareCommit(ZrtpPacketCommit *commit);
1219
1220 /**
1221 * Verify the H2 hash image.
1222 *
1223 * Verifies the H2 hash contained in a received commit message.
1224 * This functions just verifies H2 but does not store it.
1225 *
1226 * @param commit
1227 * Pointer to the peer's commit packet we just received.
1228 * @return
1229 * true if H2 is ok and verified
1230 * false if H2 could not be verified
1231 */
1232 bool verifyH2(ZrtpPacketCommit *commit);
1233
1234 /**
1235 * Send information messages to the hosting environment.
1236 *
1237 * The ZRTP implementation uses this method to send information messages
1238 * to the host. Along with the message ZRTP provides a severity indicator
1239 * that defines: Info, Warning, Error, Alert. Refer to the MessageSeverity
1240 * enum in the ZrtpCallback class.
1241 *
1242 * @param severity
1243 * This defines the message's severity
1244 * @param subCode
1245 * The subcode identifying the reason.
1246 * @see ZrtpCodes#MessageSeverity
1247 */
1248 void sendInfo(GnuZrtpCodes::MessageSeverity severity, int32_t subCode);
1249
1250 /**
1251 * ZRTP state engine calls this if the negotiation failed.
1252 *
1253 * ZRTP calls this method in case ZRTP negotiation failed. The parameters
1254 * show the severity as well as some explanatory text.
1255 *
1256 * @param severity
1257 * This defines the message's severity
1258 * @param subCode
1259 * The subcode identifying the reason.
1260 * @see ZrtpCodes#MessageSeverity
1261 */
1262 void zrtpNegotiationFailed(GnuZrtpCodes::MessageSeverity severity, int32_t subCode);
1263
1264 /**
1265 * ZRTP state engine calls this method if the other side does not support ZRTP.
1266 *
1267 * If the other side does not answer the ZRTP <em>Hello</em> packets then
1268 * ZRTP calls this method,
1269 *
1270 */
1271 void zrtpNotSuppOther();
1272
1273 /**
1274 * Signal SRTP secrets are ready.
1275 *
1276 * This method calls a callback method to inform the host that the SRTP
1277 * secrets are ready.
1278 *
1279 * @param part
1280 * Defines for which part (sender or receiver) to switch on security
1281 * @return
1282 * Returns false if something went wrong during initialization of SRTP
1283 * context. Propagate error back to state engine.
1284 */
1285 bool srtpSecretsReady(EnableSecurity part);
1286
1287 /**
1288 * Switch off SRTP secrets.
1289 *
1290 * This method calls a callback method to inform the host that the SRTP
1291 * secrets shall be cleared.
1292 *
1293 * @param part
1294 * Defines for which part (sender or receiver) to clear
1295 */
1296 void srtpSecretsOff(EnableSecurity part);
1297
1298 /**
1299 * ZRTP state engine calls these methods to enter or leave its
1300 * synchronization mutex.
1301 */
1302 void synchEnter();
1303
1304 void synchLeave();
1305
1306 /**
1307 * Helper function to store ZRTP message data in a temporary buffer
1308 *
1309 * This functions first clears the temporary buffer, then stores
1310 * the packet's data to it. We use this to check the packet's HMAC
1311 * after we received the HMAC key in to following packet.
1312 *
1313 * @param data
1314 * Pointer to the packet's ZRTP message
1315 */
1316 void storeMsgTemp(ZrtpPacketBase* pkt);
1317
1318 /**
1319 * Helper function to check a ZRTP message HMAC
1320 *
1321 * This function gets a HMAC key and uses it to compute a HMAC
1322 * with this key and the stored data of a previous received ZRTP
1323 * message. It compares the computed HMAC and the HMAC stored in
1324 * the received message and returns the result.
1325 *
1326 * @param key
1327 * Pointer to the HMAC key.
1328 * @return
1329 * Returns true if the computed HMAC and the stored HMAC match,
1330 * false otherwise.
1331 */
1332 bool checkMsgHmac(uint8_t* key);
1333
1334 /**
1335 * Set the client ID for ZRTP Hello message.
1336 *
1337 * The user of ZRTP must set its id to identify itself in the
1338 * ZRTP HELLO message. The maximum length is 16 characters. Shorter
1339 * id string are allowed, they will be filled with blanks. A longer id
1340 * is truncated to 16 characters.
1341 *
1342 * The identifier is set in the Hello packet of ZRTP. Thus only after
1343 * setting the identifier ZRTP can compute the HMAC and the final
1344 * helloHash.
1345 *
1346 * @param id
1347 * The client's id
1348 */
Alexandre Lisionddd731e2014-01-31 11:50:08 -05001349 void setClientId(std::string id);
Alexandre Lision51140e12013-12-02 10:54:09 -05001350};
1351
1352/**
1353 * @}
1354 */
1355#endif // ZRTP
1356