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 enc16_serialize_no_per_buffer_padding[] = {
50 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
51 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
52 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
53 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27
54 };
55
56
57 unsigned char plain17[] = {
58 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
59 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
60 0x10
61 };
62
63 unsigned char enc17[] = {
64 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
65 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
66 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
67 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
68 };
69
70 unsigned char enc17_serialize[] = {
71 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
72 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
73 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
74 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
75 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
76 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
77 };
78
79 unsigned char enc17_serialize_no_per_buffer_padding[] = {
80 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
81 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
82 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
83 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
84 };
85
86 static void
run(gboolean per_buffer_padding,gboolean serialize_iv,guchar * in_ref,gsize in_ref_len,guchar * out_ref,gsize out_ref_len)87 run (gboolean per_buffer_padding,
88 gboolean serialize_iv,
89 guchar * in_ref, gsize in_ref_len, guchar * out_ref, gsize out_ref_len)
90 {
91 GstHarness *h;
92 GstBuffer *buf, *outbuf;
93
94 h = gst_harness_new ("aesenc");
95 gst_harness_set_src_caps_str (h, "video/x-raw");
96
97 g_object_set (h->element,
98 "key", "1f9423681beb9a79215820f6bda73d0f",
99 "iv", "e9aa8e834d8d70b7e0d254ff670dd718",
100 "per-buffer-padding", per_buffer_padding,
101 "serialize-iv", serialize_iv, NULL);
102
103 buf = gst_buffer_new_and_alloc (in_ref_len);
104 gst_buffer_fill (buf, 0, in_ref, in_ref_len);
105 outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
106
107 fail_unless (gst_buffer_memcmp (outbuf, 0, out_ref, out_ref_len) == 0);
108
109 gst_buffer_unref (outbuf);
110 gst_buffer_unref (buf);
111
112 gst_harness_teardown (h);
113 }
114
GST_START_TEST(text16)115 GST_START_TEST (text16)
116 {
117 run (TRUE, FALSE, plain16, sizeof (plain16), enc16, sizeof (enc16));
118 }
119
120 GST_END_TEST;
121
GST_START_TEST(text16_serialize)122 GST_START_TEST (text16_serialize)
123 {
124 run (TRUE, TRUE, plain16, sizeof (plain16), enc16_serialize,
125 sizeof (enc16_serialize));
126 }
127
128 GST_END_TEST;
129
GST_START_TEST(text16_serialize_no_per_buffer_padding)130 GST_START_TEST (text16_serialize_no_per_buffer_padding)
131 {
132 run (FALSE, TRUE, plain16, sizeof (plain16),
133 enc16_serialize_no_per_buffer_padding,
134 sizeof (enc16_serialize_no_per_buffer_padding));
135 }
136
137 GST_END_TEST;
138
GST_START_TEST(text17)139 GST_START_TEST (text17)
140 {
141 run (TRUE, FALSE, plain17, sizeof (plain17), enc17, sizeof (enc17));
142 }
143
144 GST_END_TEST;
145
GST_START_TEST(text17_serialize)146 GST_START_TEST (text17_serialize)
147 {
148 run (TRUE, TRUE, plain17, sizeof (plain17), enc17_serialize,
149 sizeof (enc17_serialize));
150 }
151
152 GST_END_TEST;
153
GST_START_TEST(text17_serialize_no_per_buffer_padding)154 GST_START_TEST (text17_serialize_no_per_buffer_padding)
155 {
156 run (FALSE, TRUE, plain17, sizeof (plain17),
157 enc17_serialize_no_per_buffer_padding,
158 sizeof (enc17_serialize_no_per_buffer_padding));
159 }
160
161 GST_END_TEST;
162
163 static Suite *
aesenc_suite(void)164 aesenc_suite (void)
165 {
166 Suite *s = suite_create ("aesenc");
167 TCase *tc = tcase_create ("general");
168
169 suite_add_tcase (s, tc);
170 tcase_add_test (tc, text16);
171 tcase_add_test (tc, text16_serialize);
172 tcase_add_test (tc, text16_serialize_no_per_buffer_padding);
173 tcase_add_test (tc, text17);
174 tcase_add_test (tc, text17_serialize);
175 tcase_add_test (tc, text17_serialize_no_per_buffer_padding);
176 return s;
177 }
178
179 GST_CHECK_MAIN (aesenc);
180