Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
Add CTR encryption to webm_crypt.
Browse files Browse the repository at this point in the history
- Add support for CTR encryption based on WebM encryption RFC v0.3.
- Add version information.
- Add support to encrypt audio and video stream with independent settings.
- Add EncryptModule and DecryptModule classes.
- Added shared/webm_endian files.
- Added support for creating the HMAC data.
- Added support for checking the integrity of the data during decryption.
- Added support to not perform encrypt or decrypt for testing.
- Removed asserts.
- Added comments to classes and functions.
- Added ContentEncodings output to webm_info.
- Added IV output to webm_info.
- Fixed audio or video only encryption.
- Prepend a signal byte to all frames to signify if the frame data
  is compressed or not.
- Add a command line parameter to not encrypt frames on a stream
  from [0, <value>) milliseconds.
- Update webm_info to output encrypted info.
- Added "Release DLL" and "Debug DLL" configurations to Windows solution.
- PS15 Addressed comments.
- PS16 Addressed comments. Created swap64_check_little_endian to handle
  swapping bytes.
- PS17 Addressed comments. Fix copy/paste bug in swap64_check_little_endian.
- PS18 Addressed comments.
- PS20 Changed errors to log to stderr. Addressing comments.

Change-Id: I10a94c372cda9722900de9a09a5bd1b198e70e94
  • Loading branch information
Frank Galligan committed Aug 1, 2012
1 parent e679d38 commit e89e55f
Show file tree
Hide file tree
Showing 14 changed files with 1,455 additions and 467 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.sln -crlf
*.vcproj -crlf
*.vcxproj -crlf
*.vsprops -crlf
54 changes: 54 additions & 0 deletions shared/webm_endian.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.

#include "webm_endian.h"

namespace {

// Swaps unsigned 64 bit values to big endian if needed. Returns |value|
// unmodified if architecture is big endian. Returns swapped bytes of |value|
// if architecture is little endian. Returns 0 otherwise.
webm_tools::uint64 swap64_check_little_endian(webm_tools::uint64 value) {
// Check endianness.
union {
webm_tools::uint64 val64;
webm_tools::uint8 c[8];
} check;
check.val64 = 0x0123456789ABCDEFULL;

// Check for big endian.
if (check.c[7] == 0xEF)
return value;

// Check for not little endian.
if (check.c[0] != 0xEF)
return 0;

return value << 56 |
((value << 40) & 0x00FF000000000000ULL) |
((value << 24) & 0x0000FF0000000000ULL) |
((value << 8) & 0x000000FF00000000ULL) |
((value >> 8) & 0x00000000FF000000ULL) |
((value >> 24) & 0x0000000000FF0000ULL) |
((value >> 40) & 0x000000000000FF00ULL) |
value >> 56;
}

} // namespace

namespace webm_tools {

uint64 host_to_bigendian(uint64 value) {
return swap64_check_little_endian(value);
}

uint64 bigendian_to_host(uint64 value) {
return swap64_check_little_endian(value);
}

} // namespace webm_tools
28 changes: 28 additions & 0 deletions shared/webm_endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.

#ifndef SHARED_WEBM_ENDIAN_H_
#define SHARED_WEBM_ENDIAN_H_

#include "webm_tools_types.h"

namespace webm_tools {

// Swaps unsigned 64 bit values to big endian if needed. Returns |value| if
// architecture is big endian. Returns little endian value if architecture is
// little endian. Returns 0 otherwise.
uint64 host_to_bigendian(uint64 value);

// Swaps unsigned 64 bit values to little endian if needed. Returns |value| if
// architecture is big endian. Returns little endian value if architecture is
// little endian. Returns 0 otherwise.
uint64 bigendian_to_host(uint64 value);

} // namespace webm_tools

#endif // SHARED_WEBM_ENDIAN_H_
4 changes: 3 additions & 1 deletion shared/webm_tools_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#if defined(_MSC_VER)
#define snprintf sprintf_s
#define strtoull _strtoui64
#endif

