Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: webrtc/pc/externalhmac.h

Issue 2407743002: Fix externalhmac.h/.cc to compile with libsrtp 1 and 2 (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/pc/externalhmac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_PC_EXTERNALHMAC_H_ 11 #ifndef WEBRTC_PC_EXTERNALHMAC_H_
12 #define WEBRTC_PC_EXTERNALHMAC_H_ 12 #define WEBRTC_PC_EXTERNALHMAC_H_
13 13
14 // External libsrtp HMAC auth module which implements methods defined in 14 // External libsrtp HMAC auth module which implements methods defined in
15 // auth_type_t. 15 // auth_type_t.
16 // The default auth module will be replaced only when the ENABLE_EXTERNAL_AUTH 16 // The default auth module will be replaced only when the ENABLE_EXTERNAL_AUTH
17 // flag is enabled. This allows us to access to authentication keys, 17 // flag is enabled. This allows us to access to authentication keys,
18 // as the default auth implementation doesn't provide access and avoids 18 // as the default auth implementation doesn't provide access and avoids
19 // hashing each packet twice. 19 // hashing each packet twice.
20 20
21 // How will libsrtp select this module? 21 // How will libsrtp select this module?
22 // Libsrtp defines authentication function types identified by an unsigned 22 // Libsrtp defines authentication function types identified by an unsigned
23 // integer, e.g. HMAC_SHA1 is 3. Using authentication ids, the application 23 // integer, e.g. SRTP_HMAC_SHA1 is 3. Using authentication ids, the
24 // can plug any desired authentication modules into libsrtp. 24 // application can plug any desired authentication modules into libsrtp.
25 // libsrtp also provides a mechanism to select different auth functions for 25 // libsrtp also provides a mechanism to select different auth functions for
26 // individual streams. This can be done by setting the right value in 26 // individual streams. This can be done by setting the right value in
27 // the auth_type of srtp_policy_t. The application must first register auth 27 // the auth_type of srtp_policy_t. The application must first register auth
28 // functions and the corresponding authentication id using 28 // functions and the corresponding authentication id using
29 // crypto_kernel_replace_auth_type function. 29 // crypto_kernel_replace_auth_type function.
30 30
31 #include "webrtc/base/basictypes.h" 31 #include "webrtc/base/basictypes.h"
32 #ifdef HAVE_SRTP 32 #ifdef HAVE_SRTP
33 extern "C" { 33 extern "C" {
34 #ifdef SRTP_RELATIVE_PATH 34 #ifdef SRTP_RELATIVE_PATH
35 #include "auth.h" // NOLINT 35 #include "auth.h" // NOLINT
36 #else 36 #else
37 #include "third_party/libsrtp/crypto/include/auth.h" 37 #include "third_party/libsrtp/crypto/include/auth.h"
38 #endif // SRTP_RELATIVE_PATH 38 #endif // SRTP_RELATIVE_PATH
39 } 39 }
40 #endif // HAVE_SRTP 40 #endif // HAVE_SRTP
41 41
42 #if defined(HAVE_SRTP) && !defined(SRTP_HMAC_SHA1)
43 // Include compatibility shims to compile against libsrtp 1.x.
44 // TODO(mattdr): Remove once Chromium uses libsrtp 2.
45
46 // Remember that the definition of SRTP_HMAC_SHA1 is synthetic.
47 #define COMPILING_AGAINST_LIBSRTP1 1
48
49 #define SRTP_HMAC_SHA1 HMAC_SHA1
50 #define srtp_auth_t auth_t
51 #endif
52
42 #if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) 53 #if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH)
43 54
44 #define EXTERNAL_HMAC_SHA1 HMAC_SHA1 + 1 55 #define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1
45 #define HMAC_KEY_LENGTH 20 56 #define HMAC_KEY_LENGTH 20
46 57
47 // The HMAC context structure used to store authentication keys. 58 // The HMAC context structure used to store authentication keys.
48 // The pointer to the key will be allocated in the external_hmac_init function. 59 // The pointer to the key will be allocated in the external_hmac_init function.
49 // This pointer is owned by srtp_t in a template context. 60 // This pointer is owned by srtp_t in a template context.
50 typedef struct { 61 typedef struct {
51 uint8_t key[HMAC_KEY_LENGTH]; 62 uint8_t key[HMAC_KEY_LENGTH];
52 int key_length; 63 int key_length;
53 } ExternalHmacContext; 64 } ExternalHmacContext;
54 65
55 err_status_t external_hmac_alloc(auth_t** a, int key_len, int out_len); 66 srtp_err_status_t external_hmac_alloc(srtp_auth_t** a,
67 int key_len,
68 int out_len);
56 69
57 err_status_t external_hmac_dealloc(auth_t* a); 70 srtp_err_status_t external_hmac_dealloc(srtp_auth_t* a);
58 71
59 err_status_t external_hmac_init(ExternalHmacContext* state, 72 srtp_err_status_t external_hmac_init(ExternalHmacContext* state,
60 const uint8_t* key, 73 const uint8_t* key,
61 int key_len); 74 int key_len);
62 75
63 err_status_t external_hmac_start(ExternalHmacContext* state); 76 srtp_err_status_t external_hmac_start(ExternalHmacContext* state);
64 77
65 err_status_t external_hmac_update(ExternalHmacContext* state, 78 srtp_err_status_t external_hmac_update(ExternalHmacContext* state,
66 const uint8_t* message, 79 const uint8_t* message,
67 int msg_octets); 80 int msg_octets);
68 81
69 err_status_t external_hmac_compute(ExternalHmacContext* state, 82 srtp_err_status_t external_hmac_compute(ExternalHmacContext* state,
70 const void* message, 83 const void* message,
71 int msg_octets, 84 int msg_octets,
72 int tag_len, 85 int tag_len,
73 uint8_t* result); 86 uint8_t* result);
74 87
75 err_status_t external_crypto_init(); 88 srtp_err_status_t external_crypto_init();
76 89
77 #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) 90 #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH)
78 #endif // WEBRTC_PC_EXTERNALHMAC_H_ 91 #endif // WEBRTC_PC_EXTERNALHMAC_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/pc/externalhmac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698