merged kc_to_ascii with main, add debug define, update readme

This commit is contained in:
redlineo committed 2025-01-20 14:06:45 +00:00
1 parent 15becc1695
commit 9e653cab69
4 files changed
+51 -34

No files matched your search

+38 -15
View File
@@ -1,24 +1,33 @@
# RED_CRYPTO ver 0.2.0 # RED_CRYPTO ver 0.3.0
## Description ## Description
Password manager for (almost) any QMK keyboards. Password manager for (almost) any QMK keyboards.
Supports cryptographic algorithms: Supports cryptographic algorithms:
- [ ] AES256, - [x] Kuznechik (Russian GOST cipher)
- [x] Kuznechik (Russian GOST cipher), - [ ] SHA256 (for hashing key)
- [ ] SHA256. - [ ] 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
- [ ] expand number of stored passwords, may be with auto-adding new keycodes
- [ ] add CBC mode for Kuznechik, it will increase security
## Installation ## Installation
1. Clone this repo to your keymap folder. 1. Clone this repo to your keymap folder.
2. Copy this string to *rules.mk*. Don't forget to insert your names. This is make rules for including all needed file to firmwire. 2. Copy this string to **rules.mk**. Don't forget to insert your names. This is make rules for including all needed file to firmwire.
```make ```make
include keyboards/<keyboard>/<path to your keymap folder>/red_crypto/red_crypto.mk include keyboards/<your keyboard>/<path to your keymap folder>/red_crypto/red_crypto.mk
``` ```
3. Import library in *keymap.c*. 3. Import library in **keymap.c**.
```c ```c
#include "red_crypto/red_crypto.h" #include "red_crypto/red_crypto.h"
@@ -30,12 +39,18 @@ include keyboards/<keyboard>/<path to your keymap folder>/red_crypto/red_crypto.
#define USE_KUZNECHIK_8 #define USE_KUZNECHIK_8
``` ```
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 Cipher`, then choose type `Kuznechik 34.12-2014`, not Magma. Choose mode ECB. Now, there is no CBC or CTR. 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`.
> Don't forget IV for GOST > Don't forget IV for GOST
> ```94208510C2C001FB01C0C21085209401``` ```
94208510C2C001FB01C0C21085209401
```
6. Add your encrypted passwords in "keymap.c". Now you can encrypt 2 passwords with length <=16 byte. Keep this information in secret. Even if there are no plaintext. 6. Add your encrypted passwords in **keymap.c**. Now you can encrypt 2 passwords with length <=16 byte. Keep this information in secret. Even if there are no plaintext.
```c ```c
const uint8_t encrypted_passwords[2][16] = { {0,0,0,...,0,0,0}, {0,0,0,...,0,0,0} }; const uint8_t encrypted_passwords[2][16] = { {0,0,0,...,0,0,0}, {0,0,0,...,0,0,0} };
@@ -44,22 +59,30 @@ const uint8_t encrypted_passwords[2][16] = { {0,0,0,...,0,0,0}, {0,0,0,...,0,0,0
7. Add new layer or set new keyes everywhere you want. 7. Add new layer or set new keyes everywhere you want.
- `RED_TEST` - execute test functions of every algorithm with. Available only with `#define TEST_FUNCTIONS_ENABLED` and `COMMAND_ENABLE=yes`. You can see output via `hid_listen`. - `RED_TEST` - execute test functions of every algorithm with. Available only with `#define TEST_FUNCTIONS_ENABLED` and `COMMAND_ENABLE=yes`. You can see output via `hid_listen`.
- `GET_PASS` - execute reading password for encrypted passwords. After entering password, tap this key again. Now, you can use `RED_PASSX` keys. - `RED_CRY_M` - execute reading password for encrypted passwords. After entering password, tap this key again. Now, you can use `RED_PASSX` keys.
- `RED_PASSX` - where `X` is number of your password in database. After tapping, keyboard send decrypted password. - `RED_PASSX` - where `X` is number of your password in database. After tapping, keyboard send decrypted password.
- `RED_RNG` - use 32 times function named `tap_random_base64` from QMK. It's for generating random strings. But now random seed is not unique for every keyboard's power on. - `RED_RNG` - use 32 times function named `tap_random_base64` from QMK. It's for generating random strings. But now random seed is not unique for every keyboard's power on.
8. Copy this string to function *process_record_user* in *keymap.c* before all your code. It uses "switch case" construction inside. 8. Copy this string to function **process_record_user** in **keymap.c** before all your code. It uses "switch case" construction inside.
```c ```c
crypto_process_record_user(keycode, event, encrypted_passwords); crypto_process_record_user(keycode, event, encrypted_passwords);
``` ```
9. Flash your keyboard. 9. Compile and flash your keyboard.
## Usage ## Usage
Tap `GET_PASS`. Enter password. Tap `GET_PASS` again to confirm. Tap `RED_CRY_M`. Enter password. Tap `RED_CRY_M` again to confirm.
Now you can use `RED_PASSX` to send decrypted passwords. Now you can use `RED_PASSX` to send decrypted passwords.
If you have missed while entering password, just tap `GET_PASS` and tap `GET_PASS`. If you have missed while entering password, just tap `RED_CRY_M` and tap `RED_CRY_M`.
## Related projects
Thanks to the authors of these repositories:
- https://github.com/mjosaarinen/kuznechik - kuznechik implementation for 8bit and 128bit
- https://github.com/B-Con/crypto-algorithms - other crypto algorithms
+2
View File
@@ -12,7 +12,9 @@ void write_keycode(uint8_t up_key, uint8_t low_key, keyrecord_t *record, uint8_t
} else { } else {
readed_key[*count_char_key] = low_key; readed_key[*count_char_key] = low_key;
} }
#ifdef USE_RED_CRY_DEBUG
dprintf("%d", readed_key[*count_char_key]); dprintf("%d", readed_key[*count_char_key]);
#endif
*count_char_key = *count_char_key + 1; *count_char_key = *count_char_key + 1;
} }
}; };
+7 -10
View File
@@ -13,7 +13,7 @@ uint8_t crypto_mode = 0;
void print_chars_w128(w128_t *x) { void print_chars_w128(w128_t *x) {
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
if (x->b[i] == 0x00) break; if (x->b[i] == 0x00) break;
printf("%c", x->b[i]); dprintf("%c", x->b[i]);
} }
dprintf("\n"); dprintf("\n");
}; };
@@ -21,14 +21,14 @@ void print_chars_w128(w128_t *x) {
void print_chars(uint8_t *c) { void print_chars(uint8_t *c) {
for (uint8_t i = 0; i < 32; i++) { for (uint8_t i = 0; i < 32; i++) {
if (c[i] == 0x00) break; if (c[i] == 0x00) break;
printf("%c", c[i]); dprintf("%c", c[i]);
} }
dprintf("\n"); dprintf("\n");
}; };
void print_int(uint8_t *c) { void print_int(uint8_t *c) {
for (uint8_t i = 0; i < 32; i++) { for (uint8_t i = 0; i < 32; i++) {
printf("%d", c[i]); dprintf("%d", c[i]);
} }
dprintf("\n"); dprintf("\n");
}; };
@@ -44,9 +44,11 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
} }
kuz_decrypt_block(&key, &x); kuz_decrypt_block(&key, &x);
#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
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];
@@ -76,16 +78,11 @@ void send_chars_pass(uint8_t *out) {
uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const uint8_t encrypted_passwords[2][16]) { uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const uint8_t encrypted_passwords[2][16]) {
if (crypto_mode) { if (crypto_mode) {
switch (keycode) { switch (keycode) {
// case KC_1:
// if (record->event.pressed) {
// readed_key[count_char_key] = ASCII_LOW_1;
// count_char_key++;
// }
// return 1;
// break;
case RED_CRY_M: case RED_CRY_M:
if (record->event.pressed) { if (record->event.pressed) {
#ifdef USE_RED_CRY_DEBUG
print_int(readed_key); print_int(readed_key);
#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);
+4 -9
View File
@@ -3,7 +3,6 @@
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
#include "quantum.h" #include "quantum.h"
#ifndef RED_CRYPTO_H #ifndef RED_CRYPTO_H
# define RED_CRYPTO_H # define RED_CRYPTO_H
@@ -12,6 +11,7 @@
// #ifdef USE_RED_KUZNECHIK_128 // #ifdef USE_RED_KUZNECHIK_128
// #include "kuznechik_128bit.h" // #include "kuznechik_128bit.h"
// #endif // #endif
# ifdef USE_RED_KUZNECHIK_8 # ifdef USE_RED_KUZNECHIK_8
# include "kuznechik_8bit.h" # include "kuznechik_8bit.h"
# include "sha256.h" # include "sha256.h"
@@ -21,19 +21,14 @@
# include "aes.h" # include "aes.h"
# endif # endif
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_PASS1,
RED_PASS2,
RED_RNG, RED_RNG,
RED_TEST RED_TEST,
RED_PASS1,
RED_PASS2
}; };
uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const uint8_t encrypted_passwords[2][16]); uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const uint8_t encrypted_passwords[2][16]);
#endif #endif