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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 static const uint8_t kExternalHmacTestCase0Data[8] = { | 31 static const uint8_t kExternalHmacTestCase0Data[8] = { |
32 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 // "Hi There" | 32 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 // "Hi There" |
33 }; | 33 }; |
34 | 34 |
35 static const uint8_t kExternalHmacFakeTag[10] = { | 35 static const uint8_t kExternalHmacFakeTag[10] = { |
36 0xba, 0xdd, 0xba, 0xdd, 0xba, 0xdd, 0xba, 0xdd, 0xba, 0xdd | 36 0xba, 0xdd, 0xba, 0xdd, 0xba, 0xdd, 0xba, 0xdd, 0xba, 0xdd |
37 }; | 37 }; |
38 | 38 |
39 static const srtp_auth_test_case_t kExternalHmacTestCase0 = { | 39 static const srtp_auth_test_case_t kExternalHmacTestCase0 = { |
40 20, // Octets in key | 40 20, // Octets in key |
41 const_cast<uint8_t*>(kExternalHmacTestCase0Key), // Key | 41 const_cast<uint8_t*>(kExternalHmacTestCase0Key), // Key |
42 8, // Octets in data | 42 8, // Octets in data |
43 const_cast<uint8_t*>(kExternalHmacTestCase0Data), // Data | 43 const_cast<uint8_t*>(kExternalHmacTestCase0Data), // Data |
44 10, // Octets in tag | 44 10, // Octets in tag |
45 const_cast<uint8_t*>(kExternalHmacFakeTag), // Tag | 45 const_cast<uint8_t*>(kExternalHmacFakeTag), // Tag |
46 NULL // Pointer to next | 46 nullptr // Pointer to next |
47 // testcase | 47 // testcase |
48 }; | 48 }; |
49 | 49 |
50 static const char kExternalHmacDescription[] = | 50 static const char kExternalHmacDescription[] = |
51 "external hmac sha-1 authentication"; | 51 "external hmac sha-1 authentication"; |
52 | 52 |
53 // srtp_auth_type_t external_hmac is the hmac metaobject | 53 // srtp_auth_type_t external_hmac is the hmac metaobject |
54 | 54 |
55 static const srtp_auth_type_t external_hmac = { | 55 static const srtp_auth_type_t external_hmac = { |
56 external_hmac_alloc, | 56 external_hmac_alloc, |
57 external_hmac_dealloc, | 57 external_hmac_dealloc, |
(...skipping 15 matching lines...) Expand all Loading... |
73 // than 20 bytes yet | 73 // than 20 bytes yet |
74 if (key_len > 20) | 74 if (key_len > 20) |
75 return srtp_err_status_bad_param; | 75 return srtp_err_status_bad_param; |
76 | 76 |
77 // Check output length - should be less than 20 bytes/ | 77 // Check output length - should be less than 20 bytes/ |
78 if (out_len > 20) | 78 if (out_len > 20) |
79 return srtp_err_status_bad_param; | 79 return srtp_err_status_bad_param; |
80 | 80 |
81 // Allocate memory for auth and hmac_ctx_t structures. | 81 // Allocate memory for auth and hmac_ctx_t structures. |
82 pointer = new uint8_t[(sizeof(ExternalHmacContext) + sizeof(srtp_auth_t))]; | 82 pointer = new uint8_t[(sizeof(ExternalHmacContext) + sizeof(srtp_auth_t))]; |
83 if (pointer == NULL) | 83 if (pointer == nullptr) |
84 return srtp_err_status_alloc_fail; | 84 return srtp_err_status_alloc_fail; |
85 | 85 |
86 // Set pointers | 86 // Set pointers |
87 *a = (srtp_auth_t *)pointer; | 87 *a = (srtp_auth_t *)pointer; |
88 // |external_hmac| is const and libsrtp expects |type| to be non-const. | 88 // |external_hmac| is const and libsrtp expects |type| to be non-const. |
89 // const conversion is required. |external_hmac| is constant because we don't | 89 // const conversion is required. |external_hmac| is constant because we don't |
90 // want to increase global count in Chrome. | 90 // want to increase global count in Chrome. |
91 (*a)->type = const_cast<srtp_auth_type_t*>(&external_hmac); | 91 (*a)->type = const_cast<srtp_auth_type_t*>(&external_hmac); |
92 (*a)->state = pointer + sizeof(srtp_auth_t); | 92 (*a)->state = pointer + sizeof(srtp_auth_t); |
93 (*a)->out_len = out_len; | 93 (*a)->out_len = out_len; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const_cast<srtp_auth_type_t*>(&external_hmac), EXTERNAL_HMAC_SHA1); | 145 const_cast<srtp_auth_type_t*>(&external_hmac), EXTERNAL_HMAC_SHA1); |
146 if (status) { | 146 if (status) { |
147 LOG(LS_ERROR) << "Error in replacing default auth module, error: " | 147 LOG(LS_ERROR) << "Error in replacing default auth module, error: " |
148 << status; | 148 << status; |
149 return srtp_err_status_fail; | 149 return srtp_err_status_fail; |
150 } | 150 } |
151 return srtp_err_status_ok; | 151 return srtp_err_status_ok; |
152 } | 152 } |
153 | 153 |
154 #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) | 154 #endif // defined(HAVE_SRTP) && defined(ENABLE_EXTERNAL_AUTH) |
OLD | NEW |