| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/pc/externalhmac.h" | 11 #include "webrtc/pc/externalhmac.h" |
| 12 | 12 |
| 13 #include <stdlib.h> // For malloc/free. | 13 #include <stdlib.h> // For malloc/free. |
| 14 | 14 |
| 15 #include "webrtc/base/logging.h" |
| 16 |
| 15 #ifdef HAVE_SRTP | 17 #ifdef HAVE_SRTP |
| 16 extern "C" { | |
| 17 #ifdef SRTP_RELATIVE_PATH | |
| 18 #include "crypto_kernel.h" // NOLINT | |
| 19 #include "srtp.h" // NOLINT | |
| 20 #else | |
| 21 #include "third_party/libsrtp/crypto/include/crypto_kernel.h" | 18 #include "third_party/libsrtp/crypto/include/crypto_kernel.h" |
| 22 #include "third_party/libsrtp/include/srtp.h" | 19 #include "third_party/libsrtp/include/srtp.h" |
| 23 #endif // SRTP_RELATIVE_PATH | |
| 24 } | |
| 25 #endif // HAVE_SRTP | 20 #endif // HAVE_SRTP |
| 26 | 21 |
| 27 #include "webrtc/base/logging.h" | |
| 28 | |
| 29 #ifdef COMPILING_AGAINST_LIBSRTP1 | |
| 30 #define srtp_auth_type_t auth_type_t | |
| 31 | |
| 32 #define srtp_auth_init_func auth_init_func | |
| 33 #define srtp_auth_compute_func auth_compute_func | |
| 34 #define srtp_auth_update_func auth_update_func | |
| 35 #define srtp_auth_start_func auth_start_func | |
| 36 #define srtp_auth_test_case_t auth_test_case_t | |
| 37 | |
| 38 #define srtp_replace_auth_type crypto_kernel_replace_auth_type | |
| 39 #endif // COMPILING_AGAINST_LIBSRTP1 | |
| 40 | |
| 41 #if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) | 22 #if defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) |
| 42 | 23 |
| 43 // Begin test case 0 */ | 24 // Begin test case 0 */ |
| 44 static const uint8_t kExternalHmacTestCase0Key[20] = { | 25 static const uint8_t kExternalHmacTestCase0Key[20] = { |
| 45 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | 26 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
| 46 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | 27 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, |
| 47 0x0b, 0x0b, 0x0b, 0x0b | 28 0x0b, 0x0b, 0x0b, 0x0b |
| 48 }; | 29 }; |
| 49 | 30 |
| 50 static const uint8_t kExternalHmacTestCase0Data[8] = { | 31 static const uint8_t kExternalHmacTestCase0Data[8] = { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 const_cast<uint8_t*>(kExternalHmacFakeTag), // Tag | 45 const_cast<uint8_t*>(kExternalHmacFakeTag), // Tag |
| 65 NULL // Pointer to next | 46 NULL // Pointer to next |
| 66 // testcase | 47 // testcase |
| 67 }; | 48 }; |
| 68 | 49 |
| 69 static const char kExternalHmacDescription[] = | 50 static const char kExternalHmacDescription[] = |
| 70 "external hmac sha-1 authentication"; | 51 "external hmac sha-1 authentication"; |
| 71 | 52 |
| 72 // srtp_auth_type_t external_hmac is the hmac metaobject | 53 // srtp_auth_type_t external_hmac is the hmac metaobject |
| 73 | 54 |
| 74 #ifdef COMPILING_AGAINST_LIBSRTP1 | |
| 75 static const srtp_auth_type_t external_hmac = { | 55 static const srtp_auth_type_t external_hmac = { |
| 76 external_hmac_alloc, | 56 external_hmac_alloc, |
| 77 external_hmac_dealloc, | 57 external_hmac_dealloc, |
| 78 (srtp_auth_init_func) external_hmac_init, | |
| 79 (srtp_auth_compute_func) external_hmac_compute, | |
| 80 (srtp_auth_update_func) external_hmac_update, | |
| 81 (srtp_auth_start_func) external_hmac_start, | |
| 82 const_cast<char*>(kExternalHmacDescription), | |
| 83 0, // Instance count. | |
| 84 const_cast<srtp_auth_test_case_t*>(&kExternalHmacTestCase0), | |
| 85 NULL, // No debugging module. | |
| 86 EXTERNAL_HMAC_SHA1 | |
| 87 }; | |
| 88 #else | |
| 89 static const srtp_auth_type_t external_hmac = { | |
| 90 external_hmac_alloc, | |
| 91 external_hmac_dealloc, | |
| 92 (srtp_auth_init_func) external_hmac_init, | 58 (srtp_auth_init_func) external_hmac_init, |
| 93 (srtp_auth_compute_func) external_hmac_compute, | 59 (srtp_auth_compute_func) external_hmac_compute, |
| 94 (srtp_auth_update_func) external_hmac_update, | 60 (srtp_auth_update_func) external_hmac_update, |
| 95 (srtp_auth_start_func) external_hmac_start, | 61 (srtp_auth_start_func) external_hmac_start, |
| 96 const_cast<char*>(kExternalHmacDescription), | 62 const_cast<char*>(kExternalHmacDescription), |
| 97 const_cast<srtp_auth_test_case_t*>(&kExternalHmacTestCase0), | 63 const_cast<srtp_auth_test_case_t*>(&kExternalHmacTestCase0), |
| 98 EXTERNAL_HMAC_SHA1 | 64 EXTERNAL_HMAC_SHA1 |
| 99 }; | 65 }; |
| 100 #endif // COMPILING_AGAINST_LIBSRTP1 | |
| 101 | 66 |
| 102 srtp_err_status_t external_hmac_alloc(srtp_auth_t** a, | 67 srtp_err_status_t external_hmac_alloc(srtp_auth_t** a, |
| 103 int key_len, | 68 int key_len, |
| 104 int out_len) { | 69 int out_len) { |
| 105 uint8_t* pointer; | 70 uint8_t* pointer; |
| 106 | 71 |
| 107 // Check key length - note that we don't support keys larger | 72 // Check key length - note that we don't support keys larger |
| 108 // than 20 bytes yet | 73 // than 20 bytes yet |
| 109 if (key_len > 20) | 74 if (key_len > 20) |
| 110 return srtp_err_status_bad_param; | 75 return srtp_err_status_bad_param; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 const_cast<srtp_auth_type_t*>(&external_hmac), EXTERNAL_HMAC_SHA1); | 145 const_cast<srtp_auth_type_t*>(&external_hmac), EXTERNAL_HMAC_SHA1); |
| 181 if (status) { | 146 if (status) { |
| 182 LOG(LS_ERROR) << "Error in replacing default auth module, error: " | 147 LOG(LS_ERROR) << "Error in replacing default auth module, error: " |
| 183 << status; | 148 << status; |
| 184 return srtp_err_status_fail; | 149 return srtp_err_status_fail; |
| 185 } | 150 } |
| 186 return srtp_err_status_ok; | 151 return srtp_err_status_ok; |
| 187 } | 152 } |
| 188 | 153 |
| 189 #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) | 154 #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) |
| OLD | NEW |