henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef PC_EXTERNALHMAC_H_ |
| 12 | #define PC_EXTERNALHMAC_H_ |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [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 |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 23 | // integer, e.g. SRTP_HMAC_SHA1 is 3. Using authentication ids, the |
| 24 | // application can plug any desired authentication modules into libsrtp. |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 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 | [diff] [blame] | 30 | |
pbos | c7c26a0 | 2017-01-02 16:42:32 | [diff] [blame] | 31 | #include <stdint.h> |
| 32 | |
mattdr | 51f2919 | 2016-09-28 21:08:46 | [diff] [blame] | 33 | #include "third_party/libsrtp/crypto/include/auth.h" |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 34 | |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 35 | #define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1 |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 36 | #define HMAC_KEY_LENGTH 20 |
| 37 | |
| 38 | // The HMAC context structure used to store authentication keys. |
| 39 | // The pointer to the key will be allocated in the external_hmac_init function. |
| 40 | // This pointer is owned by srtp_t in a template context. |
| 41 | typedef struct { |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 42 | uint8_t key[HMAC_KEY_LENGTH]; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 43 | int key_length; |
pbos@webrtc.org | a9cf079 | 2014-12-18 09:12:21 | [diff] [blame] | 44 | } ExternalHmacContext; |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 45 | |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 46 | srtp_err_status_t external_hmac_alloc(srtp_auth_t** a, |
| 47 | int key_len, |
| 48 | int out_len); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 49 | |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 50 | srtp_err_status_t external_hmac_dealloc(srtp_auth_t* a); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 51 | |
Vlad Tsyrklevich | e8e8ad8 | 2017-12-07 02:38:22 | [diff] [blame] | 52 | srtp_err_status_t external_hmac_init(void* state, |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 53 | const uint8_t* key, |
| 54 | int key_len); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 55 | |
Vlad Tsyrklevich | e8e8ad8 | 2017-12-07 02:38:22 | [diff] [blame] | 56 | srtp_err_status_t external_hmac_start(void* state); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 57 | |
Vlad Tsyrklevich | e8e8ad8 | 2017-12-07 02:38:22 | [diff] [blame] | 58 | srtp_err_status_t external_hmac_update(void* state, |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 59 | const uint8_t* message, |
| 60 | int msg_octets); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 61 | |
Vlad Tsyrklevich | e8e8ad8 | 2017-12-07 02:38:22 | [diff] [blame] | 62 | srtp_err_status_t external_hmac_compute(void* state, |
| 63 | const uint8_t* message, |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 64 | int msg_octets, |
| 65 | int tag_len, |
| 66 | uint8_t* result); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 67 | |
mattdr | 8cab52d | 2016-10-10 22:33:37 | [diff] [blame] | 68 | srtp_err_status_t external_crypto_init(); |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 | [diff] [blame] | 69 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 70 | #endif // PC_EXTERNALHMAC_H_ |