2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/opensslconf.h>
13 #ifndef OPENSSL_NO_AFALGENG
14 # include <linux/version.h>
18 # if LINUX_VERSION_CODE <= KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2)
20 * If we get here then it looks like there is a mismatch between the linux
21 * headers and the actual kernel version, so we have tried to compile with
22 * afalg support, but then skipped it in e_afalg.c. As far as this test is
23 * concerned we behave as if we had been configured without support
25 # define OPENSSL_NO_AFALGENG
29 #ifndef OPENSSL_NO_AFALGENG
32 #include <openssl/engine.h>
33 #include <openssl/evp.h>
34 #include <openssl/rand.h>
37 /* Use a buffer size which is not aligned to block size */
38 #define BUFFER_SIZE (8 * 1024) - 13
42 static int test_afalg_aes_128_cbc(void)
45 const EVP_CIPHER *cipher = EVP_aes_128_cbc();
46 unsigned char key[] = "\x5F\x4D\xCC\x3B\x5A\xA7\x65\xD6\
47 \x1D\x83\x27\xDE\xB8\x82\xCF\x99";
48 unsigned char iv[] = "\x2B\x95\x99\x0A\x91\x51\x37\x4A\
49 \xBD\x8F\xF8\xC5\xA7\xA0\xFE\x08";
51 unsigned char in[BUFFER_SIZE];
52 unsigned char ebuf[BUFFER_SIZE + 32];
53 unsigned char dbuf[BUFFER_SIZE + 32];
54 int encl, encf, decl, decf;
57 if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()))
59 RAND_bytes(in, BUFFER_SIZE);
61 if (!TEST_true(EVP_CipherInit_ex(ctx, cipher, e, key, iv, 1))
62 || !TEST_true(EVP_CipherUpdate(ctx, ebuf, &encl, in, BUFFER_SIZE))
63 || !TEST_true(EVP_CipherFinal_ex(ctx, ebuf+encl, &encf)))
67 if (!TEST_true(EVP_CIPHER_CTX_reset(ctx))
68 || !TEST_true(EVP_CipherInit_ex(ctx, cipher, e, key, iv, 0))
69 || !TEST_true(EVP_CipherUpdate(ctx, dbuf, &decl, ebuf, encl))
70 || !TEST_true(EVP_CipherFinal_ex(ctx, dbuf+decl, &decf)))
74 if (!TEST_int_eq(decl, BUFFER_SIZE)
75 || !TEST_mem_eq(dbuf, BUFFER_SIZE, in, BUFFER_SIZE))
81 EVP_CIPHER_CTX_free(ctx);
85 int main(int argc, char **argv)
89 ENGINE_load_builtin_engines();
90 # ifndef OPENSSL_NO_STATIC_ENGINE
91 OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL);
96 if ((e = ENGINE_by_id("afalg")) == NULL) {
97 /* Probably a platform env issue, not a test failure. */
98 TEST_info("Can't load AFALG engine");
100 ADD_TEST(test_afalg_aes_128_cbc);
102 ret = run_tests(argv[0]);
105 return finish_test(ret);
108 #else /* OPENSSL_NO_AFALGENG */
110 int main(int argc, char **argv)
112 fprintf(stderr, "AFALG not supported - skipping AFALG tests\n");