blob: 74652b0894f6d62b053ed5175b2435390abc2e35 [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
11#ifndef TALK_SESSION_MEDIA_EXTERNAL_HMAC_H_
12#define TALK_SESSION_MEDIA_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. 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.
30#if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH)
31
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000032#include "webrtc/base/basictypes.h"
jiayl@webrtc.orga197a5e2015-03-23 22:11:49 +000033extern "C" {
kjellander7bc7c062016-04-22 04:57:49 -070034#ifdef SRTP_RELATIVE_PATH
35#include "auth.h" // NOLINT
36#else
jiayl@webrtc.orga197a5e2015-03-23 22:11:49 +000037#include "third_party/libsrtp/srtp/crypto/include/auth.h"
kjellander7bc7c062016-04-22 04:57:49 -070038#endif // SRTP_RELATIVE_PATH
jiayl@webrtc.orga197a5e2015-03-23 22:11:49 +000039}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000040
41#define EXTERNAL_HMAC_SHA1 HMAC_SHA1 + 1
42#define HMAC_KEY_LENGTH 20
43
44// The HMAC context structure used to store authentication keys.
45// The pointer to the key will be allocated in the external_hmac_init function.
46// This pointer is owned by srtp_t in a template context.
47typedef struct {
Peter Boström0c4e06b2015-10-07 12:23:21 +020048 uint8_t key[HMAC_KEY_LENGTH];
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000049 int key_length;
pbos@webrtc.orga9cf0792014-12-18 09:12:21 +000050} ExternalHmacContext;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000051
henrike@webrtc.org8b610112014-03-18 21:39:10 +000052err_status_t external_hmac_alloc(auth_t** a, int key_len, int out_len);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000053
henrike@webrtc.org8b610112014-03-18 21:39:10 +000054err_status_t external_hmac_dealloc(auth_t* a);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000055
pbos@webrtc.orga9cf0792014-12-18 09:12:21 +000056err_status_t external_hmac_init(ExternalHmacContext* state,
henrike@webrtc.org8b610112014-03-18 21:39:10 +000057 const uint8_t* key,
58 int key_len);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000059
pbos@webrtc.orga9cf0792014-12-18 09:12:21 +000060err_status_t external_hmac_start(ExternalHmacContext* state);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000061
pbos@webrtc.orga9cf0792014-12-18 09:12:21 +000062err_status_t external_hmac_update(ExternalHmacContext* state,
henrike@webrtc.org8b610112014-03-18 21:39:10 +000063 const uint8_t* message,
64 int msg_octets);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000065
pbos@webrtc.orga9cf0792014-12-18 09:12:21 +000066err_status_t external_hmac_compute(ExternalHmacContext* state,
henrike@webrtc.org8b610112014-03-18 21:39:10 +000067 const void* message,
68 int msg_octets,
69 int tag_len,
70 uint8_t* result);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000071
henrike@webrtc.org8b610112014-03-18 21:39:10 +000072err_status_t external_crypto_init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +000073
74#endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH)
75#endif // TALK_SESSION_MEDIA_EXTERNAL_HMAC_H_