diff --git a/CMakeLists.txt b/CMakeLists.txt index 93a36e5..aecaa41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,9 @@ set (AUTHOR "Romain Coltel") find_program (GIT_EXE NAMES git PATHS /usr/bin /usr/local/bin) +include(CTest) +enable_testing() + if(GIT_EXE) execute_process ( COMMAND ${GIT_EXE} rev-parse --abbrev-ref HEAD @@ -47,7 +50,9 @@ set (VERSION_RELEASE 3) set (VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}") add_subdirectory (${PROJECT_SOURCE_DIR}/src) - +if(BUILD_TESTING) + add_subdirectory (${PROJECT_SOURCE_DIR}/test) +endif() configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" diff --git a/README.md b/README.md index b306883..524c924 100644 --- a/README.md +++ b/README.md @@ -100,3 +100,20 @@ instance, if you want to compile dislocker-fuse only, you'd simply run: $ cmake . $ make dislocker-fuse ``` + +## Crypto Backends + +One can also change the cryptographic libraries used by using the CMake option "CRYPTO_BACKEND". +The current options are "mbedtls" the default, and "openssl". You MUST specify those strings exactly. +For example, to enable the openssl cryptographic backend, do this in your `cmake` command: +```bash +cmake -DCRYPTO_BACKEND=openssl +``` + +## Testing + +You can enable (the default behavior) or disable testing using the CMake option "BUILD_TESTING". +For example, to disable testing add `-DBUILD_TESTING=OFF` to your `cmake` command like so: +```bash +cmake -DBUILD_TESTING=OFF +``` \ No newline at end of file diff --git a/include/dislocker/accesses/stretch_key.h b/include/dislocker/accesses/stretch_key.h index 1a1820d..906dbe6 100644 --- a/include/dislocker/accesses/stretch_key.h +++ b/include/dislocker/accesses/stretch_key.h @@ -26,7 +26,7 @@ #include "dislocker/common.h" -#include "dislocker/ssl_bindings.h" +#include "ssl_bindings.h" diff --git a/include/dislocker/encryption/aes-xts.h b/include/dislocker/encryption/aes-xts.h index 060fd88..bfcfa0e 100644 --- a/include/dislocker/encryption/aes-xts.h +++ b/include/dislocker/encryption/aes-xts.h @@ -23,7 +23,7 @@ #ifndef DIS_AES_XTS_H #define DIS_AES_XTS_H -#include "dislocker/ssl_bindings.h" +#include "ssl_bindings.h" /* diff --git a/include/dislocker/encryption/encommon.priv.h b/include/dislocker/encryption/encommon.priv.h index 35eb8d1..aee01e7 100644 --- a/include/dislocker/encryption/encommon.priv.h +++ b/include/dislocker/encryption/encommon.priv.h @@ -26,7 +26,7 @@ #include "dislocker/encryption/encommon.h" -#include "dislocker/ssl_bindings.h" +#include "ssl_bindings.h" diff --git a/include/dislocker/ssl_bindings.h b/include/dislocker/encryption/mbedtls/ssl_bindings.h similarity index 83% rename from include/dislocker/ssl_bindings.h rename to include/dislocker/encryption/mbedtls/ssl_bindings.h index 0f17146..f27a958 100644 --- a/include/dislocker/ssl_bindings.h +++ b/include/dislocker/encryption/mbedtls/ssl_bindings.h @@ -32,7 +32,6 @@ #define SHA256(input, len, output) mbedtls_sha256(input, len, output, 0) /* Here stand the bindings for AES functions and contexts */ -#if defined(MBEDTLS_AES_H) # define AES_CONTEXT mbedtls_aes_context # define AES_SETENC_KEY(ctx, key, size) mbedtls_aes_setkey_enc(ctx, key, size) # define AES_SETDEC_KEY(ctx, key, size) mbedtls_aes_setkey_dec(ctx, key, size) @@ -41,15 +40,6 @@ mbedtls_aes_crypt_cbc(ctx, mode, size, iv, in, out); # define AES_ENCRYPT MBEDTLS_AES_ENCRYPT # define AES_DECRYPT MBEDTLS_AES_DECRYPT -#else -# define AES_CONTEXT aes_context -# define AES_SETENC_KEY(ctx, key, size) aes_setkey_enc(ctx, key, size) -# define AES_SETDEC_KEY(ctx, key, size) aes_setkey_dec(ctx, key, size) -# define AES_ECB_ENC(ctx, mode, in, out) aes_crypt_ecb(ctx, mode, in, out) -# define AES_CBC(ctx, mode, size, iv, in, out) \ - aes_crypt_cbc(ctx, mode, size, iv, in, out); -#endif /* defined(MBEDTLS_AES_H) */ - #include "dislocker/encryption/aes-xts.h" #if defined(MBEDTLS_CIPHER_MODE_XEX) diff --git a/include/dislocker/encryption/openssl/ssl_bindings.h b/include/dislocker/encryption/openssl/ssl_bindings.h new file mode 100644 index 0000000..eddcc27 --- /dev/null +++ b/include/dislocker/encryption/openssl/ssl_bindings.h @@ -0,0 +1,139 @@ +/* -*- coding: utf-8 -*- */ +/* -*- mode: c -*- */ +/* + * Dislocker -- enables to read/write on BitLocker encrypted partitions under + * Linux + * Copyright (C) 2026 Arm Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#ifndef SSL_BINDINGS_H +#define SSL_BINDINGS_H + +#include +#include +#include + +#define DIS_OSSL_MAX_AES_KEY_BYTES 512/8 + +typedef struct dis_ossl_aes_ctx dis_ossl_aes_ctx; +struct dis_ossl_aes_ctx { + unsigned char key[DIS_OSSL_MAX_AES_KEY_BYTES]; + size_t len; + int enc_dec; +}; + +#define AES_CONTEXT dis_ossl_aes_ctx + +#define DIS_OSSL_CIPHER_ECB 0 +#define DIS_OSSL_CIPHER_CBC 1 + +static inline const EVP_CIPHER *dis_ossle_get_cipher(size_t key_len, int ossl_mode) +{ + if (ossl_mode == DIS_OSSL_CIPHER_ECB) + { + switch (key_len) + { + case 16: return EVP_aes_128_ecb(); + case 24: return EVP_aes_192_ecb(); + case 32: return EVP_aes_256_ecb(); + default: return NULL; + } + } + else if (ossl_mode == DIS_OSSL_CIPHER_CBC) + { + switch (key_len) + { + case 16: return EVP_aes_128_cbc(); + case 24: return EVP_aes_192_cbc(); + case 32: return EVP_aes_256_cbc(); + default: return NULL; + } + } + return NULL; +} + +static inline int dis_ossl_set_key(AES_CONTEXT *ctx, const unsigned char *key, size_t key_bits, int enc_dec) +{ + size_t key_len = key_bits / 8; + if (key_len > sizeof(ctx->key)) + return 1; + + memcpy(ctx->key, key, key_len); + ctx->len = key_bits / 8; + ctx->enc_dec = enc_dec; + + return 0; +} + +static inline int dis_ossl_aes_crypt( + AES_CONTEXT *ctx, + int mode, + int size, + const unsigned char *iv, + const unsigned char *input, + unsigned char *output, + int cipher) +{ + int rc = 1; /* fail unless otherwise changed */ + int out_len = 0; + + const EVP_CIPHER *ossl_cipher = dis_ossle_get_cipher(ctx->len, cipher); + if (!ossl_cipher) + return rc; + + EVP_CIPHER_CTX *ossl_ctx = EVP_CIPHER_CTX_new(); + if (!ossl_ctx) + return rc; + + if (mode == AES_ENCRYPT) + { + if (!EVP_EncryptInit(ossl_ctx, ossl_cipher, ctx->key, iv)) goto error; + if (!EVP_CIPHER_CTX_set_padding(ossl_ctx, 0)) goto error; + if (!EVP_EncryptUpdate(ossl_ctx, output, &out_len, input, size)) goto error; + if (!EVP_EncryptFinal(ossl_ctx, &output[out_len], &out_len)) goto error; + } else { + if (!EVP_DecryptInit(ossl_ctx, ossl_cipher, ctx->key, iv)) goto error; + if (!EVP_CIPHER_CTX_set_padding(ossl_ctx, 0)) goto error; + if (!EVP_DecryptUpdate(ossl_ctx, output, &out_len, input, size)) goto error; + if (!EVP_DecryptFinal(ossl_ctx, &output[out_len], &out_len)) goto error; + } + + /* success */ + rc = 0; + +error: + EVP_CIPHER_CTX_free(ossl_ctx); + return rc; +} + +#define AES_SETENC_KEY(ctx, key, size) dis_ossl_set_key(ctx, key, size, AES_ENCRYPT) +#define AES_SETDEC_KEY(ctx, key, size) dis_ossl_set_key(ctx, key, size, AES_DECRYPT) +#define AES_ECB_ENC(ctx, mode, in, out) dis_ossl_aes_crypt(ctx, mode, 16, NULL, in, out, DIS_OSSL_CIPHER_ECB) +#define AES_CBC(ctx, mode, size, iv, in, out) dis_ossl_aes_crypt(ctx, mode, size, iv, in, out, DIS_OSSL_CIPHER_CBC) + +/* + * OpenSSL doesn't provide XEX nor XTS, so just use the dislocker implementations. Note that + * the dislocker implementations use the OpenSSL primitives already defined, these are optional + */ +#include "dislocker/encryption/aes-xts.h" +#define AES_XEX(ctx1, ctx2, mode, size, iv, in, out) \ + dis_aes_crypt_xex(ctx1, ctx2, mode, size, iv, in, out) + +#define AES_XTS(ctx1, ctx2, mode, size, iv, in, out) \ + dis_aes_crypt_xts(ctx1, ctx2, mode, size, iv, in, out) + +#endif /* SSL_BINDINGS_H */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d0a8ab4..9e46937 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,7 +47,6 @@ endif() if( NOT CMAKE_CROSSCOMPILING ) include_directories (SYSTEM /usr/local/include) endif() -include_directories (${PROJECT_SOURCE_DIR}/include) set (LIB pthread) set (SOURCES @@ -118,9 +117,6 @@ endif() # Libraries set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -find_package (MbedTLS 3 REQUIRED) -set (LIB ${LIB} MbedTLS::mbedcrypto) - # Ruby bindings set(WITH_RUBY "AUTO" CACHE STRING "Enable Ruby bindings. Valid values are ON, OFF, or AUTO") if (NOT "${WITH_RUBY}" STREQUAL "OFF") @@ -201,7 +197,8 @@ endif() # Targets add_library (${PROJECT_NAME} SHARED ${SOURCES}) -target_link_libraries (${PROJECT_NAME} ${LIB}) +target_include_directories (${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_link_libraries (${PROJECT_NAME} PRIVATE ${LIB}) set_target_properties (${PROJECT_NAME} PROPERTIES VERSION "${VERSION}" SOVERSION "${VERSION_MAJOR}.${VERSION_MINOR}") install (TARGETS ${PROJECT_NAME} LIBRARY DESTINATION "${libdir}") @@ -213,12 +210,45 @@ if (${APPLE}) install (TARGETS ${BUNDLE_NAME} DESTINATION "${libdir}") endif() +set(CRYPTO_BACKEND "mbedtls" CACHE STRING "Crypto library backend") +set_property(CACHE CRYPTO_BACKEND PROPERTY STRINGS "mbedtls" "openssl") + +add_library(dislocker_crypto_backend INTERFACE) + +message(STATUS "Crypto backend: ${CRYPTO_BACKEND}") +if(CRYPTO_BACKEND STREQUAL "mbedtls") + find_package (MbedTLS 3 REQUIRED) + target_link_libraries(${PROJECT_NAME} + PRIVATE + MbedTLS::mbedcrypto + ) + target_link_libraries(dislocker_crypto_backend INTERFACE MbedTLS::mbedcrypto) + target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME}/encryption/mbedtls + ) +elseif(CRYPTO_BACKEND STREQUAL "openssl") + find_package(OpenSSL REQUIRED) + target_link_libraries(${PROJECT_NAME} + PRIVATE + OpenSSL::Crypto + ) + target_link_libraries(dislocker_crypto_backend INTERFACE OpenSSL::Crypto) + target_include_directories(${PROJECT_NAME} + PUBLIC + ${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME}/encryption/openssl + ) +else() + message(FATAL_ERROR "Unknown CRYPTO_BACKEND='${CRYPTO_BACKEND}'.") +endif() + + set (CLEAN_FILES "") if(FUSE_FOUND) set (BIN_FUSE ${PROJECT_NAME}-fuse) add_executable (${BIN_FUSE} ${BIN_FUSE}.c) - target_link_libraries (${BIN_FUSE} ${FUSE_LIBBRARIES} ${PROJECT_NAME}) + target_link_libraries (${BIN_FUSE} PRIVATE ${FUSE_LIBBRARIES} ${LIB} ${PROJECT_NAME}) set_target_properties (${BIN_FUSE} PROPERTIES COMPILE_DEFINITIONS FUSE_USE_VERSION=314) set_target_properties (${BIN_FUSE} PROPERTIES LINK_FLAGS "-pie -fPIE") add_custom_command (TARGET ${BIN_FUSE} POST_BUILD diff --git a/src/encryption/aes-xts.c b/src/encryption/aes-xts.c index be09c46..bb80120 100644 --- a/src/encryption/aes-xts.c +++ b/src/encryption/aes-xts.c @@ -24,7 +24,7 @@ #include #include -#include "dislocker/ssl_bindings.h" +#include "ssl_bindings.h" #ifndef GET_UINT64_LE #define GET_UINT64_LE(n,b,i) \ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..5dc2e1f --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,27 @@ +# Dislocker -- enables to read/write on BitLocker encrypted partitions under +# Linux +# Copyright (C) 2026 Arm Ltd +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. + +add_executable(crypto_tests + test-crypto.c +) + +target_link_libraries(crypto_tests PRIVATE ${PROJECT_NAME} dislocker_crypto_backend) + +add_test(NAME cyrpto_tests COMMAND crypto_tests) + diff --git a/test/test-crypto.c b/test/test-crypto.c new file mode 100644 index 0000000..f61ae6c --- /dev/null +++ b/test/test-crypto.c @@ -0,0 +1,147 @@ +/* -*- coding: utf-8 -*- */ +/* -*- mode: c -*- */ +/* + * Dislocker -- enables to read/write on BitLocker encrypted partitions under + * Linux + * Copyright (C) 2026 Arm Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#include +#include +#include + +#include "ssl_bindings.h" + +#include "test.h" +#include "test_vectors.h" + +static void test_ecb_encrypt_128(void) +{ + AES_CONTEXT ctx; + + NEW_ARRAY_FROM(char, buf, orig_16); + + /* Test AES ECB 128 Encryption */ + AES_SETENC_KEY(&ctx, key_aes_128, sizeof(key_aes_128) * 8); + + AES_ECB_ENC(&ctx, AES_ENCRYPT, buf, buf); + + CHECK_STATIC_BUFFERS(buf, aes_ecb_128_expected); + + /* Test AES ECB 128 Decryption */ + AES_SETDEC_KEY(&ctx, key_aes_128, sizeof(key_aes_128) * 8); + + AES_ECB_ENC(&ctx, AES_DECRYPT, buf, buf); + + CHECK_STATIC_BUFFERS(buf, orig_16); +} + +static void test_ecb_encrypt_256(void) { + AES_CONTEXT ctx; + + NEW_ARRAY_FROM(char, buf, orig_16); + + /* Test AES ECB 256 Encryption */ + AES_SETENC_KEY(&ctx, key_aes_256, sizeof(key_aes_256) * 8); + + AES_ECB_ENC(&ctx, AES_ENCRYPT, buf, buf); + + CHECK_STATIC_BUFFERS(buf, expected_aes_ecb_256); + + /* Test AES ECB 256 Decryption */ + AES_SETDEC_KEY(&ctx, key_aes_256, sizeof(key_aes_256) * 8); + + AES_ECB_ENC(&ctx, AES_DECRYPT, buf, buf); + + CHECK_STATIC_BUFFERS(buf, orig_16); +} + +static void test_cbc_encrypt_128(void) { + AES_CONTEXT ctx; + + NEW_ARRAY_FROM(char, buf, orig_512); + + /* mbedtls requires a mutable IV */ + NEW_ARRAY_FROM(char, iv, static_iv); + + /* Test AES CBC 128 Encryption + * + * In at least one test, modify the key to ensure the internal + * context buffer doesn't depend on the key pointer remaining + * constant. + */ + char mutable_key[sizeof(key_aes_128)]; + memcpy(mutable_key, key_aes_128, sizeof(mutable_key)); + AES_SETENC_KEY(&ctx, mutable_key, sizeof(key_aes_128) * 8); + memset(mutable_key, 0xFF, sizeof(mutable_key)); + + AES_CBC(&ctx, AES_ENCRYPT, sizeof(buf), iv, buf, buf); + + CHECK_STATIC_BUFFERS(buf, expected_cbc_128); + + /* Test AES CBC 128 Decryption */ + memcpy(iv, static_iv, sizeof(iv)); + + AES_SETDEC_KEY(&ctx, key_aes_128, sizeof(key_aes_128) * 8); + + AES_CBC(&ctx, AES_DECRYPT, sizeof(expected_cbc_128), iv, expected_cbc_128, buf); + + CHECK_STATIC_BUFFERS(buf, orig_512); +} + +static void test_cbc_encrypt_256(void) { + AES_CONTEXT ctx; + + NEW_ARRAY_FROM(char, buf, orig_512); + + /* mbedtls requires a mutable IV */ + NEW_ARRAY_FROM(char, iv, static_iv); + + /* Test AES CBC 128 Encryption */ + AES_SETENC_KEY(&ctx, key_aes_256, sizeof(key_aes_256) * 8); + + AES_CBC(&ctx, AES_ENCRYPT, sizeof(buf), iv, buf, buf); + + CHECK_STATIC_BUFFERS(buf, expected_cbc_256); + + /* Test AES CBC 128 Decryption */ + memcpy(iv, static_iv, sizeof(iv)); + + AES_SETDEC_KEY(&ctx, key_aes_256, sizeof(key_aes_256) * 8); + + AES_CBC(&ctx, AES_DECRYPT, sizeof(expected_cbc_128), iv, expected_cbc_256, buf); + + CHECK_STATIC_BUFFERS(buf, orig_512); +} + + +int main(int argc, char *argv[]) +{ + ADD_TEST(test_ecb_encrypt_128); + ADD_TEST(test_ecb_encrypt_256); + + ADD_TEST(test_cbc_encrypt_128); + ADD_TEST(test_cbc_encrypt_256); + + printf("--- Statistics ---\n"); + printf("Total: %d\n", _tests); + printf("Pass: %d\n", _tests - _failures); + printf("Fail: %d\n", _failures); + printf("-------------------\n"); + + return _failures & 0xFF; +} diff --git a/test/test.h b/test/test.h new file mode 100644 index 0000000..311a8a9 --- /dev/null +++ b/test/test.h @@ -0,0 +1,68 @@ +/* -*- coding: utf-8 -*- */ +/* -*- mode: c -*- */ +/* + * Dislocker -- enables to read/write on BitLocker encrypted partitions under + * Linux + * Copyright (C) 2026 Arm Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#ifndef TEST_H_ +#define TEST_H_ + +static int _failures; +static int _tests; +static jmp_buf _jmp; + +#define ADD_TEST(name) \ + do { \ + _tests++; \ + int x = setjmp(_jmp); \ + if (!x) \ + name(); \ + } while(0) + + +static void _CHECK_BUFFERS(const void *a, const void *b, size_t size_a, size_t size_b, + const char *file_name, const char *func_name, int lineno) +{ + if(size_a != size_b) + { + fprintf(stderr, "%s:%s:%d: Buffer size mismatch: %zu != %zu\n", + file_name, func_name, lineno, size_a, size_b); + _failures++; + longjmp(_jmp, 1); + } + if (memcmp(a, b, size_a)) + { + fprintf(stderr, "%s:%s:%d: Buffers do not match\n", + file_name, func_name, lineno); + _failures++; + longjmp(_jmp, 1); + } +} + +#define CHECK_BUFFERS(a, b, a_size, b_size) \ + _CHECK_BUFFERS(a, b, a_size, b_size, __FILE__, __func__, __LINE__) + +#define CHECK_STATIC_BUFFERS(a, b) \ + CHECK_BUFFERS(a, b, sizeof(a), sizeof(b)) + +#define NEW_ARRAY_FROM(t, n, from) \ + t n[sizeof(from)]; \ + memcpy(n, from, sizeof(n)); + +#endif /* TEST_H_ */ diff --git a/test/test_vectors.h b/test/test_vectors.h new file mode 100644 index 0000000..fc30e7b --- /dev/null +++ b/test/test_vectors.h @@ -0,0 +1,233 @@ +/* -*- coding: utf-8 -*- */ +/* -*- mode: c -*- */ +/* + * Dislocker -- enables to read/write on BitLocker encrypted partitions under + * Linux + * Copyright (C) 2026 Arm Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + */ +#ifndef TEST_VECTORS_H_ +#define TEST_VECTORS_H_ + +static const char key_aes_128[] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '0', '1', '2', '3', '4', '5' +}; + +static const char key_aes_256[] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '0', '1', '2', '3', '4', '5', + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '0', '1', '2', '3', '4', '5' +}; + +const static char static_iv[] = { + 0x9F, 0x3C, 0xA7, 0xD2, + 0x48, 0x6B, 0x91, 0xEE, + 0x14, 0x5A, 0xC8, 0x70, + 0x2D, 0xF4, 0x89, 0xB6 +}; + +static const char orig_16[] = { + 'A','B','C','D','E','F','G','H', + 'I','J','K','L','M','N','O','P' +}; + +static const char aes_ecb_128_expected[] = { + 0x4F, 0x57, 0xA4, 0x78, + 0x47, 0x19, 0x5F, 0x80, + 0xE5, 0x09, 0x45, 0x72, + 0x6F, 0xA7, 0xF8, 0x92 +}; + +static const char expected_aes_ecb_256[] = { + 0xB5, 0x73, 0x10, 0xBB, + 0x6B, 0xC2, 0xFE, 0x09, + 0xA6, 0x13, 0xC6, 0x2A, + 0x0F, 0xA4, 0x09, 0xFD +}; + +static const char orig_512[] = { + 0x3A, 0x7F, 0x12, 0xC4, 0x9B, 0xE1, 0x55, 0x8D, + 0x6A, 0xF0, 0x24, 0xB7, 0x91, 0x0E, 0xDC, 0x48, + 0xAF, 0x62, 0x19, 0xE8, 0x73, 0x04, 0x9D, 0xC1, + 0x56, 0xB2, 0xF9, 0x0A, 0x8C, 0x47, 0xDE, 0x31, + 0x6E, 0x95, 0xCB, 0x18, 0xF4, 0x02, 0x7A, 0xAD, + 0x40,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 0xAF, 0x62, 0x19, 0xE8, 0x73, 0x04, 0x9D, 0xC1, + 0x56, 0xB2, 0xF9, 0x0A, 0x8C, 0x47, 0xDE, 0x31, + 0x6E, 0x95, 0xCB, 0x18, 0xF4, 0x02, 0x7A, 0xAD, + 0x40, 0xE7, 0x29, 0x93, 0xBD, 0x54, 0x08, 0xF1, + 0xCA, 0x6C, 0x9E, 0x13, 0x85, 0xDF, 0x22, 0xB8, + 0x4D, 0xF6, 0x01, 0x97, 0xAC, 0x38, 0xE2, 0x59, + 0x71, 0x0F, 0xC9, 0xB4, 0x2A, 0x8E, 0xD3, 0x64, + 0xF8, 0x15, 0x9A, 0x43, 0xED, 0x70, 0x06, 0xBC, + 0x52, 0x91, 0xAF, 0x28, 0xE4, 0x0B, 0x7D, 0xC6, + 0x39, 0xF2, 0x84, 0x1E, 0xD8, 0x6B, 0x95, 0x40, + 0xAE, 0x57, 0x03, 0xF7, 0x9C, 0x21, 0xC0, 0x68, + 0x14, 0xDB, 0x85, 0x3E, 0xFA, 0x92, 0x07, 0x4C, + 0xB1, 0xE9, 0x26, 0x7C, 0xD5, 0x90, 0x58, 0x0D, + 0xC7, 0xA3, 0xF5, 0x1B, 0x6F, 0x84, 0x2E, 0x99 +}; + +static const char expected_cbc_128[] = { + 0xAE, 0xA3, 0x5C, 0x8A, 0x86, 0xB7, 0x4A, 0xA4, + 0x51, 0x24, 0xC9, 0x55, 0x3C, 0x1F, 0xEA, 0x9B, + 0xAF, 0x5D, 0xD3, 0xDF, 0x01, 0x31, 0x15, 0x93, + 0xA2, 0x14, 0xEE, 0xBA, 0xA5, 0x37, 0xCE, 0x77, + 0x6A, 0xB3, 0x5C, 0x0D, 0x20, 0xBA, 0x08, 0xC4, + 0x65, 0x41, 0x43, 0xF9, 0x0B, 0x79, 0x85, 0x37, + 0xDA, 0xDA, 0xF8, 0xE4, 0x06, 0xE8, 0xDD, 0xB0, + 0x1C, 0x43, 0xA8, 0x10, 0xB1, 0x57, 0x58, 0xA7,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A, 0x73, 0x85, + 0x77, 0xB3, 0x80, 0x42, 0x51, 0xC8, 0x4B, 0x5B, + 0xB9, 0xC3, 0xC5, 0xC9, 0x44, 0x2C, 0xAB, 0xD2, + 0x4B, 0xA6, 0x5C, 0x5E, 0x53, 0x23, 0x8C, 0x1F, + 0x4D, 0xEF, 0xB9, 0xBE, 0x5A, 0x30, 0xA7, 0xB4, + 0x2F, 0x32, 0x61, 0x6B, 0x5A, 0xA5, 0x64, 0xA8, + 0xFA, 0xFE, 0x87, 0x6F, 0xB4, 0x15, 0x68, 0x20, + 0x72, 0xDE, 0x76, 0x5B, 0x5C, 0xA0, 0x02, 0x92, + 0x92, 0x95, 0x67, 0x1A, 0xA5, 0xB6, 0xA8, 0xE0, + 0x91, 0x26, 0xDC, 0xD3, 0xD7, 0xB3, 0xEE, 0xEE, + 0x0E, 0x27, 0xA3, 0x13, 0x34, 0x00, 0x32, 0x01, + 0x7B, 0xDA, 0x80, 0x52, 0xD9, 0x4D, 0xF5, 0xD1 +}; + +static const char expected_cbc_256[] = { + 0xD0, 0x6B, 0x93, 0x3B, 0x8F, 0xE0, 0x67, 0x2E, 0x8F, 0xE2, 0x75, 0xDD, 0x90, 0x1D, 0xFE, 0xD9, + 0xA0, 0x67, 0xDB, 0x2F, 0xE9, 0x99, 0xEF, 0x9D, 0xD0, 0x25, 0x9F, 0x87, 0xFD, 0xE7, 0x53, 0xFA, + 0xD0, 0x61, 0x29, 0x9E, 0xA3, 0x26, 0xDD, 0xB1, 0x91, 0x18, 0x38, 0xD2, 0xED, 0xBC, 0x28, 0x7D, + 0xA5, 0x53, 0xEE, 0xC1, 0x88, 0xEC, 0xDB, 0x7E, 0x60, 0xD5, 0x48, 0x76, 0x58, 0xC1, 0x6C, 0x8D, + 0x4B, 0x7F, 0xC6, 0x1C, 0x4F, 0x13, 0x40, 0x3C, 0x1F, 0x63, 0x46, 0x28, 0xD8, 0x3C, 0x30, 0x4D, + 0x3A, 0x8F, 0xA0, 0xE2, 0x0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