1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 22:58:30 +00:00

Merge pull request #3369 from ventaquil/code-cleanup-luks

LUKS code cleanup
This commit is contained in:
Jens Steube 2022-07-25 14:56:43 +02:00 committed by GitHub
commit d15793a8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 543 additions and 809 deletions

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_aes.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_serpent.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_twofish.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_aes.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_serpent.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_twofish.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_aes.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_serpent.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_twofish.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_aes.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_serpent.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -18,9 +18,9 @@
#include M2S(INCLUDE_PATH/inc_cipher_twofish.cl)
#endif
#define LUKS_STRIPES 4000
#define LUKS_CT_LEN 512
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_CT_LEN ( 512)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
typedef enum hc_luks_hash_type
{
@ -60,10 +60,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];

View File

@ -155,14 +155,14 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[128];
u32 af_buf[((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES) / 4];
u32 af_buf[HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES / 4];
u32 af_len;
} luks_t;
@ -187,9 +187,9 @@ void *module_benchmark_esalt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
{
luks_t *luks = (luks_t *) hcmalloc (sizeof (luks_t));
luks->key_size = HC_LUKS_KEY_SIZE_256;
luks->cipher_type = HC_LUKS_CIPHER_TYPE_AES;
luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN;
luks->key_size = HC_LUKS_KEY_SIZE_256;
luks->cipher_type = HC_LUKS_CIPHER_TYPE_AES;
luks->cipher_mode = HC_LUKS_CIPHER_MODE_XTS_PLAIN;
return luks;
}
@ -554,7 +554,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
if (rc_seek1 == -1)
{
hc_fclose (&fp);
hc_fclose (&fp);
return (PARSER_LUKS_FILE_SIZE);
}

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-1 + AES";
static const u64 KERN_TYPE = 14611;
static const u64 KERN_TYPE = 14611; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,31 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
typedef enum kern_type_luks
{
KERN_TYPE_LUKS_SHA1_AES = 14611,
KERN_TYPE_LUKS_SHA1_SERPENT = 14612,
KERN_TYPE_LUKS_SHA1_TWOFISH = 14613,
KERN_TYPE_LUKS_SHA256_AES = 14621,
KERN_TYPE_LUKS_SHA256_SERPENT = 14622,
KERN_TYPE_LUKS_SHA256_TWOFISH = 14623,
KERN_TYPE_LUKS_SHA512_AES = 14631,
KERN_TYPE_LUKS_SHA512_SERPENT = 14632,
KERN_TYPE_LUKS_SHA512_TWOFISH = 14633,
KERN_TYPE_LUKS_RIPEMD160_AES = 14641,
KERN_TYPE_LUKS_RIPEMD160_SERPENT = 14642,
KERN_TYPE_LUKS_RIPEMD160_TWOFISH = 14643,
KERN_TYPE_LUKS_WHIRLPOOL_AES = 14651,
KERN_TYPE_LUKS_WHIRLPOOL_SERPENT = 14652,
KERN_TYPE_LUKS_WHIRLPOOL_TWOFISH = 14653,
} kern_type_luks_t;
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -107,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -199,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -286,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -309,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -324,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -347,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -358,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -366,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-1 + Serpent";
static const u64 KERN_TYPE = 14612;
static const u64 KERN_TYPE = 14612; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-1 + Twofish";
static const u64 KERN_TYPE = 14613;
static const u64 KERN_TYPE = 14613; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-256 + AES";
static const u64 KERN_TYPE = 14621;
static const u64 KERN_TYPE = 14621; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-256 + Serpent";
static const u64 KERN_TYPE = 14622;
static const u64 KERN_TYPE = 14622; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-256 + Twofish";
static const u64 KERN_TYPE = 14623;
static const u64 KERN_TYPE = 14623; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-512 + AES";
static const u64 KERN_TYPE = 14631;
static const u64 KERN_TYPE = 14631; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-512 + Serpent";
static const u64 KERN_TYPE = 14632;
static const u64 KERN_TYPE = 14632; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 SHA-512 + Twofish";
static const u64 KERN_TYPE = 14633;
static const u64 KERN_TYPE = 14633; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 RIPEMD-160 + AES";
static const u64 KERN_TYPE = 14641;
static const u64 KERN_TYPE = 14641; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 RIPEMD-160 + Serpent";
static const u64 KERN_TYPE = 14642;
static const u64 KERN_TYPE = 14642; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -19,7 +19,7 @@ static const u32 DGST_POS3 = 3;
static const u32 DGST_SIZE = DGST_SIZE_4_16;
static const u32 HASH_CATEGORY = HASH_CATEGORY_FDE;
static const char *HASH_NAME = "LUKS v1 RIPEMD-160 + Twofish";
static const u64 KERN_TYPE = 14643;
static const u64 KERN_TYPE = 14643; // old kernel used here
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE
| OPTI_TYPE_SLOW_HASH_SIMD_LOOP;
static const u64 OPTS_TYPE = OPTS_TYPE_STOCK_MODULE
@ -43,11 +43,15 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig,
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
#define LUKS_STRIPES 4000
#define LUKS_SALT_LEN 32
#define LUKS_CT_LEN 512
#define LUKS_AF_MIN_LEN ((HC_LUKS_KEY_SIZE_128 / 8) * LUKS_STRIPES)
#define LUKS_AF_MAX_LEN ((HC_LUKS_KEY_SIZE_512 / 8) * LUKS_STRIPES)
#define LUKS_STRIPES ( 4000)
#define LUKS_SALT_LEN ( 32)
#define LUKS_SALT_HEX_LEN ( LUKS_SALT_LEN * 2)
#define LUKS_CT_LEN ( 512)
#define LUKS_CT_HEX_LEN ( LUKS_CT_LEN * 2)
#define LUKS_AF_MIN_LEN (HC_LUKS_KEY_SIZE_128 / 8 * LUKS_STRIPES)
#define LUKS_AF_MIN_HEX_LEN ( LUKS_AF_MIN_LEN * 2)
#define LUKS_AF_MAX_LEN (HC_LUKS_KEY_SIZE_512 / 8 * LUKS_STRIPES)
#define LUKS_AF_MAX_HEX_LEN ( LUKS_AF_MAX_LEN * 2)
typedef enum hc_luks_hash_type
{
@ -87,10 +91,10 @@ typedef enum hc_luks_cipher_mode
typedef struct luks
{
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
int hash_type; // hc_luks_hash_type_t
int key_size; // hc_luks_key_size_t
int cipher_type; // hc_luks_cipher_type_t
int cipher_mode; // hc_luks_cipher_mode_t
u32 ct_buf[LUKS_CT_LEN / 4];
@ -179,22 +183,22 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
token.sep[4] = '$';
token.len_min[4] = LUKS_SALT_LEN * 2;
token.len_max[4] = LUKS_SALT_LEN * 2;
token.len_min[4] = LUKS_SALT_HEX_LEN;
token.len_max[4] = LUKS_SALT_HEX_LEN;
token.attr[4] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// af
token.sep[5] = '$';
token.len_min[5] = LUKS_AF_MIN_LEN * 2;
token.len_max[5] = LUKS_AF_MAX_LEN * 2;
token.len_min[5] = LUKS_AF_MIN_HEX_LEN;
token.len_max[5] = LUKS_AF_MAX_HEX_LEN;
token.attr[5] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
// ct
token.sep[6] = '$';
token.len_min[6] = LUKS_CT_LEN * 2;
token.len_max[6] = LUKS_CT_LEN * 2;
token.len_min[6] = LUKS_CT_HEX_LEN;
token.len_max[6] = LUKS_CT_HEX_LEN;
token.attr[6] = TOKEN_ATTR_VERIFY_LENGTH
| TOKEN_ATTR_VERIFY_HEX;
@ -266,12 +270,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *salt_pos = token.buf[4];
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
salt->salt_buf[i] = hex_to_u32 (salt_pos + j);
}
salt->salt_len = LUKS_SALT_LEN;
salt->salt_len = hex_decode (salt_pos, LUKS_SALT_HEX_LEN, (u8 *) salt->salt_buf);
// iter
@ -289,12 +288,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *af_pos = token.buf[5];
for (u32 i = 0, j = 0; i < af_len / 4; i += 1, j += 8)
{
luks->af_buf[i] = hex_to_u32 (af_pos + j);
}
luks->af_len = af_len;
luks->af_len = hex_decode (af_pos, token.len[5], (u8 *) luks->af_buf);
// ct
@ -304,10 +298,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
const u8 *ct_pos = token.buf[6];
for (u32 i = 0, j = 0; i < ct_len / 4; i += 1, j += 8)
{
luks->ct_buf[i] = hex_to_u32 (ct_pos + j);
}
hex_decode (ct_pos, LUKS_CT_HEX_LEN, (u8 *) luks->ct_buf);
return (PARSER_OK);
}
@ -327,6 +318,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_CIPHER_MODE_CBC_PLAIN64: cipher_mode = "cbc-plain64"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN: cipher_mode = "xts-plain"; break;
case HC_LUKS_CIPHER_MODE_XTS_PLAIN64: cipher_mode = "xts-plain64"; break;
default: return 0;
}
// key size
@ -338,6 +330,7 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
case HC_LUKS_KEY_SIZE_128: key_size = 128; break;
case HC_LUKS_KEY_SIZE_256: key_size = 256; break;
case HC_LUKS_KEY_SIZE_512: key_size = 512; break;
default: return 0;
}
// iterations
@ -346,36 +339,21 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
// salt
#define LUKS_SALT_HEX_LEN (LUKS_SALT_LEN * 2 + 1)
char salt_buf[LUKS_SALT_HEX_LEN + 1] = { 0 };
char salt_buf[LUKS_SALT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_SALT_LEN / 4; i += 1, j += 8)
{
snprintf (salt_buf + j, LUKS_SALT_HEX_LEN - j, "%08x", byte_swap_32 (salt->salt_buf[i]));
}
hex_encode ((const u8 *) salt->salt_buf, LUKS_SALT_LEN, (u8 *) salt_buf);
// af
#define LUKS_AF_HEX_LEN (LUKS_AF_MAX_LEN * 2 + 1)
char af_buf[LUKS_AF_MAX_HEX_LEN + 1] = { 0 };
char af_buf[LUKS_AF_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < luks->af_len / 4; i += 1, j += 8)
{
snprintf (af_buf + j, LUKS_AF_HEX_LEN - j, "%08x", byte_swap_32 (luks->af_buf[i]));
}
hex_encode ((const u8 *) luks->af_buf, luks->af_len, (u8 *) af_buf);
// ct
#define LUKS_CT_HEX_LEN (LUKS_CT_LEN * 2 + 1)
char ct_buf[LUKS_CT_HEX_LEN + 1] = { 0 };
char ct_buf[LUKS_CT_HEX_LEN] = { 0 };
for (u32 i = 0, j = 0; i < LUKS_CT_LEN / 4; i += 1, j += 8)
{
snprintf (ct_buf + j, LUKS_CT_HEX_LEN - j, "%08x", byte_swap_32 (luks->ct_buf[i]));
}
hex_encode ((const u8 *) luks->ct_buf, LUKS_CT_LEN, (u8 *) ct_buf);
// output

