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
+43 -7

No files matched your search

+14 -5
View File
@@ -5,15 +5,16 @@
Password manager for (almost) any QMK keyboards.
Supports cryptographic algorithms:
- [x] Kuznechik (Russian GOST cipher)
- [ ] SHA256 (for hashing key)
- [x] SHA256 (for hashing key)
- [ ] Streebog (for hashing key, Russian GOST hash algorithm)
- [ ] AES256
## Features and plans
- [x] add read all ASCII-printable symbols for key
- [x] add Kuznechik lib for non 128 bit MCU
- [ ] use SHA256 for hashing key to set key length to 32 bytes
- [ ] expand password length from 16 byte to 64
- [x] use SHA256 for hashing key to set key length to 32 bytes
- [ ] expand stored passwords length from 16 byte to 64
- [ ] expand number of stored passwords, may be with auto-adding new keycodes
- [ ] 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"
```
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
#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`.
> 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
```
+27 -2
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}};
//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};
#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;
@@ -33,17 +39,36 @@ void print_int(uint8_t *c) {
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]) {
kuz_key_t key;
w128_t x;
#ifdef USE_SHA256_KEY
SHA256_CTX 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];
sha256_final(&ctx, result_key);
print_hex(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 i = 0; i < 16; i++) {
x.b[i] = encrypted_passwords[j][i];
+2
View File
@@ -14,8 +14,10 @@
# ifdef USE_RED_KUZNECHIK_8
# include "kuznechik_8bit.h"
# ifdef USE_SHA256_KEY
# include "sha256.h"
# endif
# endif
# ifdef USE_RED_AES_256
# include "aes.h"