add hashing key with SHA256, update readme

This commit is contained in:
redlineo committed 2025-01-21 07:47:11 +00:00
1 parent 842beb2716
commit 6b2605d270
3 files changed
+46 -10

No files matched your search

+14 -5
View File
@@ -5,15 +5,16 @@
Password manager for (almost) any QMK keyboards. Password manager for (almost) any QMK keyboards.
Supports cryptographic algorithms: Supports cryptographic algorithms:
- [x] Kuznechik (Russian GOST cipher) - [x] Kuznechik (Russian GOST cipher)
- [ ] SHA256 (for hashing key) - [x] SHA256 (for hashing key)
- [ ] Streebog (for hashing key, Russian GOST hash algorithm)
- [ ] AES256 - [ ] AES256
## Features and plans ## Features and plans
- [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
- [ ] 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 password length from 16 byte to 64 - [ ] expand stored passwords length from 16 byte to 64
- [ ] expand number of stored passwords, may be with auto-adding new keycodes - [ ] expand number of stored passwords, may be with auto-adding new keycodes
- [ ] add CBC mode for Kuznechik, it will increase security - [ ] add CBC mode for Kuznechik, it will increase security
@@ -33,17 +34,25 @@ include keyboards/<your keyboard>/<path to your keymap folder>/red_crypto/red_cr
#include "red_crypto/red_crypto.h" #include "red_crypto/red_crypto.h"
``` ```
4. Enable chosen algorithms. Now you can use only `Kuznechik`. 4. Enable chosen algorithms with define in `config.h`. Now you can use only `Kuznechik`.
```c ```c
#define USE_KUZNECHIK_8 #define USE_KUZNECHIK_8
``` ```
If you want use SHA256 of your key to encrypt passwords, define this in `config.h`.
```c
#define USE_SHA256_KEY
```
5. Encrypt your passwords with chosen algorithm (AES, Kuznechik). Now available only Kuznechik. You can use `CyberChef`. 5. Encrypt your passwords with chosen algorithm (AES, Kuznechik). Now available only Kuznechik. You can use `CyberChef`.
> Don't use web version! We are here for security, right? > Don't use web version! We are here for security, right?
Choose `GOST Encrypt`, then choose type `GOST R 34.12 (Kuznechik, 2015)`, not `Magma`. Choose mode `ECB`. Now, there is no other modes for `Kuznechik`. If you've enabled SHA256 for key, choose `SHA2`, then `SHA256` mode and `64` rounds. Hash your key, then copy it to next step.
Choose `GOST Encrypt`, then choose type `GOST R 34.12 (Kuznechik, 2015)`, not `Magma`. Choose mode `ECB`. Now there is no other modes for `Kuznechik`.
> Don't forget IV for GOST > Don't forget IV for GOST
``` ```
+29 -4
View File
@@ -4,7 +4,13 @@
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}};
//you can use key any length with SHA256, kuznechik use only 32byte
#ifdef USE_SHA256_KEY
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 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};
#endif
#ifndef USE_SHA256_KEY
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
uint8_t count_char_key = 0; uint8_t count_char_key = 0;
@@ -33,17 +39,36 @@ void print_int(uint8_t *c) {
dprintf("\n"); dprintf("\n");
}; };
void print_hex(uint8_t *h) {
for (uint8_t i = 0; i < 32; i++) {
dprintf("%x ", h[i]);
}
dprintf("\n");
};
size_t min_len(size_t a, size_t b) {
if (a < b)
return a;
else
return b;
}
void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) { 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;
#ifdef USE_SHA256_KEY
SHA256_CTX ctx; SHA256_CTX ctx;
sha256_init(&ctx); sha256_init(&ctx);
sha256_update(&ctx,readed_key,MAX_KEY_LEN); sha256_update(&ctx, readed_key, min_len(u_strlen(readed_key), MAX_KEY_LEN));
BYTE result_key[SHA256_BLOCK_SIZE]; BYTE result_key[SHA256_BLOCK_SIZE];
sha256_final(&ctx,result_key); sha256_final(&ctx, result_key);
print_hex(result_key);
kuz_set_decrypt_key(&key, result_key); kuz_set_decrypt_key(&key, result_key);
#endif
#ifndef USE_SHA256_KEY
kuz_set_decrypt_key(&key, readed_key);
#endif
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];
@@ -93,7 +118,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 // 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;
} }
+3 -1
View File
@@ -14,14 +14,16 @@
# ifdef USE_RED_KUZNECHIK_8 # ifdef USE_RED_KUZNECHIK_8
# include "kuznechik_8bit.h" # include "kuznechik_8bit.h"
# ifdef USE_SHA256_KEY
# include "sha256.h" # include "sha256.h"
# endif # endif
# endif
# ifdef USE_RED_AES_256 # ifdef USE_RED_AES_256
# include "aes.h" # include "aes.h"
# endif # endif
#define MAX_KEY_LEN 128 # 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