OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebM 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 |
11 #include <cstdio> | 11 #include <cstdio> |
12 #include <cstdlib> | 12 #include <cstdlib> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 #include "third_party/googletest/src/include/gtest/gtest.h" | 15 #include "third_party/googletest/src/include/gtest/gtest.h" |
16 #include "test/codec_factory.h" | 16 #include "test/codec_factory.h" |
17 #include "test/ivf_video_source.h" | 17 #include "test/ivf_video_source.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 // In a real use the 'decrypt_state' parameter will be a pointer to a struct | 20 // In a real use the 'decrypt_state' parameter will be a pointer to a struct |
21 // with whatever internal state the decryptor uses. For testing we'll just | 21 // with whatever internal state the decryptor uses. For testing we'll just |
22 // xor with a constant key, and decrypt_state will point to the start of | 22 // xor with a constant key, and decrypt_state will point to the start of |
23 // the original buffer. | 23 // the original buffer. |
24 const uint8_t test_key[16] = { | 24 const uint8_t test_key[16] = { |
25 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, | 25 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, |
26 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0 | 26 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0 |
27 }; | 27 }; |
28 | 28 |
29 void encrypt_buffer(const uint8_t *src, uint8_t *dst, | 29 void encrypt_buffer(const uint8_t *src, uint8_t *dst, size_t size, |
30 int size, int offset = 0) { | 30 ptrdiff_t offset) { |
31 for (int i = 0; i < size; ++i) { | 31 for (size_t i = 0; i < size; ++i) { |
32 dst[i] = src[i] ^ test_key[(offset + i) & 15]; | 32 dst[i] = src[i] ^ test_key[(offset + i) & 15]; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 void test_decrypt_cb(void *decrypt_state, const uint8_t *input, | 36 void test_decrypt_cb(void *decrypt_state, const uint8_t *input, |
37 uint8_t *output, int count) { | 37 uint8_t *output, int count) { |
38 encrypt_buffer(input, output, count, | 38 encrypt_buffer(input, output, count, |
39 input - reinterpret_cast<uint8_t *>(decrypt_state)); | 39 input - reinterpret_cast<uint8_t *>(decrypt_state)); |
40 } | 40 } |
41 | 41 |
(...skipping 12 matching lines...) Expand all Loading... |
54 | 54 |
55 // no decryption | 55 // no decryption |
56 vpx_codec_err_t res = decoder.DecodeFrame(video.cxdata(), video.frame_size()); | 56 vpx_codec_err_t res = decoder.DecodeFrame(video.cxdata(), video.frame_size()); |
57 ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError(); | 57 ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError(); |
58 | 58 |
59 // decrypt frame | 59 // decrypt frame |
60 video.Next(); | 60 video.Next(); |
61 | 61 |
62 #if CONFIG_DECRYPT | 62 #if CONFIG_DECRYPT |
63 std::vector<uint8_t> encrypted(video.frame_size()); | 63 std::vector<uint8_t> encrypted(video.frame_size()); |
64 encrypt_buffer(video.cxdata(), &encrypted[0], video.frame_size()); | 64 encrypt_buffer(video.cxdata(), &encrypted[0], video.frame_size(), 0); |
65 vp8_decrypt_init di = { test_decrypt_cb, &encrypted[0] }; | 65 vp8_decrypt_init di = { test_decrypt_cb, &encrypted[0] }; |
66 decoder.Control(VP8D_SET_DECRYPTOR, &di); | 66 decoder.Control(VP8D_SET_DECRYPTOR, &di); |
67 #endif // CONFIG_DECRYPT | 67 #endif // CONFIG_DECRYPT |
68 | 68 |
69 res = decoder.DecodeFrame(video.cxdata(), video.frame_size()); | 69 res = decoder.DecodeFrame(video.cxdata(), video.frame_size()); |
70 ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError(); | 70 ASSERT_EQ(VPX_CODEC_OK, res) << decoder.DecodeError(); |
71 } | 71 } |
72 | 72 |
73 } // namespace libvpx_test | 73 } // namespace libvpx_test |
OLD | NEW |