expanded storage size and password length
This commit is contained in:
1 parent
c615c136b1
commit
6d8cbd1277
3 files changed
+95
-18
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
# RED_CRYPTO ver 0.4.0
|
# RED_CRYPTO ver 0.5.0
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ 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 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
|
```c
|
||||||
#define USE_KUZNECHIK_8
|
#define USE_KUZNECHIK_8
|
||||||
@@ -46,6 +46,13 @@ If you want use SHA256 of your key to encrypt passwords, define this in `config.
|
|||||||
#define USE_SHA256_KEY
|
#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`.
|
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?
|
||||||
|
|||||||
+61
-13
@@ -2,7 +2,27 @@
|
|||||||
|
|
||||||
#include "red_crypto.h"
|
#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] = {
|
||||||
|
{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},
|
||||||
|
|
||||||
|
{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},
|
||||||
|
|
||||||
|
{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},
|
||||||
|
|
||||||
|
{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},
|
||||||
|
};
|
||||||
|
|
||||||
// you can use key any length with SHA256, kuznechik use only 32byte
|
// you can use key any length with SHA256, kuznechik use only 32byte
|
||||||
#ifdef USE_SHA256_KEY
|
#ifdef USE_SHA256_KEY
|
||||||
@@ -12,6 +32,8 @@ uint8_t readed_key[128] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|||||||
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};
|
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
|
#endif
|
||||||
|
|
||||||
|
const uint8_t test_pass_block[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
uint8_t count_char_key = 0;
|
uint8_t count_char_key = 0;
|
||||||
|
|
||||||
uint8_t crypto_mode = 0;
|
uint8_t crypto_mode = 0;
|
||||||
@@ -53,7 +75,7 @@ size_t min_len(size_t a, size_t b) {
|
|||||||
return 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;
|
kuz_key_t key;
|
||||||
w128_t x;
|
w128_t x;
|
||||||
|
|
||||||
@@ -69,20 +91,36 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
|
|||||||
#ifndef USE_SHA256_KEY
|
#ifndef USE_SHA256_KEY
|
||||||
kuz_set_decrypt_key(&key, readed_key);
|
kuz_set_decrypt_key(&key, readed_key);
|
||||||
#endif
|
#endif
|
||||||
for (uint8_t j = 0; j < 2; j++) {
|
for (uint8_t j = 0; j < STORAGE_SIZE; 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
|
#ifdef USE_RED_CRY_DEBUG
|
||||||
dprintf("decrypted\t=");
|
dprintf("decrypted\t=");
|
||||||
|
#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 + 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_w128(&x);
|
||||||
print_chars_w128(&x);
|
print_chars_w128(&x);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 16; i++) {
|
|
||||||
dec_pass[j][i] = x.b[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -100,12 +138,12 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
void send_chars_pass(uint8_t *out) {
|
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]);
|
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) {
|
if (crypto_mode) {
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case RED_CRY_M:
|
case RED_CRY_M:
|
||||||
@@ -134,6 +172,16 @@ uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const
|
|||||||
send_chars_pass(dec_pass[1]);
|
send_chars_pass(dec_pass[1]);
|
||||||
}
|
}
|
||||||
break;
|
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;
|
||||||
case RED_RNG:
|
case RED_RNG:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
// TODO: change seed
|
// TODO: change seed
|
||||||
|
|||||||
+25
-3
@@ -25,14 +25,36 @@
|
|||||||
|
|
||||||
# define MAX_KEY_LEN 128
|
# 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 {
|
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_RNG,
|
RED_RNG,
|
||||||
RED_TEST,
|
RED_TEST,
|
||||||
RED_PASS1,
|
RED_PASS1, RED_PASS2, RED_PASS3, RED_PASS4, RED_PASS5, RED_PASS6, RED_PASS7, RED_PASS8, RED_PASS9, RED_PASS10, RED_PASS11, RED_PASS12
|
||||||
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[STORAGE_SIZE][STORAGE_PASS_LEN]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user