1 /* 2 * Encryption functions 3 * 4 * Copyright (C) 2013-2020, Joachim Metz <joachim.metz@gmail.com> 5 * 6 * Refer to AUTHORS for acknowledgements. 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #if !defined( _LIBLUKSDE_ENCRYPTION_H ) 23 #define _LIBLUKSDE_ENCRYPTION_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #include "libluksde_libcaes.h" 29 #include "libluksde_libcerror.h" 30 #include "libluksde_libfcrypto.h" 31 32 #if defined( __cplusplus ) 33 extern "C" { 34 #endif 35 36 enum LIBLUKSDE_ENCRYPTION_CRYPT_MODES 37 { 38 LIBLUKSDE_ENCRYPTION_CRYPT_MODE_DECRYPT = 0, 39 LIBLUKSDE_ENCRYPTION_CRYPT_MODE_ENCRYPT = 1 40 }; 41 42 typedef struct libluksde_encryption_context libluksde_encryption_context_t; 43 44 struct libluksde_encryption_context 45 { 46 /* The encryption mode, which is a combination of method and chaining mode 47 */ 48 int encryption_mode; 49 50 /* The initialization vector mode 51 */ 52 int initialization_vector_mode; 53 54 /* The ESSIV hashing method 55 */ 56 int essiv_hashing_method; 57 58 /* The AES decryption context 59 */ 60 libcaes_context_t *aes_decryption_context; 61 62 /* The AES encryption context 63 */ 64 libcaes_context_t *aes_encryption_context; 65 66 /* The AES-XTS decryption context 67 */ 68 libcaes_tweaked_context_t *aes_xts_decryption_context; 69 70 /* The AES-XTS encryption context 71 */ 72 libcaes_tweaked_context_t *aes_xts_encryption_context; 73 74 /* The RC4 decryption context 75 */ 76 libfcrypto_rc4_context_t *rc4_decryption_context; 77 78 /* The RC4 encryption context 79 */ 80 libfcrypto_rc4_context_t *rc4_encryption_context; 81 82 /* The Serpent decryption context 83 */ 84 libfcrypto_serpent_context_t *serpent_decryption_context; 85 86 /* The Serpent encryption context 87 */ 88 libfcrypto_serpent_context_t *serpent_encryption_context; 89 90 /* The ESSIV encryption context 91 */ 92 libcaes_context_t *essiv_encryption_context; 93 }; 94 95 int libluksde_encryption_initialize( 96 libluksde_encryption_context_t **context, 97 int method, 98 int chaining_mode, 99 int initialization_vector_mode, 100 int essiv_hashing_method, 101 libcerror_error_t **error ); 102 103 int libluksde_encryption_free( 104 libluksde_encryption_context_t **context, 105 libcerror_error_t **error ); 106 107 int libluksde_encryption_set_key( 108 libluksde_encryption_context_t *context, 109 const uint8_t *key, 110 size_t key_size, 111 libcerror_error_t **error ); 112 113 int libluksde_encryption_crypt( 114 libluksde_encryption_context_t *context, 115 int mode, 116 const uint8_t *input_data, 117 size_t input_data_size, 118 uint8_t *output_data, 119 size_t output_data_size, 120 uint64_t sector_number, 121 libcerror_error_t **error ); 122 123 #if defined( __cplusplus ) 124 } 125 #endif 126 127 #endif /* !defined( _LIBLUKSDE_ENCRYPTION_H ) */ 128 129