1 /* GStreamer
2 *
3 * Copyright (C) 2021 Aaron Boxer <aaron.boxer@collabora.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 #include <gst/gst.h>
25 #include <gst/check/gstcheck.h>
26 #include <gst/check/gstharness.h>
27
28 unsigned char plain16[] = {
29 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
30 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
31 };
32
33 unsigned char enc16[] = {
34 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
35 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
36 0x40, 0xee, 0xfd, 0xcb, 0x3b, 0xbe, 0xf3, 0x0b,
37 0xa7, 0xaf, 0x5e, 0x20, 0x87, 0x78, 0x8a, 0x45
38 };
39
40 unsigned char enc16_serialize[] = {
41 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
42 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
43 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
44 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
45 0x40, 0xee, 0xfd, 0xcb, 0x3b, 0xbe, 0xf3, 0x0b,
46 0xa7, 0xaf, 0x5e, 0x20, 0x87, 0x78, 0x8a, 0x45
47 };
48
49 unsigned char plain17[] = {
50 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
51 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
52 0x10
53 };
54
55 unsigned char enc17[] = {
56 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
57 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
58 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
59 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
60 };
61
62 unsigned char enc17_serialize[] = {
63 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
64 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
65 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
66 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
67 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
68 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
69 };
70
71 static void
run(gboolean per_buffer_padding,gboolean serialize_iv,guchar * in_ref,gsize in_ref_len,guchar * out_ref,gsize out_ref_len)72 run (gboolean per_buffer_padding,
73 gboolean serialize_iv,
74 guchar * in_ref, gsize in_ref_len, guchar * out_ref, gsize out_ref_len)
75 {
76
77 GstHarness *h;
78 GstBuffer *buf, *outbuf;
79 gint out_ref_len_truncated = out_ref_len & ~0xF;
80
81 h = gst_harness_new ("aesdec");
82 gst_harness_set_src_caps_str (h, "video/x-raw");
83
84 g_object_set (h->element,
85 "key", "1f9423681beb9a79215820f6bda73d0f",
86 "iv", "e9aa8e834d8d70b7e0d254ff670dd718",
87 "per-buffer-padding", per_buffer_padding,
88 "serialize-iv", serialize_iv, NULL);
89
90 buf = gst_buffer_new_and_alloc (in_ref_len);
91 gst_buffer_fill (buf, 0, in_ref, in_ref_len);
92 outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
93
94 fail_unless (gst_buffer_memcmp (outbuf, 0, out_ref,
95 out_ref_len_truncated) == 0);
96
97 gst_buffer_unref (outbuf);
98 gst_buffer_unref (buf);
99
100 if (!per_buffer_padding) {
101 gint final_bytes = out_ref_len & 0xF;
102
103 if (final_bytes != 0) {
104 gst_harness_push_event (h, gst_event_new_eos ());
105 outbuf = gst_harness_try_pull (h);
106 fail_unless (outbuf);
107 fail_unless (gst_buffer_get_size (outbuf) == final_bytes);
108 fail_unless (gst_buffer_memcmp (outbuf, 0,
109 out_ref + out_ref_len_truncated, final_bytes) == 0);
110 gst_buffer_unref (outbuf);
111 }
112 }
113
114 gst_harness_teardown (h);
115 }
116
GST_START_TEST(text16)117 GST_START_TEST (text16)
118 {
119 run (TRUE, FALSE, enc16, sizeof (enc16), plain16, sizeof (plain16));
120 }
121
122 GST_END_TEST;
123
GST_START_TEST(text16_serialize)124 GST_START_TEST (text16_serialize)
125 {
126 run (TRUE, TRUE, enc16_serialize, sizeof (enc16_serialize), plain16,
127 sizeof (plain16));
128 }
129
130 GST_END_TEST;
131
GST_START_TEST(text16_serialize_no_per_buffer_padding)132 GST_START_TEST (text16_serialize_no_per_buffer_padding)
133 {
134 run (FALSE, TRUE, enc16_serialize, sizeof (enc16_serialize), plain16,
135 sizeof (plain16));
136 }
137
138 GST_END_TEST;
139
140
GST_START_TEST(text17)141 GST_START_TEST (text17)
142 {
143 run (TRUE, FALSE, enc17, sizeof (enc17), plain17, sizeof (plain17));
144 }
145
146 GST_END_TEST;
147
GST_START_TEST(text17_serialize)148 GST_START_TEST (text17_serialize)
149 {
150 run (TRUE, TRUE, enc17_serialize, sizeof (enc17_serialize), plain17,
151 sizeof (plain17));
152 }
153
154 GST_END_TEST;
155
156
GST_START_TEST(text17_serialize_no_per_buffer_padding)157 GST_START_TEST (text17_serialize_no_per_buffer_padding)
158 {
159 run (FALSE, TRUE, enc17_serialize, sizeof (enc17_serialize), plain17,
160 sizeof (plain17));
161 }
162
163 GST_END_TEST;
164
165 static Suite *
aesdec_suite(void)166 aesdec_suite (void)
167 {
168 Suite *s = suite_create ("aesdec");
169 TCase *tc = tcase_create ("general");
170
171 suite_add_tcase (s, tc);
172 tcase_add_test (tc, text16);
173 tcase_add_test (tc, text16_serialize);
174 tcase_add_test (tc, text16_serialize_no_per_buffer_padding);
175 tcase_add_test (tc, text17);
176 tcase_add_test (tc, text17_serialize);
177 tcase_add_test (tc, text17_serialize_no_per_buffer_padding);
178 return s;
179 }
180
181 GST_CHECK_MAIN (aesdec);
182