henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 11 | #ifndef WEBRTC_PC_EXTERNALHMAC_H_ |
| 12 | #define WEBRTC_PC_EXTERNALHMAC_H_ |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 13 | |
| 14 | // External libsrtp HMAC auth module which implements methods defined in |
| 15 | // auth_type_t. |
| 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, |
| 18 | // as the default auth implementation doesn't provide access and avoids |
| 19 | // hashing each packet twice. |
| 20 | |
| 21 | // How will libsrtp select this module? |
| 22 | // Libsrtp defines authentication function types identified by an unsigned |
| 23 | // integer, e.g. HMAC_SHA1 is 3. Using authentication ids, the application |
| 24 | // can plug any desired authentication modules into libsrtp. |
| 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 |
| 27 | // the auth_type of srtp_policy_t. The application must first register auth |
| 28 | // functions and the corresponding authentication id using |
| 29 | // crypto_kernel_replace_auth_type function. |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 30 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 31 | #include "webrtc/base/basictypes.h" |
mattdr | 51f2919 | 2016-09-28 14:08:46 -0700 | [diff] [blame^] | 32 | #ifdef HAVE_SRTP |
jiayl@webrtc.org | a197a5e | 2015-03-23 22:11:49 +0000 | [diff] [blame] | 33 | extern "C" { |
kjellander | 7bc7c06 | 2016-04-22 04:57:49 -0700 | [diff] [blame] | 34 | #ifdef SRTP_RELATIVE_PATH |
| 35 | #include "auth.h" // NOLINT |
| 36 | #else |
mattdr | 51f2919 | 2016-09-28 14:08:46 -0700 | [diff] [blame^] | 37 | #include "third_party/libsrtp/crypto/include/auth.h" |
kjellander | 7bc7c06 | 2016-04-22 04:57:49 -0700 | [diff] [blame] | 38 | #endif // SRTP_RELATIVE_PATH |
jiayl@webrtc.org | a197a5e | 2015-03-23 22:11:49 +0000 | [diff] [blame] | 39 | } |
mattdr | 51f2919 | 2016-09-28 14:08:46 -0700 | [diff] [blame^] | 40 | #endif // HAVE_SRTP |
| 41 | |
| 42 | #if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 43 | |
| 44 | #define EXTERNAL_HMAC_SHA1 HMAC_SHA1 + 1 |
| 45 | #define HMAC_KEY_LENGTH 20 |
| 46 | |
| 47 | // The HMAC context structure used to store authentication keys. |
| 48 | // 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. |
| 50 | typedef struct { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 51 | uint8_t key[HMAC_KEY_LENGTH]; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 52 | int key_length; |
pbos@webrtc.org | a9cf079 | 2014-12-18 09:12:21 +0000 | [diff] [blame] | 53 | } ExternalHmacContext; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 54 | |
henrike@webrtc.org | 8b61011 | 2014-03-18 21:39:10 +0000 | [diff] [blame] | 55 | err_status_t external_hmac_alloc(auth_t** a, int key_len, int out_len); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 56 | |
henrike@webrtc.org | 8b61011 | 2014-03-18 21:39:10 +0000 | [diff] [blame] | 57 | err_status_t external_hmac_dealloc(auth_t* a); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 58 | |
pbos@webrtc.org | a9cf079 | 2014-12-18 09:12:21 +0000 | [diff] [blame] | 59 | err_status_t external_hmac_init(ExternalHmacContext* state, |
henrike@webrtc.org | 8b61011 | 2014-03-18 21:39:10 +0000 | [diff] [blame] | 60 | const uint8_t* key, |
| 61 | int key_len); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 62 | |
pbos@webrtc.org | a9cf079 | 2014-12-18 09:12:21 +0000 | [diff] [blame] | 63 | err_status_t external_hmac_start(ExternalHmacContext* state); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 64 | |
pbos@webrtc.org | a9cf079 | 2014-12-18 09:12:21 +0000 | [diff] [blame] | 65 | err_status_t external_hmac_update(ExternalHmacContext* state, |
henrike@webrtc.org | 8b61011 | 2014-03-18 21:39:10 +0000 | [diff] [blame] | 66 | const uint8_t* message, |
| 67 | int msg_octets); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 68 | |
pbos@webrtc.org | a9cf079 | 2014-12-18 09:12:21 +0000 | [diff] [blame] | 69 | err_status_t external_hmac_compute(ExternalHmacContext* state, |
henrike@webrtc.org | 8b61011 | 2014-03-18 21:39:10 +0000 | [diff] [blame] | 70 | const void* message, |
| 71 | int msg_octets, |
| 72 | int tag_len, |
| 73 | uint8_t* result); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 74 | |
henrike@webrtc.org | 8b61011 | 2014-03-18 21:39:10 +0000 | [diff] [blame] | 75 | err_status_t external_crypto_init(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 76 | |
| 77 | #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 78 | #endif // WEBRTC_PC_EXTERNALHMAC_H_ |