xref: /aosp_15_r20/external/webrtc/pc/external_hmac.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2014 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef PC_EXTERNAL_HMAC_H_
12*d9f75844SAndroid Build Coastguard Worker #define PC_EXTERNAL_HMAC_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker // External libsrtp HMAC auth module which implements methods defined in
15*d9f75844SAndroid Build Coastguard Worker // auth_type_t.
16*d9f75844SAndroid Build Coastguard Worker // The default auth module will be replaced only when the ENABLE_EXTERNAL_AUTH
17*d9f75844SAndroid Build Coastguard Worker // flag is enabled. This allows us to access to authentication keys,
18*d9f75844SAndroid Build Coastguard Worker // as the default auth implementation doesn't provide access and avoids
19*d9f75844SAndroid Build Coastguard Worker // hashing each packet twice.
20*d9f75844SAndroid Build Coastguard Worker 
21*d9f75844SAndroid Build Coastguard Worker // How will libsrtp select this module?
22*d9f75844SAndroid Build Coastguard Worker // Libsrtp defines authentication function types identified by an unsigned
23*d9f75844SAndroid Build Coastguard Worker // integer, e.g. SRTP_HMAC_SHA1 is 3. Using authentication ids, the
24*d9f75844SAndroid Build Coastguard Worker // application can plug any desired authentication modules into libsrtp.
25*d9f75844SAndroid Build Coastguard Worker // libsrtp also provides a mechanism to select different auth functions for
26*d9f75844SAndroid Build Coastguard Worker // individual streams. This can be done by setting the right value in
27*d9f75844SAndroid Build Coastguard Worker // the auth_type of srtp_policy_t. The application must first register auth
28*d9f75844SAndroid Build Coastguard Worker // functions and the corresponding authentication id using
29*d9f75844SAndroid Build Coastguard Worker // crypto_kernel_replace_auth_type function.
30*d9f75844SAndroid Build Coastguard Worker 
31*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
32*d9f75844SAndroid Build Coastguard Worker 
33*d9f75844SAndroid Build Coastguard Worker #include "third_party/libsrtp/crypto/include/crypto_types.h"
34*d9f75844SAndroid Build Coastguard Worker #include "third_party/libsrtp/include/srtp.h"
35*d9f75844SAndroid Build Coastguard Worker #include "third_party/libsrtp/include/srtp_priv.h"
36*d9f75844SAndroid Build Coastguard Worker 
37*d9f75844SAndroid Build Coastguard Worker #define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1
38*d9f75844SAndroid Build Coastguard Worker #define HMAC_KEY_LENGTH 20
39*d9f75844SAndroid Build Coastguard Worker 
40*d9f75844SAndroid Build Coastguard Worker // The HMAC context structure used to store authentication keys.
41*d9f75844SAndroid Build Coastguard Worker // The pointer to the key  will be allocated in the external_hmac_init function.
42*d9f75844SAndroid Build Coastguard Worker // This pointer is owned by srtp_t in a template context.
43*d9f75844SAndroid Build Coastguard Worker typedef struct {
44*d9f75844SAndroid Build Coastguard Worker   uint8_t key[HMAC_KEY_LENGTH];
45*d9f75844SAndroid Build Coastguard Worker   int key_length;
46*d9f75844SAndroid Build Coastguard Worker } ExternalHmacContext;
47*d9f75844SAndroid Build Coastguard Worker 
48*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_hmac_alloc(srtp_auth_t** a,
49*d9f75844SAndroid Build Coastguard Worker                                       int key_len,
50*d9f75844SAndroid Build Coastguard Worker                                       int out_len);
51*d9f75844SAndroid Build Coastguard Worker 
52*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_hmac_dealloc(srtp_auth_t* a);
53*d9f75844SAndroid Build Coastguard Worker 
54*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_hmac_init(void* state,
55*d9f75844SAndroid Build Coastguard Worker                                      const uint8_t* key,
56*d9f75844SAndroid Build Coastguard Worker                                      int key_len);
57*d9f75844SAndroid Build Coastguard Worker 
58*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_hmac_start(void* state);
59*d9f75844SAndroid Build Coastguard Worker 
60*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_hmac_update(void* state,
61*d9f75844SAndroid Build Coastguard Worker                                        const uint8_t* message,
62*d9f75844SAndroid Build Coastguard Worker                                        int msg_octets);
63*d9f75844SAndroid Build Coastguard Worker 
64*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_hmac_compute(void* state,
65*d9f75844SAndroid Build Coastguard Worker                                         const uint8_t* message,
66*d9f75844SAndroid Build Coastguard Worker                                         int msg_octets,
67*d9f75844SAndroid Build Coastguard Worker                                         int tag_len,
68*d9f75844SAndroid Build Coastguard Worker                                         uint8_t* result);
69*d9f75844SAndroid Build Coastguard Worker 
70*d9f75844SAndroid Build Coastguard Worker srtp_err_status_t external_crypto_init();
71*d9f75844SAndroid Build Coastguard Worker 
72*d9f75844SAndroid Build Coastguard Worker #endif  // PC_EXTERNAL_HMAC_H_
73