Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: media/cast/cast_defines.h

Issue 62843002: Cast: Added support for AES-CTR crypto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CAST_CAST_DEFINES_H_ 5 #ifndef MEDIA_CAST_CAST_DEFINES_H_
6 #define MEDIA_CAST_CAST_DEFINES_H_ 6 #define MEDIA_CAST_CAST_DEFINES_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 28 matching lines...) Expand all
39 kDefaultRtpMaxDelayMs = 100, 39 kDefaultRtpMaxDelayMs = 100,
40 }; 40 };
41 41
42 const uint16 kRtcpCastAllPacketsLost = 0xffff; 42 const uint16 kRtcpCastAllPacketsLost = 0xffff;
43 43
44 const size_t kMinLengthOfRtcp = 8; 44 const size_t kMinLengthOfRtcp = 8;
45 45
46 // Basic RTP header + cast header. 46 // Basic RTP header + cast header.
47 const size_t kMinLengthOfRtp = 12 + 6; 47 const size_t kMinLengthOfRtp = 12 + 6;
48 48
49 const size_t kAesBlockSize = 16;
50
49 // Each uint16 represents one packet id within a cast frame. 51 // Each uint16 represents one packet id within a cast frame.
50 typedef std::set<uint16> PacketIdSet; 52 typedef std::set<uint16> PacketIdSet;
51 // Each uint8 represents one cast frame. 53 // Each uint8 represents one cast frame.
52 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; 54 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
53 55
54 // TODO(pwestin): Re-factor the functions bellow into a class with static 56 // TODO(pwestin): Re-factor the functions bellow into a class with static
55 // methods. 57 // methods.
56 58
57 // January 1970, in NTP seconds. 59 // January 1970, in NTP seconds.
58 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on 60 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * 125 int64 ntp_time_us = static_cast<int64>(ntp_seconds) *
124 base::Time::kMicrosecondsPerSecond + 126 base::Time::kMicrosecondsPerSecond +
125 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; 127 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit;
126 128
127 base::TimeDelta elapsed_since_unix_epoch = 129 base::TimeDelta elapsed_since_unix_epoch =
128 base::TimeDelta::FromMicroseconds(ntp_time_us - 130 base::TimeDelta::FromMicroseconds(ntp_time_us -
129 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); 131 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond));
130 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; 132 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch;
131 } 133 }
132 134
135 inline char ConvertFromBase16Char(char base_16) {
Alpha Left Google 2013/11/07 01:10:11 Don't do this. You should assume the key and IV ar
pwestin 2013/11/07 17:16:04 Moved to test app. I did find the base 64 but not
136 DCHECK((base_16 >= '0' && base_16 <= '9') ||
137 (base_16 >= 'a' && base_16 <= 'f') ||
138 (base_16 >= 'A' && base_16 <= 'F'));
139
140 if (base_16 >= '0' && base_16 <= '9') {
141 return base_16 - '0';
142 }
143 if (base_16 >= 'a' && base_16 <= 'f') {
144 return base_16 - 'a' + 10;
145 }
146 return base_16 - 'A' + 10;
147 }
148
149 inline std::string ConvertFromBase16String(std::string base_16) {
150 std::string compressed;
151 DCHECK(base_16.size() % 2 == 0) << "Must be a multiple of 2";
152 compressed.reserve(base_16.size() / 2);
153
154 for (std::string::iterator it = base_16.begin(); it != base_16.end(); ++it) {
155 char first_part = ConvertFromBase16Char(*it++);
156 char second_part = ConvertFromBase16Char(*it);
157 compressed.push_back((first_part << 4) + second_part);
158 }
159 return compressed;
160 }
161
162 inline std::string GetAesNounce(uint32 frame_id, const std::string& iv_mask) {
163 std::string aes_ivec(kAesBlockSize, 0);
164
165 aes_ivec[11] = frame_id & 0xff;
166 aes_ivec[10] = (frame_id >> 8) & 0xff;
167 aes_ivec[9] = (frame_id >> 16) & 0xff;
168 aes_ivec[8] = (frame_id >> 24) & 0xff;
169
170 for (size_t i = 0; i < kAesBlockSize; ++i) {
171 aes_ivec[i] ^= iv_mask[i];
172 }
173 return aes_ivec;
174 }
175
133 } // namespace cast 176 } // namespace cast
134 } // namespace media 177 } // namespace media
135 178
136 #endif // MEDIA_CAST_CAST_DEFINES_H_ 179 #endif // MEDIA_CAST_CAST_DEFINES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698