unified dec_pass array, update readme

This commit is contained in:
redlineo committed 2025-01-22 07:02:14 +00:00
1 parent 90399dc61b
commit aaa6f71708
2 files changed
+24 -32

No files matched your search

+3 -5
View File
@@ -14,8 +14,9 @@ Supports cryptographic algorithms:
- [x] add read all ASCII-printable symbols for key - [x] add read all ASCII-printable symbols for key
- [x] add Kuznechik lib for non 128 bit MCU - [x] add Kuznechik lib for non 128 bit MCU
- [x] use SHA256 for hashing key to set key length to 32 bytes - [x] use SHA256 for hashing key to set key length to 32 bytes
- [ ] expand stored passwords length from 16 byte to 64 - [x] expand stored passwords length from 16 byte to 64
- [ ] expand number of stored passwords, may be with auto-adding new keycodes - [x] expand number of stored passwords (manual adding new keys)
- [ ] write new passwords to EEPROM without flashing firmware
- [ ] add CBC mode for Kuznechik, it will increase security - [ ] add CBC mode for Kuznechik, it will increase security
## Installation ## Installation
@@ -86,9 +87,6 @@ const uint8_t encrypted_passwords[STORAGE_SIZE][STORAGE_PASS_LEN] = {
If you want more passwords in storage, you should: If you want more passwords in storage, you should:
- add keys `RED_PASSX` into `enum red_crypto_keys` in `red_crypto.h` - add keys `RED_PASSX` into `enum red_crypto_keys` in `red_crypto.h`
- add into `crypto_proccess_record_user` handling new keys - add into `crypto_proccess_record_user` handling new keys
- add into `uint8_t dec_pass[STORAGE_SIZE][STORAGE_PASS_LEN]` additional data. There are must be same size as `encrypted_passwords`.
> I know, that's inconvenient. I'm sorry, trying to do something with it.
7. Add new layer or set new keyes everywhere you want. 7. Add new layer or set new keyes everywhere you want.
+21 -27
View File
@@ -2,27 +2,15 @@
#include "red_crypto.h" #include "red_crypto.h"
uint8_t dec_pass[STORAGE_SIZE][STORAGE_PASS_LEN] = { uint8_t dec_pass[STORAGE_SIZE][STORAGE_PASS_LEN];
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, void init_dec_pass() {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, for (uint8_t i = 0; i < STORAGE_SIZE; i++) {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, for (uint8_t j = 0; j < STORAGE_PASS_LEN; j++) {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, dec_pass[i][j] = 0x00;
}
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
// you can use key any length with SHA256, kuznechik use only 32byte // you can use key any length with SHA256, kuznechik use only 32byte
#ifdef USE_SHA256_KEY #ifdef USE_SHA256_KEY
@@ -32,8 +20,6 @@ uint8_t readed_key[128] = {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[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};
#endif #endif
const uint8_t test_pass_block[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t count_char_key = 0; uint8_t count_char_key = 0;
uint8_t crypto_mode = 0; uint8_t crypto_mode = 0;
@@ -79,6 +65,8 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[STORAGE_SIZE][STORAGE_P
kuz_key_t key; kuz_key_t key;
w128_t x; w128_t x;
init_dec_pass();
#ifdef USE_SHA256_KEY #ifdef USE_SHA256_KEY
SHA256_CTX ctx; SHA256_CTX ctx;
sha256_init(&ctx); sha256_init(&ctx);
@@ -96,8 +84,8 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[STORAGE_SIZE][STORAGE_P
dprintf("decrypted\t="); dprintf("decrypted\t=");
#endif #endif
for (uint8_t k = 0; k < STORAGE_PASS_LEN / 16; k++) { for (uint8_t k = 0; k < STORAGE_PASS_LEN / 16; k++) {
uint8_t cnt_zeros=0; uint8_t cnt_zeros = 0;
for (uint8_t z = 0+k*16; z < 16+k*16; z++) { for (uint8_t z = 0 + k * 16; z < 16 + k * 16; z++) {
if (encrypted_passwords[j][z] == 0x00) { if (encrypted_passwords[j][z] == 0x00) {
cnt_zeros++; cnt_zeros++;
} else { } else {
@@ -105,16 +93,16 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[STORAGE_SIZE][STORAGE_P
break; break;
} }
} }
if (cnt_zeros!=0) break; // if there is zero 8 byte block in password, e.g. password length <32 or <64 if (cnt_zeros != 0) break; // if there is zero 8 byte block in password, e.g. password length <32 or <64
for (uint8_t i = 0 + k * 16; i < 16 + k * 16; i++) { for (uint8_t i = 0 + k * 16; i < 16 + k * 16; i++) {
x.b[i%16] = encrypted_passwords[j][i]; x.b[i % 16] = encrypted_passwords[j][i];
} }
kuz_decrypt_block(&key, &x); kuz_decrypt_block(&key, &x);
for (uint8_t i = 0 + k * 16; i < 16 + k * 16; i++) { for (uint8_t i = 0 + k * 16; i < 16 + k * 16; i++) {
dec_pass[j][i] = x.b[i%16]; dec_pass[j][i] = x.b[i % 16];
} }
#ifdef USE_RED_CRY_DEBUG #ifdef USE_RED_CRY_DEBUG
@@ -182,6 +170,12 @@ uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const
send_chars_pass(dec_pass[3]); send_chars_pass(dec_pass[3]);
} }
break; break;
// if you want to add more keys for passwords, copy this `case`
// case RED_PASSX: //change X here
// if (record->event.pressed) {
// send_chars_pass(dec_pass[X]); //change X here
// }
// break;
case RED_RNG: case RED_RNG:
if (record->event.pressed) { if (record->event.pressed) {
// TODO: change seed // TODO: change seed