summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAaron Boxer <aaron.boxer@collabora.com>2021-07-06 12:31:42 -0400
committerOlivier CrĂȘte <olivier.crete@collabora.com>2021-08-25 21:16:09 -0400
commit5cf4dc2b82f10cbe2dc603fd49ab080ff8d32e56 (patch)
tree88ee9c2833d850ce9aab59ee6928d1e88fc98d01 /tests
parent1a919a1e413a87a01077b4c6823223c0f264e88d (diff)
downloadgstreamer-plugins-bad-5cf4dc2b82f10cbe2dc603fd49ab080ff8d32e56.tar.gz
aes: add aes encryption and decryption elements
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1505>
Diffstat (limited to 'tests')
-rw-r--r--tests/check/elements/aesdec.c181
-rw-r--r--tests/check/elements/aesenc.c179
-rw-r--r--tests/check/meson.build3
3 files changed, 363 insertions, 0 deletions
diff --git a/tests/check/elements/aesdec.c b/tests/check/elements/aesdec.c
new file mode 100644
index 000000000..6ffbc4b2b
--- /dev/null
+++ b/tests/check/elements/aesdec.c
@@ -0,0 +1,181 @@
+/* GStreamer
+ *
+ * Copyright (C) 2021 Aaron Boxer <aaron.boxer@collabora.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <gst/gst.h>
+#include <gst/check/gstcheck.h>
+#include <gst/check/gstharness.h>
+
+unsigned char plain16[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+};
+
+unsigned char enc16[] = {
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0x40, 0xee, 0xfd, 0xcb, 0x3b, 0xbe, 0xf3, 0x0b,
+ 0xa7, 0xaf, 0x5e, 0x20, 0x87, 0x78, 0x8a, 0x45
+};
+
+unsigned char enc16_serialize[] = {
+ 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
+ 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0x40, 0xee, 0xfd, 0xcb, 0x3b, 0xbe, 0xf3, 0x0b,
+ 0xa7, 0xaf, 0x5e, 0x20, 0x87, 0x78, 0x8a, 0x45
+};
+
+unsigned char plain17[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10
+};
+
+unsigned char enc17[] = {
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
+ 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
+};
+
+unsigned char enc17_serialize[] = {
+ 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
+ 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
+ 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
+};
+
+static void
+run (gboolean per_buffer_padding,
+ gboolean serialize_iv,
+ guchar * in_ref, gsize in_ref_len, guchar * out_ref, gsize out_ref_len)
+{
+
+ GstHarness *h;
+ GstBuffer *buf, *outbuf;
+ gint out_ref_len_truncated = out_ref_len & ~0xF;
+
+ h = gst_harness_new ("aesdec");
+ gst_harness_set_src_caps_str (h, "video/x-raw");
+
+ g_object_set (h->element,
+ "key", "1f9423681beb9a79215820f6bda73d0f",
+ "iv", "e9aa8e834d8d70b7e0d254ff670dd718",
+ "per-buffer-padding", per_buffer_padding,
+ "serialize-iv", serialize_iv, NULL);
+
+ buf = gst_buffer_new_and_alloc (in_ref_len);
+ gst_buffer_fill (buf, 0, in_ref, in_ref_len);
+ outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
+
+ fail_unless (gst_buffer_memcmp (outbuf, 0, out_ref,
+ out_ref_len_truncated) == 0);
+
+ gst_buffer_unref (outbuf);
+ gst_buffer_unref (buf);
+
+ if (!per_buffer_padding) {
+ gint final_bytes = out_ref_len & 0xF;
+
+ if (final_bytes != 0) {
+ gst_harness_push_event (h, gst_event_new_eos ());
+ outbuf = gst_harness_try_pull (h);
+ fail_unless (outbuf);
+ fail_unless (gst_buffer_get_size (outbuf) == final_bytes);
+ fail_unless (gst_buffer_memcmp (outbuf, 0,
+ out_ref + out_ref_len_truncated, final_bytes) == 0);
+ gst_buffer_unref (outbuf);
+ }
+ }
+
+ gst_harness_teardown (h);
+}
+
+GST_START_TEST (text16)
+{
+ run (TRUE, FALSE, enc16, sizeof (enc16), plain16, sizeof (plain16));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text16_serialize)
+{
+ run (TRUE, TRUE, enc16_serialize, sizeof (enc16_serialize), plain16,
+ sizeof (plain16));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text16_serialize_no_per_buffer_padding)
+{
+ run (FALSE, TRUE, enc16_serialize, sizeof (enc16_serialize), plain16,
+ sizeof (plain16));
+}
+
+GST_END_TEST;
+
+
+GST_START_TEST (text17)
+{
+ run (TRUE, FALSE, enc17, sizeof (enc17), plain17, sizeof (plain17));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text17_serialize)
+{
+ run (TRUE, TRUE, enc17_serialize, sizeof (enc17_serialize), plain17,
+ sizeof (plain17));
+}
+
+GST_END_TEST;
+
+
+GST_START_TEST (text17_serialize_no_per_buffer_padding)
+{
+ run (FALSE, TRUE, enc17_serialize, sizeof (enc17_serialize), plain17,
+ sizeof (plain17));
+}
+
+GST_END_TEST;
+
+static Suite *
+aesdec_suite (void)
+{
+ Suite *s = suite_create ("aesdec");
+ TCase *tc = tcase_create ("general");
+
+ suite_add_tcase (s, tc);
+ tcase_add_test (tc, text16);
+ tcase_add_test (tc, text16_serialize);
+ tcase_add_test (tc, text16_serialize_no_per_buffer_padding);
+ tcase_add_test (tc, text17);
+ tcase_add_test (tc, text17_serialize);
+ tcase_add_test (tc, text17_serialize_no_per_buffer_padding);
+ return s;
+}
+
+GST_CHECK_MAIN (aesdec);
diff --git a/tests/check/elements/aesenc.c b/tests/check/elements/aesenc.c
new file mode 100644
index 000000000..5662e678e
--- /dev/null
+++ b/tests/check/elements/aesenc.c
@@ -0,0 +1,179 @@
+/* GStreamer
+ *
+ * Copyright (C) 2021 Aaron Boxer <aaron.boxer@collabora.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <gst/gst.h>
+#include <gst/check/gstcheck.h>
+#include <gst/check/gstharness.h>
+
+unsigned char plain16[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
+};
+
+unsigned char enc16[] = {
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0x40, 0xee, 0xfd, 0xcb, 0x3b, 0xbe, 0xf3, 0x0b,
+ 0xa7, 0xaf, 0x5e, 0x20, 0x87, 0x78, 0x8a, 0x45
+};
+
+unsigned char enc16_serialize[] = {
+ 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
+ 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0x40, 0xee, 0xfd, 0xcb, 0x3b, 0xbe, 0xf3, 0x0b,
+ 0xa7, 0xaf, 0x5e, 0x20, 0x87, 0x78, 0x8a, 0x45
+};
+
+unsigned char enc16_serialize_no_per_buffer_padding[] = {
+ 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
+ 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27
+};
+
+
+unsigned char plain17[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10
+};
+
+unsigned char enc17[] = {
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
+ 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
+};
+
+unsigned char enc17_serialize[] = {
+ 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
+ 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+ 0xe1, 0xe0, 0xaa, 0xf4, 0xe8, 0x29, 0x7c, 0x9f,
+ 0xc4, 0xe3, 0x11, 0x4a, 0x97, 0x58, 0x9c, 0xa5
+};
+
+unsigned char enc17_serialize_no_per_buffer_padding[] = {
+ 0xe9, 0xaa, 0x8e, 0x83, 0x4d, 0x8d, 0x70, 0xb7,
+ 0xe0, 0xd2, 0x54, 0xff, 0x67, 0x0d, 0xd7, 0x18,
+ 0xfc, 0x49, 0x14, 0xc6, 0xee, 0x06, 0xe1, 0xb1,
+ 0xc7, 0xa2, 0x3a, 0x05, 0x13, 0x15, 0x29, 0x27,
+};
+
+static void
+run (gboolean per_buffer_padding,
+ gboolean serialize_iv,
+ guchar * in_ref, gsize in_ref_len, guchar * out_ref, gsize out_ref_len)
+{
+ GstHarness *h;
+ GstBuffer *buf, *outbuf;
+
+ h = gst_harness_new ("aesenc");
+ gst_harness_set_src_caps_str (h, "video/x-raw");
+
+ g_object_set (h->element,
+ "key", "1f9423681beb9a79215820f6bda73d0f",
+ "iv", "e9aa8e834d8d70b7e0d254ff670dd718",
+ "per-buffer-padding", per_buffer_padding,
+ "serialize-iv", serialize_iv, NULL);
+
+ buf = gst_buffer_new_and_alloc (in_ref_len);
+ gst_buffer_fill (buf, 0, in_ref, in_ref_len);
+ outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
+
+ fail_unless (gst_buffer_memcmp (outbuf, 0, out_ref, out_ref_len) == 0);
+
+ gst_buffer_unref (outbuf);
+ gst_buffer_unref (buf);
+
+ gst_harness_teardown (h);
+}
+
+GST_START_TEST (text16)
+{
+ run (TRUE, FALSE, plain16, sizeof (plain16), enc16, sizeof (enc16));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text16_serialize)
+{
+ run (TRUE, TRUE, plain16, sizeof (plain16), enc16_serialize,
+ sizeof (enc16_serialize));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text16_serialize_no_per_buffer_padding)
+{
+ run (FALSE, TRUE, plain16, sizeof (plain16),
+ enc16_serialize_no_per_buffer_padding,
+ sizeof (enc16_serialize_no_per_buffer_padding));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text17)
+{
+ run (TRUE, FALSE, plain17, sizeof (plain17), enc17, sizeof (enc17));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text17_serialize)
+{
+ run (TRUE, TRUE, plain17, sizeof (plain17), enc17_serialize,
+ sizeof (enc17_serialize));
+}
+
+GST_END_TEST;
+
+GST_START_TEST (text17_serialize_no_per_buffer_padding)
+{
+ run (FALSE, TRUE, plain17, sizeof (plain17),
+ enc17_serialize_no_per_buffer_padding,
+ sizeof (enc17_serialize_no_per_buffer_padding));
+}
+
+GST_END_TEST;
+
+static Suite *
+aesenc_suite (void)
+{
+ Suite *s = suite_create ("aesenc");
+ TCase *tc = tcase_create ("general");
+
+ suite_add_tcase (s, tc);
+ tcase_add_test (tc, text16);
+ tcase_add_test (tc, text16_serialize);
+ tcase_add_test (tc, text16_serialize_no_per_buffer_padding);
+ tcase_add_test (tc, text17);
+ tcase_add_test (tc, text17_serialize);
+ tcase_add_test (tc, text17_serialize_no_per_buffer_padding);
+ return s;
+}
+
+GST_CHECK_MAIN (aesenc);
diff --git a/tests/check/meson.build b/tests/check/meson.build
index b4055a931..713b99933 100644
--- a/tests/check/meson.build
+++ b/tests/check/meson.build
@@ -18,9 +18,12 @@ nalutils_dep = gstcodecparsers_dep.partial_dependency (compile_args: true, inclu
enable_gst_play_tests = get_option('gst_play_tests')
libsoup_dep = dependency('libsoup-2.4', version : '>=2.48', required : enable_gst_play_tests,
fallback : ['libsoup', 'libsoup_dep'])
+aes_dep = dependency('openssl', required : false)
# name, condition when to skip the test and extra dependencies
base_tests = [
+ [['elements/aesenc.c'], false, [aes_dep]],
+ [['elements/aesdec.c'], false, [aes_dep]],
[['elements/aiffparse.c']],
[['elements/asfmux.c']],
[['elements/autoconvert.c']],