namespace webm_tools {
Expand All @@ -28,7 +29,8 @@ typedef unsigned int uint32;
typedef long long int64; // NOLINT
typedef unsigned long long uint64; // NOLINT

static const double kNanosecondsPerSecond = 1000000000.0;
const double kNanosecondsPerSecond = 1000000000.0;
const int kNanosecondsPerMillisecond = 1000000;

} // namespace webm_tools

Expand Down
16 changes: 7 additions & 9 deletions webm_crypt/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
LIBWEBM = ../../libwebm
CHROMIUMINC = /usr/local/google/Chromium/src
CHROMIUMOBJ = $(CHROMIUMINC)/out/Debug/obj.target
BASEDIR = $(CHROMIUMOBJ)/base
DYNANNDIR = $(BASEDIR)/third_party/dynamic_annotations
CRYPTODIR = $(CHROMIUMOBJ)/crypto
OBJECTS = webm_crypt.o
CHROMIUMOBJ = $(CHROMIUMINC)/out/Debug/lib
OBJECTS = ../shared/webm_endian.o webm_crypt.o
EXE = webm_crypt
INCLUDES = -I$(LIBWEBM) -I$(CHROMIUMINC) -I/usr/include/nss -I/usr/include/nspr
INCLUDES = -I$(LIBWEBM) -I../shared -I$(CHROMIUMINC) -I/usr/include/nss \
-I/usr/include/nspr
CXXFLAGS = -W -Wall -g -DUSE_NSS

$(EXE): $(OBJECTS)
$(CXX) $(OBJECTS) -L$(LIBWEBM) -L$(BASEDIR) -L$(DYNANNDIR) -L$(CRYPTODIR) \
-lwebm -lcrcrypto -ldynamic_annotations -lbase -lsymbolize \
-ldl -lrt -lglib-2.0 -lnss3 -lnssutil3 -lnspr4 -lpthread -o $@
$(CXX) $(OBJECTS) -L$(LIBWEBM) -L$(CHROMIUMOBJ) -Wl,-rpath \
$(CHROMIUMOBJ) -lwebm -lcrcrypto -lbase -ldl -lrt -lglib-2.0 -lnss3 \
-lnssutil3 -lnspr4 -lpthread -o $@

%.o: %.cc
$(CXX) -c $(CXXFLAGS) $(INCLUDES) $< -o $@
Expand Down
19 changes: 7 additions & 12 deletions webm_crypt/Readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The WebM project authors. All Rights Reserved.
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
Expand All @@ -15,21 +15,16 @@
chromium/src/base/third_party/dynamic_annotations.sln solutions.
3. Get the libwebm source code.
git clone http://git.chromium.org/webm/libwebm.git
4. Pull the encryption patch.
git fetch http://gerrit.chromium.org/gerrit/p/webm/libwebm refs/changes/03/9803/4 && git checkout FETCH_HEAD
4. Choose the configuration that matches the chromium libs. i.e. "Debug DLL",
"Debug", "Release", or "Release DLL"
5. Build libwebm.
6. Change the webm_crypt solution to point to your libs and build.
6. Open environment.props file and change CHROMIUM_INC's value to your
Chromium src directory.

// Build instructions for Linux:
1. Follow http://code.google.com/p/chromium/wiki/LinuxBuildInstructions to
build chrome application.
2. Get the libwebm source code.
git clone http://git.chromium.org/webm/libwebm.git
3. Pull the encryption patch.
git fetch http://gerrit.chromium.org/gerrit/p/webm/libwebm refs/changes/03/9803/4 && git checkout FETCH_HEAD
4. Build libwebm.
5. Change Makefile to point to your libs and build.

Known Issues:

Currently crashes on Linux.
3. Build libwebm.
4. Change Makefile to point to your libs and build.
15 changes: 15 additions & 0 deletions webm_crypt/environment.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<CHROMIUM_INC>D:\src\Chromium\Src</CHROMIUM_INC>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup />
<ItemGroup>
<BuildMacro Include="CHROMIUM_INC">
<Value>$(CHROMIUM_INC)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
</ItemGroup>
</Project>
Loading

0 comments on commit e89e55f

Please sign in to comment.