2013-03-16 02:21:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 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 <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
2013-06-13 21:16:58 +02:00
|
|
|
#include <vector>
|
2013-03-16 02:21:55 +01:00
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
2013-06-13 21:16:58 +02:00
|
|
|
#include "test/codec_factory.h"
|
2013-03-16 02:21:55 +01:00
|
|
|
#include "test/ivf_video_source.h"
|
|
|
|
|
|
|
|
namespace {
|
2013-06-13 21:16:58 +02:00
|
|
|
// In a real use the 'decrypt_state' parameter will be a pointer to a struct
|
|
|
|
// with whatever internal state the decryptor uses. For testing we'll just
|
|
|
|
// xor with a constant key, and decrypt_state will point to the start of
|
|
|
|
// the original buffer.
|
|
|
|
const uint8_t test_key[16] = {
|
|
|
|
0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
|
|
|
|
0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0
|
2013-03-16 02:21:55 +01:00
|
|
|
};
|
|
|
|
|
2013-09-05 17:45:56 +02:00
|
|
|
void encrypt_buffer(const uint8_t *src, uint8_t *dst,
|
|
|
|
int size, int offset = 0) {
|
2013-06-13 21:16:58 +02:00
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
dst[i] = src[i] ^ test_key[(offset + i) & 15];
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 02:21:55 +01:00
|
|
|
|
2013-06-13 21:16:58 +02:00
|
|
|
void test_decrypt_cb(void *decrypt_state, const uint8_t *input,
|
|
|
|
uint8_t *output, int count) {
|
2013-09-05 17:45:56 +02:00
|
|
|
encrypt_buffer(input, output, count,
|
|
|
|
input - reinterpret_cast<uint8_t *>(decrypt_state));
|
2013-06-13 21:16:58 +02:00
|
|
|
}
|
2013-03-16 02:21:55 +01:00
|
|
|
|
2013-09-05 17:45:56 +02:00
|
|
|
} // namespace
|
2013-03-16 02:21:55 +01:00
|
|
|
|
2013-06-13 21:16:58 +02:00
|
|
|
namespace libvpx_test {
|
2013-03-16 02:21:55 +01:00
|
|
|
|
|
|
|
TEST(TestDecrypt, DecryptWorks) {
|
|
|
|
libvpx_test::IVFVideoSource video("vp80-00-comprehensive-001.ivf");
|
|
|
|
video.Init();
|
|
|
|
|
|
|
|
vpx_codec_dec_cfg_t dec_cfg = {0};
|
2013-06-13 21:16:58 +02:00
|
|
|
VP8Decoder decoder(dec_cfg, 0);
|
2013-03-16 02:21:55 +01:00
|
|
|
|
|
|
|
video.Begin();
|
2013-06-13 21:16:58 +02:00
|
|
|
|
|
|
|
// no decryption
|
2013-03-16 02:21:55 +01:00
|
|
|
vpx_codec_err_t res = decoder.DecodeFrame(video.cxdata(), video.frame_size());
|
|
|
|
ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
|
|
|
|
|
2013-06-13 21:16:58 +02:00
|
|
|
// decrypt frame
|
2013-03-16 02:21:55 +01:00
|
|
|
video.Next();
|
2013-06-13 21:16:58 +02:00
|
|
|
|
|
|
|
#if CONFIG_DECRYPT
|
|
|
|
std::vector<uint8_t> encrypted(video.frame_size());
|
|
|
|
encrypt_buffer(video.cxdata(), &encrypted[0], video.frame_size());
|
|
|
|
vp8_decrypt_init di = { test_decrypt_cb, &encrypted[0] };
|
|
|
|
decoder.Control(VP8D_SET_DECRYPTOR, &di);
|
|
|
|
#endif // CONFIG_DECRYPT
|
|
|
|
|
2013-03-16 02:21:55 +01:00
|
|
|
res = decoder.DecodeFrame(video.cxdata(), video.frame_size());
|
2013-06-13 21:16:58 +02:00
|
|
|
ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError();
|
2013-03-16 02:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace libvpx_test
|