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
+16 -6

No files matched your search

+9 -3
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,7 +37,13 @@ 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];
@@ -54,7 +60,6 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
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
@@ -88,6 +93,7 @@ uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const
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