pre openssl integration

This commit is contained in:
Gregory 2019-04-06 16:14:39 +03:00
parent 93ad85fc40
commit fcc8e7dca4
8 changed files with 35 additions and 9 deletions

View file

@ -18,7 +18,7 @@
# define FT_BASE64_READ_SIZE 1024 # define FT_BASE64_READ_SIZE 1024
# define FT_BASE64_ENCODE_BLOCK_SIZE 3 # define FT_BASE64_ENCODE_BLOCK_SIZE 3
# define FT_BASE64_DECODE_BLOCK_SIZE 4 # define FT_BASE64_DECODE_BLOCK_SIZE 4
# define FT_BASE64_ALPHABET_LENGTH 64 # define FT_BASE64_ALPHABET_LENGTH 65
typedef uint64_t t_byte8; typedef uint64_t t_byte8;
typedef unsigned char t_byte1; typedef unsigned char t_byte1;

29
openssl_cases.txt Normal file
View file

@ -0,0 +1,29 @@
// ENCRYPTING
1. "openssl des-ecb -S a"
prompts to enter password, generate key with given pass and salt,
prepend salt header.
2. "openssl des-ecb -pass pass:asd"
generate salt and key, prepend salt header.
3. "openssl des-ecb -S a -pass:asd"
generate key from givent salt and pass, prepend header.
4. "openssl des-ecb -S a -pass:asd -K 1"
encrypt with GIVEN key, prepend GIVEN salt hedaer.
5. "openssl des-ecb -K 1"
encrypt with given key, doesn't generate and prepend salt.
6. "openssl des-ecb -S 0 -pass pass:asd -P -pbkdf2"
generate key using PKCS5_PBKDF2_HMAC with 10000 iteration,
8 byte salt, 3 byte key, sha256 hash function
// DECRYPTING
7. "echo -n Salted__ | openssl des-ecb -d"
prompts to enter password, generate key but fails to decode.
8. "echo -n Salted__aaaaaaaa | openssl des-ecb -d"
prompts to enter password, generate key but fails to validate padding.

View file

@ -21,4 +21,5 @@ void ft_base64_init(t_base64_ctx *ctx)
ft_memcpy(ctx->alphabet, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26); ft_memcpy(ctx->alphabet, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
ft_memcpy(ctx->alphabet + 26, "abcdefghijklmnopqrstuvwxyz", 26); ft_memcpy(ctx->alphabet + 26, "abcdefghijklmnopqrstuvwxyz", 26);
ft_memcpy(ctx->alphabet + 52, "0123456789+/", 12); ft_memcpy(ctx->alphabet + 52, "0123456789+/", 12);
ctx->alphabet[64] = 0;
} }

View file

@ -81,7 +81,6 @@ void ft_des_ecb
ft_des_derive_key(&ctx); ft_des_derive_key(&ctx);
if (ctx.decode) if (ctx.decode)
{ {
ft_des_generate_decryption_round_keys(ctx.key, ctx.round_keys);
if (ctx.b64) if (ctx.b64)
ft_des_ecb_decrypt_b64(&ctx); ft_des_ecb_decrypt_b64(&ctx);
else else
@ -89,7 +88,6 @@ void ft_des_ecb
} }
else else
{ {
ft_des_generate_encryption_round_keys(ctx.key, ctx.round_keys);
if (ctx.b64) if (ctx.b64)
ft_des_ecb_encrypt_b64(&ctx); ft_des_ecb_encrypt_b64(&ctx);
else else

View file

@ -35,6 +35,7 @@ void ft_des_ecb_decrypt
t_byte1 buffer[FT_DES_BYTE_BLOCK_SIZE]; t_byte1 buffer[FT_DES_BYTE_BLOCK_SIZE];
t_byte1 message[FT_DES_BYTE_BLOCK_SIZE]; t_byte1 message[FT_DES_BYTE_BLOCK_SIZE];
ft_des_generate_decryption_round_keys(c->key, c->round_keys);
last_read = 0; last_read = 0;
while((readed = buffered_read(c, buffer))) while((readed = buffered_read(c, buffer)))
{ {

View file

@ -10,6 +10,7 @@ void ft_des_ecb_encrypt
t_byte1 buffer[FT_DES_READ_SIZE]; t_byte1 buffer[FT_DES_READ_SIZE];
t_byte8 readed; t_byte8 readed;
ft_des_generate_encryption_round_keys(ctx->key, ctx->round_keys);
while((readed = read(ctx->input_fd, buffer, FT_DES_READ_SIZE)) > 0) while((readed = read(ctx->input_fd, buffer, FT_DES_READ_SIZE)) > 0)
ft_des_ecb_encode_process_chunk(ctx, readed, buffer); ft_des_ecb_encode_process_chunk(ctx, readed, buffer);
ft_des_ecb_finish_encrypt(ctx); ft_des_ecb_finish_encrypt(ctx);

View file

@ -28,10 +28,10 @@ static int transform_block()
ft_base64_init(&ctx); ft_base64_init(&ctx);
ft_base64_encode_transform(&ctx, (t_byte1 *)"Man", buff); ft_base64_encode_transform(&ctx, (t_byte1 *)"Man", buff);
_is(ft_strcmp((char *)buff, "TWFu") == 0); _is(ft_strncmp((char *)buff, "TWFu", 4) == 0);
ft_base64_encode_transform(&ctx, (t_byte1 *)"LOL", buff); ft_base64_encode_transform(&ctx, (t_byte1 *)"LOL", buff);
_is(ft_strcmp((char *)buff, "TE9M") == 0); _is(ft_strncmp((char *)buff, "TE9M", 4) == 0);
_end("transform block"); _end("transform block");
} }

View file

@ -1,4 +0,0 @@
#!/usr/bin/env sh
while true; do
find src t inc Makefile | entr -cd make check -j8
done