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

Unified Diff: media/cast/transport/cast_transport_defines.h

Issue 138843011: Cast: Adding helper crypto classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: media/cast/transport/cast_transport_defines.h
diff --git a/media/cast/transport/cast_transport_defines.h b/media/cast/transport/cast_transport_defines.h
index c096d6f77ce4c9ef1ec5193ec590cb1016175f6b..bcc42b62de4d39ac0f6cf82b12631ae729aee2cf 100644
--- a/media/cast/transport/cast_transport_defines.h
+++ b/media/cast/transport/cast_transport_defines.h
@@ -8,6 +8,7 @@
#include <list>
#include <map>
#include <set>
+#include <string>
#include "base/basictypes.h"
#include "base/time/time.h"
@@ -30,6 +31,26 @@ typedef std::set<uint16> PacketIdSet;
// Each uint8 represents one cast frame.
typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
+// Crypto.
+const size_t kAesBlockSize = 16;
+const size_t kAesKeySize = 16;
+
+inline std::string GetAesNonce(uint32 frame_id, const std::string& iv_mask) {
+ std::string aes_nonce(kAesBlockSize, 0);
+
+ // Serializing frame_id in big-endian order (aes_nonce[8] is the most
+ // significant byte of frame_id).
+ aes_nonce[11] = frame_id & 0xff;
+ aes_nonce[10] = (frame_id >> 8) & 0xff;
+ aes_nonce[9] = (frame_id >> 16) & 0xff;
+ aes_nonce[8] = (frame_id >> 24) & 0xff;
+
+ for (size_t i = 0; i < kAesBlockSize; ++i) {
+ aes_nonce[i] ^= iv_mask[i];
+ }
+ return aes_nonce;
+}
+
// Rtcp defines.
enum RtcpPacketTypes {

Powered by Google App Engine
This is Rietveld 408576698