From 77366d97363401c4a2df33d1b301ac448b777af1 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Fri, 13 Apr 2018 08:29:17 -0500 Subject: [PATCH] Begin OpenSSL AES Key transformation --- crypto-openssl.c | 52 +++++++++++++++++++++++++++++++++++++++++++----- sha256.c | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 sha256.c diff --git a/crypto-openssl.c b/crypto-openssl.c index b8a3b36..ef1801d 100755 --- a/crypto-openssl.c +++ b/crypto-openssl.c @@ -45,17 +45,59 @@ #include "mod0keecrack.h" -int aes_transformkey(m0_kdbx_header_entry_t *hdr, uint8_t *tkey, size_t tkeylen) { +int aes_transformkey(m0_kdbx_header_entry_t *hdr, uint8_t *tkey, size_t tkeylen) +{ + uint64_t rounds = 0; + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + + EVP_EncryptInit_ex( + ctx, + EVP_aes_128_ecb(), + NULL, + key, + NULL); + + EVP_EncryptUpdate( + ctx, + NULL, + 0, + tkey, + tkeylen); + + + for(rounds = 0; rounds < hdr[TRANSFORMROUNDS].qw; rounds++) { + } + +cleanup: + if (ctx) { + EVP_CIPHER_CTX_free(ctx); + } } -int aes_decrypt_check(m0_kdbx_header_entry_t *hdr, uint8_t *masterkey, m0_kdbx_payload_t *p) { +bool aes_decrypt_check(m0_kdbx_header_entry_t *hdr, uint8_t *masterkey, m0_kdbx_payload_t *p) { } int sha256_hash(uint8_t *hash, uint8_t *data, size_t len) { EVP_MD_CTX *ctx = EVP_MD_CTX_new(); - EVP_DigestInit(ctx, EVP_sha256()); - EVP_DigestUpdate(ctx, data, len); - EVP_DigestFinal(ctx, hash, NULL); + + EVP_DigestInit( + ctx, + EVP_sha256() + ); + + EVP_DigestUpdate( + ctx, + data, + len + ); + + EVP_DigestFinal( + ctx, + hash, + NULL + ); + + return 0; } diff --git a/sha256.c b/sha256.c new file mode 100644 index 0000000..38a6a6c --- /dev/null +++ b/sha256.c @@ -0,0 +1,40 @@ +/* + * ===================================================================================== + * + * Filename: sha256.c + * + * Description: An OpenSSL SHA256 Utility + * + * Version: 1.0 + * Created: 04/03/2018 06:13:41 PM + * Revision: none + * Compiler: gcc + * + * Author: William Brawner (Billy), billybrawner@gmail.com + * Organization: + * + * ===================================================================================== + */ +#include +#include +#include +#include "helper.h" + +int main(int argc, char ** argv) { + if (argc < 2) { + printf("Please enter a string to hash\n"); + return 1; + } + + printf("You entered %s\n", argv[1]); + printf("Your string contains %d characters\n", strlen(argv[1])); + + EVP_MD_CTX *ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx, EVP_sha256()); + EVP_DigestUpdate(ctx, argv[1], strlen(argv[1])); + char* hash = malloc(EVP_MD_CTX_size(ctx)); + EVP_DigestFinal(ctx, hash, NULL); + printf("Your hashed string: "); + print_hex_buf(hash, 32); + printf("\n"); +}