blob: f9f1a2cc6f7493d6747680cc2d56e6ca646fd3a5 [file] [log] [blame]
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2014 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.orga7b98182014-02-21 15:51:43 +00009 */
10
terelius8c011e52016-04-26 05:28:11 -070011#ifndef WEBRTC_PC_EXTERNALHMAC_H_
12#define WEBRTC_PC_EXTERNALHMAC_H_
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000013
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
mattdr8cab52d2016-10-10 15:33:37 -070023// integer, e.g. SRTP_HMAC_SHA1 is 3. Using authentication ids, the
24// application can plug any desired authentication modules into libsrtp.
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000025// 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.orga7b98182014-02-21 15:51:43 +000030
pbos7eb0e232017-01-02 07:32:25 -080031#include "webrtc/base/basictypes.h"
mattdr51f29192016-09-28 14:08:46 -070032#ifdef HAVE_SRTP
mattdr51f29192016-09-28 14:08:46 -070033#include "third_party/libsrtp/crypto/include/auth.h"
mattdr51f29192016-09-28 14:08:46 -070034#endif // HAVE_SRTP
35
36#if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH)
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000037
mattdr8cab52d2016-10-10 15:33:37 -070038#define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000039#define HMAC_KEY_LENGTH 20
40
41// The HMAC context structure used to store authentication keys.
42// The pointer to the key will be allocated in the external_hmac_init function.
43// This pointer is owned by srtp_t in a template context.
44typedef struct {
Peter Boström0c4e06b2015-10-07 12:23:21 +020045 uint8_t key[HMAC_KEY_LENGTH];
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000046 int key_length;
pbos@webrtc.orga9cf0792014-12-18 09:12:21 +000047} ExternalHmacContext;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000048
mattdr8cab52d2016-10-10 15:33:37 -070049srtp_err_status_t external_hmac_alloc(srtp_auth_t** a,
50 int key_len,
51 int out_len);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000052
mattdr8cab52d2016-10-10 15:33:37 -070053srtp_err_status_t external_hmac_dealloc(srtp_auth_t* a);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000054
mattdr8cab52d2016-10-10 15:33:37 -070055srtp_err_status_t external_hmac_init(ExternalHmacContext* state,
56 const uint8_t* key,
57 int key_len);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000058
mattdr8cab52d2016-10-10 15:33:37 -070059srtp_err_status_t external_hmac_start(ExternalHmacContext* state);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000060
mattdr8cab52d2016-10-10 15:33:37 -070061srtp_err_status_t external_hmac_update(ExternalHmacContext* state,
62 const uint8_t* message,
63 int msg_octets);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000064
mattdr8cab52d2016-10-10 15:33:37 -070065srtp_err_status_t external_hmac_compute(ExternalHmacContext* state,
66 const void* message,
67 int msg_octets,
68 int tag_len,
69 uint8_t* result);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000070
mattdr8cab52d2016-10-10 15:33:37 -070071srtp_err_status_t external_crypto_init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000072
73#endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH)
terelius8c011e52016-04-26 05:28:11 -070074#endif // WEBRTC_PC_EXTERNALHMAC_H_