2 * Copyright 2016-2017 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>
14 #include <openssl/engine.h>
15 #include <openssl/evp.h>
16 #include <openssl/rand.h>
19 /* Use a buffer size which is not aligned to block size */
20 #define BUFFER_SIZE (8 * 1024) - 13
22 #ifndef OPENSSL_NO_ENGINE
27 #ifndef OPENSSL_NO_AFALGENG
28 # include <linux/version.h>
32 # if LINUX_VERSION_CODE < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2)
34 * If we get here then it looks like there is a mismatch between the linux
35 * headers and the actual kernel version, so we have tried to compile with
36 * afalg support, but then skipped it in e_afalg.c. As far as this test is
37 * concerned we behave as if we had been configured without support
39 # define OPENSSL_NO_AFALGENG
43 #ifndef OPENSSL_NO_AFALGENG
44 static int test_afalg_aes_128_cbc(void)
47 const EVP_CIPHER
*cipher
= EVP_aes_128_cbc();
48 unsigned char key
[] = "\x5F\x4D\xCC\x3B\x5A\xA7\x65\xD6\
49 \x1D\x83\x27\xDE\xB8\x82\xCF\x99";
50 unsigned char iv
[] = "\x2B\x95\x99\x0A\x91\x51\x37\x4A\
51 \xBD\x8F\xF8\xC5\xA7\xA0\xFE\x08";
53 unsigned char in
[BUFFER_SIZE
];
54 unsigned char ebuf
[BUFFER_SIZE
+ 32];
55 unsigned char dbuf
[BUFFER_SIZE
+ 32];
56 int encl
, encf
, decl
, decf
;
59 if (!TEST_ptr(ctx
= EVP_CIPHER_CTX_new()))
61 RAND_bytes(in
, BUFFER_SIZE
);
63 if (!TEST_true(EVP_CipherInit_ex(ctx
, cipher
, e
, key
, iv
, 1))
64 || !TEST_true(EVP_CipherUpdate(ctx
, ebuf
, &encl
, in
, BUFFER_SIZE
))
65 || !TEST_true(EVP_CipherFinal_ex(ctx
, ebuf
+encl
, &encf
)))
69 if (!TEST_true(EVP_CIPHER_CTX_reset(ctx
))
70 || !TEST_true(EVP_CipherInit_ex(ctx
, cipher
, e
, key
, iv
, 0))
71 || !TEST_true(EVP_CipherUpdate(ctx
, dbuf
, &decl
, ebuf
, encl
))
72 || !TEST_true(EVP_CipherFinal_ex(ctx
, dbuf
+decl
, &decf
)))
76 if (!TEST_int_eq(decl
, BUFFER_SIZE
)
77 || !TEST_mem_eq(dbuf
, BUFFER_SIZE
, in
, BUFFER_SIZE
))
83 EVP_CIPHER_CTX_free(ctx
);
88 #ifndef OPENSSL_NO_ENGINE
91 ENGINE_load_builtin_engines();
92 # ifndef OPENSSL_NO_STATIC_ENGINE
93 OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG
, NULL
);
101 #ifndef OPENSSL_NO_ENGINE
102 if ((e
= ENGINE_by_id("afalg")) == NULL
) {
103 /* Probably a platform env issue, not a test failure. */
104 TEST_info("Can't load AFALG engine");
106 # ifndef OPENSSL_NO_AFALGENG
107 ADD_TEST(test_afalg_aes_128_cbc
);
115 #ifndef OPENSSL_NO_ENGINE
116 void cleanup_tests(void)