1 /* 2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 #ifndef PC_EXTERNAL_HMAC_H_ 12 #define PC_EXTERNAL_HMAC_H_ 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. SRTP_HMAC_SHA1 is 3. Using authentication ids, the 24 // application 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. 30 31 #include <stdint.h> 32 33 #include "third_party/libsrtp/crypto/include/auth.h" 34 #include "third_party/libsrtp/crypto/include/crypto_types.h" 35 #include "third_party/libsrtp/include/srtp.h" 36 37 #define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1 38 #define HMAC_KEY_LENGTH 20 39 40 // The HMAC context structure used to store authentication keys. 41 // The pointer to the key will be allocated in the external_hmac_init function. 42 // This pointer is owned by srtp_t in a template context. 43 typedef struct { 44 uint8_t key[HMAC_KEY_LENGTH]; 45 int key_length; 46 } ExternalHmacContext; 47 48 srtp_err_status_t external_hmac_alloc(srtp_auth_t** a, 49 int key_len, 50 int out_len); 51 52 srtp_err_status_t external_hmac_dealloc(srtp_auth_t* a); 53 54 srtp_err_status_t external_hmac_init(void* state, 55 const uint8_t* key, 56 int key_len); 57 58 srtp_err_status_t external_hmac_start(void* state); 59 60 srtp_err_status_t external_hmac_update(void* state, 61 const uint8_t* message, 62 int msg_octets); 63 64 srtp_err_status_t external_hmac_compute(void* state, 65 const uint8_t* message, 66 int msg_octets, 67 int tag_len, 68 uint8_t* result); 69 70 srtp_err_status_t external_crypto_init(); 71 72 #endif // PC_EXTERNAL_HMAC_H_ 73