View File

@ -1,12 +1,15 @@
#!/usr/bin/env python3
import sys
#
# Author......: See docs/credits.txt
# License.....: MIT
#
from argparse import ArgumentParser
from collections import namedtuple
from dataclasses import dataclass
from os import SEEK_SET
from struct import Struct
from sys import stderr
from typing import List
try:
@ -82,7 +85,8 @@ class KeyVersion1:
def __init__(self, active, iterations, salt, af):
self.active = self.Active(active)
assert iterations >= 0, "key iterations cannot be less than zero"
if (self.active in [self.Active.ENABLED, self.Active.ENABLED_OLD]) and (iterations <= 0):
raise ValueError("key iterations cannot be less than zero")
self.iterations = iterations
self.salt = salt
self.af = af
@ -150,45 +154,62 @@ class HeaderVersion1:
keys: List[KeyVersion1]
def __init__(self, magic, version, cipher, mode, hash, payload, key_size, digest, salt, iterations, uuid, keys):
assert magic == self.MAGIC, "Invalid magic bytes"
if magic != self.MAGIC:
raise ValueError("invalid magic bytes")
self.magic = magic
assert version == self.VERSION, "Invalid version"
if version != self.VERSION:
raise ValueError("invalid version")
self.version = version
if isinstance(cipher, bytes):
try:
cipher = bytes_to_str(cipher)
self.cipher = self.Cipher(cipher)
except UnicodeDecodeError as e:
raise ValueError("Cannot decode cipher") from e
self.cipher = self.Cipher(cipher)
raise ValueError("cannot decode cipher") from e
except ValueError as e:
raise ValueError("invalid cipher value") from e
if isinstance(mode, bytes):
try:
mode = bytes_to_str(mode)
self.mode = self.Mode(mode)
except UnicodeDecodeError as e:
raise ValueError("Cannot decode mode") from e
self.mode = self.Mode(mode)
raise ValueError("cannot decode mode") from e
except ValueError as e:
raise ValueError("invalid mode value") from e
if isinstance(hash, bytes):
try:
hash = bytes_to_str(hash)
self.hash = self.Hash(hash)
except UnicodeDecodeError as e:
raise ValueError("Cannot decode hash") from e
self.hash = self.Hash(hash)
raise ValueError("cannot decode hash") from e
except ValueError as e:
raise ValueError("invalid hash value") from e
self.payload = payload
self.key_size = self.KeySize(key_size)
try:
self.key_size = self.KeySize(key_size)
except ValueError as e:
raise ValueError("invalid key size provided") from e
self.digest = digest
self.salt = salt
assert iterations > 0, "Iterations cannot be less or equal to zero"
try:
iterations = int(iterations)
except ValueError as e:
raise ValueError("iterations is not a number") from e
if iterations <= 0:
raise ValueError("iterations cannot be less or equal to zero")
self.iterations = iterations
if isinstance(uuid, bytes):
try:
uuid = bytes_to_str(uuid)
except UnicodeDecodeError as e:
raise ValueError("Cannot decode UUID") from e
raise ValueError("cannot decode UUID") from e
self.uuid = uuid
if all(isinstance(key, tuple) for key in keys):
keys = [KeyVersion1(*key) for key in keys]
elif all(isinstance(key, dict) for key in keys):
keys = [KeyVersion1(**key) for key in keys]
assert all(isinstance(key, KeyVersion1) for key in keys), "Not a key object provided"
if any(not isinstance(key, KeyVersion1) for key in keys):
raise ValueError("not a key object provided")
self.keys = keys
@ -201,16 +222,13 @@ def extract_version1(file):
# prepare structs
key_struct = Struct(">LL32sLL")
header_struct = Struct(
">6sH32s32s32sLL20s32sL40s"
+ str(key_struct.size * KEYS_COUNT)
+ "s"
+ str(PADDING_LENGTH)
+ "x"
">6sH32s32s32sLL20s32sL40s" + str(key_struct.size * KEYS_COUNT) + "s" + str(PADDING_LENGTH) + "x"
)
# read header
header = file.read(header_struct.size)
assert len(header) == header_struct.size, "File contains less data than needed"
if len(header) < header_struct.size:
raise ValueError("file contains less data than needed")
# convert bytes into temporary header
header = header_struct.unpack(header)
@ -224,7 +242,8 @@ def extract_version1(file):
for key in tmp_keys:
file.seek(key.material_offset * SECTOR_SIZE, SEEK_SET)
af = file.read(header.key_bytes * key.stripes)
assert len(af) == (header.key_bytes * key.stripes), "File contains less data than needed"
if len(af) < (header.key_bytes * key.stripes):
raise ValueError("file contains less data than needed")
key = KeyVersion1(key.active, key.iterations, key.salt, af)
keys.append(key)
@ -232,7 +251,8 @@ def extract_version1(file):
# read payload
file.seek(header.payload_offset * SECTOR_SIZE, SEEK_SET)
payload = file.read(PAYLOAD_SIZE)
assert len(payload) == PAYLOAD_SIZE, "File contains less data than needed"
if len(payload) < PAYLOAD_SIZE:
raise ValueError("file contains less data than needed")
# convert into header
header = HeaderVersion1(
@ -275,54 +295,52 @@ def extract_version1(file):
break
else:
# all keys are disabled
raise ValueError("All keys are disabled")
raise ValueError("all keys are disabled")
# main
def main(args):
if __name__ == "__main__":
# prepare parser and parse args
parser = ArgumentParser(description="luks2hashcat extraction tool")
parser.add_argument("path", type=str, help="path to LUKS container")
args = parser.parse_args(args)
args = parser.parse_args()
# prepare struct
header_struct = Struct(">6sH")
with open(args.path, "rb") as file:
# read pre header
header = file.read(header_struct.size)
assert len(header) == header_struct.size, "File contains less data than needed"
# convert bytes into temporary pre header
header = header_struct.unpack(header)
header = TmpHeaderPre(*header)
# check magic bytes
magic_bytes = {
HeaderVersion1.MAGIC,
}
assert header.magic in magic_bytes, "Improper magic bytes"
# back to start of the file
file.seek(0, SEEK_SET)
# extract with proper function
try:
mapping = {
HeaderVersion1.VERSION: extract_version1,
}
extract = mapping[header.version]
extract(file)
except KeyError as e:
raise ValueError("Unsupported version") from e
if __name__ == "__main__":
try:
main(sys.argv[1:])
with open(args.path, "rb") as file:
# read pre header
header = file.read(header_struct.size)
if len(header) < header_struct.size:
parser.error("file contains less data than needed")
# convert bytes into temporary pre header
header = header_struct.unpack(header)
header = TmpHeaderPre(*header)
# check magic bytes
magic_bytes = {
HeaderVersion1.MAGIC,
}
if header.magic not in magic_bytes:
parser.error("improper magic bytes")
# back to start of the file
file.seek(0, SEEK_SET)
# extract with proper function
try:
mapping = {
HeaderVersion1.VERSION: extract_version1,
}
extract = mapping[header.version]
extract(file)
except KeyError as e:
raise ValueError("unsupported version") from e
except IOError as e:
print('Error:', e.strerror, file=stderr)
except (AssertionError, ValueError) as e:
print('Error:', e, file=stderr)
parser.error(e.strerror.lower())
except ValueError as e:
parser.error(str(e))