expand key lenght, add key hashing

This commit is contained in:
redlineo committed 2025-01-20 14:55:18 +00:00
1 parent 4630460b88
commit 842beb2716
4 files changed
+27 -17

No files matched your search

+20 -14
View File
@@ -4,7 +4,7 @@
uint8_t dec_pass[2][16] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; uint8_t dec_pass[2][16] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
uint8_t readed_key[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t readed_key[128] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t count_char_key = 0; uint8_t count_char_key = 0;
@@ -37,36 +37,41 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
kuz_key_t key; kuz_key_t key;
w128_t x; w128_t x;
kuz_set_decrypt_key(&key, readed_key); SHA256_CTX ctx;
sha256_init(&ctx);
sha256_update(&ctx,readed_key,MAX_KEY_LEN);
BYTE result_key[SHA256_BLOCK_SIZE];
sha256_final(&ctx,result_key);
kuz_set_decrypt_key(&key, result_key);
for (uint8_t j = 0; j < 2; j++) { for (uint8_t j = 0; j < 2; j++) {
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
x.b[i] = encrypted_passwords[j][i]; x.b[i] = encrypted_passwords[j][i];
} }
kuz_decrypt_block(&key, &x); kuz_decrypt_block(&key, &x);
#ifdef USE_RED_CRY_DEBUG #ifdef USE_RED_CRY_DEBUG
dprintf("decrypted\t="); dprintf("decrypted\t=");
print_w128(&x); print_w128(&x);
print_chars_w128(&x); print_chars_w128(&x);
#endif #endif
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
dec_pass[j][i] = x.b[i]; dec_pass[j][i] = x.b[i];
} }
} }
}; };
// TODO: add encrypt new passwords with binding on new keys // TODO: add encrypt new passwords with binding on new keys
// and storing all these to EEPROM // and storing all these to EEPROM
// void encrypt_pass_kuzn(){ // void encrypt_pass_kuzn(){
// kuz_set_encrypt_key(&key,readed_key); // kuz_set_encrypt_key(&key,readed_key);
// for (uint8_t i=0; i<16; i++) { // for (uint8_t i=0; i<16; i++) {
// x.b[i] = pass[i]; // x.b[i] = pass[i];
// } // }
// kuz_encrypt_block(&key,&x); // kuz_encrypt_block(&key,&x);
// printf("encrypted\t="); print_w128(&x); // printf("encrypted\t="); print_w128(&x);
// print_chars_w128(&x); // print_chars_w128(&x);
// } // }
void send_chars_pass(uint8_t *out) { void send_chars_pass(uint8_t *out) {
@@ -80,14 +85,15 @@ uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const
switch (keycode) { switch (keycode) {
case RED_CRY_M: case RED_CRY_M:
if (record->event.pressed) { if (record->event.pressed) {
#ifdef USE_RED_CRY_DEBUG #ifdef USE_RED_CRY_DEBUG
print_int(readed_key); print_int(readed_key);
#endif #endif
crypto_mode = 0; crypto_mode = 0;
count_char_key = 0; count_char_key = 0;
decrypt_pass_kuzn(encrypted_passwords); decrypt_pass_kuzn(encrypted_passwords);
} }
default: default:
//reading key
return kc_to_ascii(keycode, record, readed_key, &count_char_key); return kc_to_ascii(keycode, record, readed_key, &count_char_key);
break; break;
} }
+2
View File
@@ -21,6 +21,8 @@
# include "aes.h" # include "aes.h"
# endif # endif
#define MAX_KEY_LEN 128
enum red_crypto_keys { enum red_crypto_keys {
RED_CRY_M = SAFE_RANGE + 0x80, // added safe range offset RED_CRY_M = SAFE_RANGE + 0x80, // added safe range offset
RED_RNG, RED_RNG,
+4 -3
View File
@@ -158,13 +158,14 @@ void sha256_final(SHA256_CTX *ctx, BYTE hash[])
} }
} }
/*********************** TEST FUNCTION DEFINITIONS ***********************/ size_t u_strlen(const unsigned char * array)
#ifdef TEST_FUNCTIONS_ENABLED
inline size_t u_strlen(const unsigned char * array)
{ {
return strlen((const char*)array); return strlen((const char*)array);
} }
/*********************** TEST FUNCTION DEFINITIONS ***********************/
#ifdef TEST_FUNCTIONS_ENABLED
void exec_sha256_test(void) void exec_sha256_test(void)
{ {
BYTE text1[] = {"abc"}; BYTE text1[] = {"abc"};
+1
View File
@@ -31,6 +31,7 @@ typedef struct {
void sha256_init(SHA256_CTX *ctx); void sha256_init(SHA256_CTX *ctx);
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len); void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX *ctx, BYTE hash[]); void sha256_final(SHA256_CTX *ctx, BYTE hash[]);
size_t u_strlen(const unsigned char * array);
// test // test
#ifdef TEST_FUNCTIONS_ENABLED #ifdef TEST_FUNCTIONS_ENABLED