Compare commits
4
Commits
kc_to_ascii
...
hash_key
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b2605d270 | ||
|
|
842beb2716 | ||
|
|
4630460b88 | ||
|
|
9e653cab69 |
No files matched your search
@@ -1,41 +1,65 @@
|
||||
# RED_CRYPTO ver 0.2.0
|
||||
# RED_CRYPTO ver 0.3.0
|
||||
|
||||
## Description
|
||||
|
||||
Password manager for (almost) any QMK keyboards.
|
||||
Supports cryptographic algorithms:
|
||||
- [ ] AES256,
|
||||
- [x] Kuznechik (Russian GOST cipher),
|
||||
- [ ] SHA256.
|
||||
- [x] Kuznechik (Russian GOST cipher)
|
||||
- [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
|
||||
- [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
|
||||
|
||||
## Installation
|
||||
|
||||
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
|
||||
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
|
||||
#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
|
||||
```
|
||||
|
||||
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.
|
||||
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?
|
||||
|
||||
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
|
||||
> ```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
|
||||
const uint8_t encrypted_passwords[2][16] = { {0,0,0,...,0,0,0}, {0,0,0,...,0,0,0} };
|
||||
@@ -44,22 +68,33 @@ 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.
|
||||
|
||||
- `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_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
|
||||
crypto_process_record_user(keycode,event,encrypted_passwords);
|
||||
uint8_t crypto_return = crypto_process_record_user(keycode, event, encrypted_passwords);
|
||||
if (crypto_return == 1){
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
9. Flash your keyboard.
|
||||
9. Compile and flash your keyboard.
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
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
|
||||
+4
-2
@@ -12,7 +12,9 @@ void write_keycode(uint8_t up_key, uint8_t low_key, keyrecord_t *record, uint8_t
|
||||
} else {
|
||||
readed_key[*count_char_key] = low_key;
|
||||
}
|
||||
#ifdef USE_RED_CRY_DEBUG
|
||||
dprintf("%d", readed_key[*count_char_key]);
|
||||
#endif
|
||||
*count_char_key = *count_char_key + 1;
|
||||
}
|
||||
};
|
||||
@@ -205,8 +207,8 @@ uint8_t kc_to_ascii(uint16_t keycode, keyrecord_t *record, uint8_t readed_key[],
|
||||
write_keycode(ASCII_UP_QUOTE, ASCII_LOW_QUOTE, record, readed_key, count_char_key);
|
||||
return 1;
|
||||
break;
|
||||
//i am not sure about KC_GRAVE and KC_NONUS_HASH
|
||||
//need to test
|
||||
// i am not sure about KC_GRAVE and KC_NONUS_HASH
|
||||
// need to test
|
||||
case KC_GRAVE:
|
||||
write_keycode(ASCII_NON_PRINTABLE, ASCII_GRAVE, record, readed_key, count_char_key);
|
||||
return 1;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
#include "quantum.h"
|
||||
|
||||
#ifndef KC_TO_ASCII_H
|
||||
#define KC_TO_ASCII_H
|
||||
# define KC_TO_ASCII_H
|
||||
|
||||
uint8_t kc_to_ascii(uint16_t keycode, keyrecord_t *record, uint8_t readed_key[], uint8_t *count_char_key);
|
||||
|
||||
|
||||
+46
-18
@@ -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;
|
||||
|
||||
@@ -13,7 +19,7 @@ uint8_t crypto_mode = 0;
|
||||
void print_chars_w128(w128_t *x) {
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
if (x->b[i] == 0x00) break;
|
||||
printf("%c", x->b[i]);
|
||||
dprintf("%c", x->b[i]);
|
||||
}
|
||||
dprintf("\n");
|
||||
};
|
||||
@@ -21,50 +27,76 @@ void print_chars_w128(w128_t *x) {
|
||||
void print_chars(uint8_t *c) {
|
||||
for (uint8_t i = 0; i < 32; i++) {
|
||||
if (c[i] == 0x00) break;
|
||||
printf("%c", c[i]);
|
||||
dprintf("%c", c[i]);
|
||||
}
|
||||
dprintf("\n");
|
||||
};
|
||||
|
||||
void print_int(uint8_t *c) {
|
||||
for (uint8_t i = 0; i < 32; i++) {
|
||||
printf("%d", c[i]);
|
||||
dprintf("%d", c[i]);
|
||||
}
|
||||
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, 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];
|
||||
}
|
||||
kuz_decrypt_block(&key, &x);
|
||||
|
||||
#ifdef USE_RED_CRY_DEBUG
|
||||
dprintf("decrypted\t=");
|
||||
print_w128(&x);
|
||||
print_chars_w128(&x);
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
dec_pass[j][i] = x.b[i];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// TODO: add encrypt new passwords with binding on new keys
|
||||
// and storing all these to EEPROM
|
||||
// void encrypt_pass_kuzn(){
|
||||
// kuz_set_encrypt_key(&key,readed_key);
|
||||
// for (uint8_t i=0; i<16; i++) {
|
||||
// x.b[i] = pass[i];
|
||||
// }
|
||||
// kuz_encrypt_block(&key,&x);
|
||||
// printf("encrypted\t="); print_w128(&x);
|
||||
// print_chars_w128(&x);
|
||||
// kuz_set_encrypt_key(&key,readed_key);
|
||||
// for (uint8_t i=0; i<16; i++) {
|
||||
// x.b[i] = pass[i];
|
||||
// }
|
||||
// kuz_encrypt_block(&key,&x);
|
||||
// printf("encrypted\t="); print_w128(&x);
|
||||
// print_chars_w128(&x);
|
||||
// }
|
||||
|
||||
void send_chars_pass(uint8_t *out) {
|
||||
@@ -76,21 +108,17 @@ 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]) {
|
||||
if (crypto_mode) {
|
||||
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:
|
||||
if (record->event.pressed) {
|
||||
#ifdef USE_RED_CRY_DEBUG
|
||||
print_int(readed_key);
|
||||
#endif
|
||||
crypto_mode = 0;
|
||||
count_char_key = 0;
|
||||
decrypt_pass_kuzn(encrypted_passwords);
|
||||
}
|
||||
default:
|
||||
// reading key
|
||||
return kc_to_ascii(keycode, record, readed_key, &count_char_key);
|
||||
break;
|
||||
}
|
||||
|
||||
+16
-17
@@ -3,37 +3,36 @@
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "quantum.h"
|
||||
|
||||
|
||||
#ifndef RED_CRYPTO_H
|
||||
#define RED_CRYPTO_H
|
||||
# define RED_CRYPTO_H
|
||||
|
||||
#include "kc_to_ascii.h"
|
||||
# include "kc_to_ascii.h"
|
||||
|
||||
// #ifdef USE_RED_KUZNECHIK_128
|
||||
// #include "kuznechik_128bit.h"
|
||||
// #endif
|
||||
#ifdef USE_RED_KUZNECHIK_8
|
||||
#include "kuznechik_8bit.h"
|
||||
#include "sha256.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_RED_AES_256
|
||||
#include "aes.h"
|
||||
#endif
|
||||
# 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"
|
||||
# endif
|
||||
|
||||
# define MAX_KEY_LEN 128
|
||||
|
||||
enum red_crypto_keys {
|
||||
RED_CRY_M = SAFE_RANGE+0x80, // added safe range offset
|
||||
RED_PASS1,
|
||||
RED_PASS2,
|
||||
RED_CRY_M = SAFE_RANGE + 0x80, // added safe range offset
|
||||
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]);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -158,13 +158,14 @@ void sha256_final(SHA256_CTX *ctx, BYTE hash[])
|
||||
}
|
||||
}
|
||||
|
||||
/*********************** TEST FUNCTION DEFINITIONS ***********************/
|
||||
#ifdef TEST_FUNCTIONS_ENABLED
|
||||
inline size_t u_strlen(const unsigned char * array)
|
||||
size_t u_strlen(const unsigned char * array)
|
||||
{
|
||||
return strlen((const char*)array);
|
||||
}
|
||||
|
||||
/*********************** TEST FUNCTION DEFINITIONS ***********************/
|
||||
#ifdef TEST_FUNCTIONS_ENABLED
|
||||
|
||||
void exec_sha256_test(void)
|
||||
{
|
||||
BYTE text1[] = {"abc"};
|
||||
|
||||
Reference in new issue
Block a user