external_hmac.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef PC_EXTERNAL_HMAC_H_
  11. #define PC_EXTERNAL_HMAC_H_
  12. // External libsrtp HMAC auth module which implements methods defined in
  13. // auth_type_t.
  14. // The default auth module will be replaced only when the ENABLE_EXTERNAL_AUTH
  15. // flag is enabled. This allows us to access to authentication keys,
  16. // as the default auth implementation doesn't provide access and avoids
  17. // hashing each packet twice.
  18. // How will libsrtp select this module?
  19. // Libsrtp defines authentication function types identified by an unsigned
  20. // integer, e.g. SRTP_HMAC_SHA1 is 3. Using authentication ids, the
  21. // application can plug any desired authentication modules into libsrtp.
  22. // libsrtp also provides a mechanism to select different auth functions for
  23. // individual streams. This can be done by setting the right value in
  24. // the auth_type of srtp_policy_t. The application must first register auth
  25. // functions and the corresponding authentication id using
  26. // crypto_kernel_replace_auth_type function.
  27. #include <stdint.h>
  28. #include "third_party/libsrtp/crypto/include/auth.h"
  29. #include "third_party/libsrtp/crypto/include/crypto_types.h"
  30. #include "third_party/libsrtp/include/srtp.h"
  31. #define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1
  32. #define HMAC_KEY_LENGTH 20
  33. // The HMAC context structure used to store authentication keys.
  34. // The pointer to the key will be allocated in the external_hmac_init function.
  35. // This pointer is owned by srtp_t in a template context.
  36. typedef struct {
  37. uint8_t key[HMAC_KEY_LENGTH];
  38. int key_length;
  39. } ExternalHmacContext;
  40. srtp_err_status_t external_hmac_alloc(srtp_auth_t** a,
  41. int key_len,
  42. int out_len);
  43. srtp_err_status_t external_hmac_dealloc(srtp_auth_t* a);
  44. srtp_err_status_t external_hmac_init(void* state,
  45. const uint8_t* key,
  46. int key_len);
  47. srtp_err_status_t external_hmac_start(void* state);
  48. srtp_err_status_t external_hmac_update(void* state,
  49. const uint8_t* message,
  50. int msg_octets);
  51. srtp_err_status_t external_hmac_compute(void* state,
  52. const uint8_t* message,
  53. int msg_octets,
  54. int tag_len,
  55. uint8_t* result);
  56. srtp_err_status_t external_crypto_init();
  57. #endif // PC_EXTERNAL_HMAC_H_