Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c890ad0c33 | ||
|
|
aaa6f71708 | ||
|
|
90399dc61b | ||
|
|
1e18045a38 | ||
|
|
6d8cbd1277 | ||
|
|
c615c136b1 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
# RED_CRYPTO ver 0.3.0
|
||||
# RED_CRYPTO ver 0.5.0
|
||||
|
||||
## Description
|
||||
|
||||
@@ -14,8 +14,9 @@ Supports cryptographic algorithms:
|
||||
- [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
|
||||
- [x] expand stored passwords length from 16 byte to 64
|
||||
- [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
|
||||
|
||||
## Installation
|
||||
@@ -34,7 +35,7 @@ include keyboards/<your keyboard>/<path to your keymap folder>/red_crypto/red_cr
|
||||
#include "red_crypto/red_crypto.h"
|
||||
```
|
||||
|
||||
4. Enable chosen algorithms with define in `config.h`. Now you can use only `Kuznechik`.
|
||||
4. Define chosen algorithms and parameters in `config.h`. Now you can use only `Kuznechik`.
|
||||
|
||||
```c
|
||||
#define USE_KUZNECHIK_8
|
||||
@@ -46,6 +47,13 @@ If you want use SHA256 of your key to encrypt passwords, define this in `config.
|
||||
#define USE_SHA256_KEY
|
||||
```
|
||||
|
||||
Change storage size (default `4`) and maximum password length (default `64`).
|
||||
|
||||
```c
|
||||
#define STORAGE_SIZE 4
|
||||
#define STORAGE_PASS_LEN 64 // use a multiple of 16, e.g. 16, 32, 64... but don't forget about available memory!
|
||||
```
|
||||
|
||||
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?
|
||||
@@ -59,12 +67,27 @@ Choose `GOST Encrypt`, then choose type `GOST R 34.12 (Kuznechik, 2015)`, not `M
|
||||
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 4 passwords with any length (16, 32, 64, more not tested).
|
||||
|
||||
> Keep this information in secret. Even if there are no plaintext.
|
||||
|
||||
Chosen parameter `STORAGE_PASS_LEN` must be the same as the number of zeros in this array.
|
||||
|
||||
Chosen parameter `STORAGE_SIZE` must be the same as the number of passwords in this array.
|
||||
|
||||
```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[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},
|
||||
};
|
||||
```
|
||||
|
||||
If you want more passwords in storage, you should:
|
||||
- add keys `RED_PASSX` into `enum red_crypto_keys` in `red_crypto.h`
|
||||
- add into `crypto_proccess_record_user` handling new keys
|
||||
|
||||
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`.
|
||||
@@ -97,4 +120,4 @@ If you have missed while entering password, just tap `RED_CRY_M` and tap `RED_CR
|
||||
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
|
||||
- https://github.com/B-Con/crypto-algorithms - other crypto algorithms
|
||||
+57
-15
@@ -2,9 +2,17 @@
|
||||
|
||||
#include "red_crypto.h"
|
||||
|
||||
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[STORAGE_SIZE][STORAGE_PASS_LEN];
|
||||
|
||||
//you can use key any length with SHA256, kuznechik use only 32byte
|
||||
void init_dec_pass(void) {
|
||||
for (uint8_t i = 0; i < STORAGE_SIZE; i++) {
|
||||
for (uint8_t j = 0; j < STORAGE_PASS_LEN; j++) {
|
||||
dec_pass[i][j] = 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -53,10 +61,12 @@ size_t min_len(size_t a, size_t b) {
|
||||
return b;
|
||||
}
|
||||
|
||||
void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
|
||||
void decrypt_pass_kuzn(const uint8_t encrypted_passwords[STORAGE_SIZE][STORAGE_PASS_LEN]) {
|
||||
kuz_key_t key;
|
||||
w128_t x;
|
||||
|
||||
init_dec_pass();
|
||||
|
||||
#ifdef USE_SHA256_KEY
|
||||
SHA256_CTX ctx;
|
||||
sha256_init(&ctx);
|
||||
@@ -69,20 +79,36 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
|
||||
#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);
|
||||
|
||||
for (uint8_t j = 0; j < STORAGE_SIZE; j++) {
|
||||
#ifdef USE_RED_CRY_DEBUG
|
||||
dprintf("decrypted\t=");
|
||||
print_w128(&x);
|
||||
print_chars_w128(&x);
|
||||
#endif
|
||||
for (uint8_t k = 0; k < STORAGE_PASS_LEN / 16; k++) {
|
||||
uint8_t cnt_zeros = 0;
|
||||
for (uint8_t z = 0 + k * 16; z < 16 + k * 16; z++) {
|
||||
if (encrypted_passwords[j][z] == 0x00) {
|
||||
cnt_zeros++;
|
||||
} else {
|
||||
cnt_zeros = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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; i < 16; i++) {
|
||||
dec_pass[j][i] = x.b[i];
|
||||
for (uint8_t i = 0 + k * 16; i < 16 + k * 16; i++) {
|
||||
x.b[i % 16] = encrypted_passwords[j][i];
|
||||
}
|
||||
|
||||
kuz_decrypt_block(&key, &x);
|
||||
|
||||
for (uint8_t i = 0 + k * 16; i < 16 + k * 16; i++) {
|
||||
dec_pass[j][i] = x.b[i % 16];
|
||||
}
|
||||
|
||||
#ifdef USE_RED_CRY_DEBUG
|
||||
print_w128(&x);
|
||||
print_chars_w128(&x);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -100,12 +126,12 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
|
||||
// }
|
||||
|
||||
void send_chars_pass(uint8_t *out) {
|
||||
for (uint8_t i = 0; i < 16 && out[i] != 0; i++) {
|
||||
for (uint8_t i = 0; i < STORAGE_PASS_LEN && out[i] != 0; i++) {
|
||||
send_char((char)out[i]);
|
||||
}
|
||||
};
|
||||
|
||||
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[STORAGE_SIZE][STORAGE_PASS_LEN]) {
|
||||
if (crypto_mode) {
|
||||
switch (keycode) {
|
||||
case RED_CRY_M:
|
||||
@@ -134,6 +160,22 @@ uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const
|
||||
send_chars_pass(dec_pass[1]);
|
||||
}
|
||||
break;
|
||||
case RED_PASS3:
|
||||
if (record->event.pressed) {
|
||||
send_chars_pass(dec_pass[2]);
|
||||
}
|
||||
break;
|
||||
case RED_PASS4:
|
||||
if (record->event.pressed) {
|
||||
send_chars_pass(dec_pass[3]);
|
||||
}
|
||||
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:
|
||||
if (record->event.pressed) {
|
||||
// TODO: change seed
|
||||
|
||||
+25
-3
@@ -25,14 +25,36 @@
|
||||
|
||||
# define MAX_KEY_LEN 128
|
||||
|
||||
# ifndef STORAGE_SIZE
|
||||
# define STORAGE_SIZE 4
|
||||
# endif
|
||||
|
||||
# ifdef STORAGE_PASS_LEN
|
||||
# if STORAGE_PASS_LEN % 16 != 0
|
||||
# error Storage password length must be a multiple of 16
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef STORAGE_PASS_LEN
|
||||
# define STORAGE_PASS_LEN 64
|
||||
# endif
|
||||
|
||||
|
||||
//example for encrypted 64 byte password
|
||||
// const uint8_t red_enc_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},
|
||||
// };
|
||||
|
||||
enum red_crypto_keys {
|
||||
RED_CRY_M = SAFE_RANGE + 0x80, // added safe range offset
|
||||
RED_RNG,
|
||||
RED_TEST,
|
||||
RED_PASS1,
|
||||
RED_PASS2
|
||||
RED_PASS1, RED_PASS2, RED_PASS3, RED_PASS4, RED_PASS5, RED_PASS6, RED_PASS7, RED_PASS8, RED_PASS9, RED_PASS10, RED_PASS11, RED_PASS12
|
||||
};
|
||||
|
||||
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[STORAGE_SIZE][STORAGE_PASS_LEN]);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user