diff --git a/README.md b/README.md index 2f7d6ee..41ff247 100644 --- a/README.md +++ b/README.md @@ -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///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 ``` diff --git a/red_crypto.c b/red_crypto.c index 15edd4a..919688a 100644 --- a/red_crypto.c +++ b/red_crypto.c @@ -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); - + 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]; @@ -93,7 +118,7 @@ uint8_t crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const decrypt_pass_kuzn(encrypted_passwords); } default: - //reading key + // reading key return kc_to_ascii(keycode, record, readed_key, &count_char_key); break; } diff --git a/red_crypto.h b/red_crypto.h index ef54510..7939790 100644 --- a/red_crypto.h +++ b/red_crypto.h @@ -14,14 +14,16 @@ # ifdef USE_RED_KUZNECHIK_8 # include "kuznechik_8bit.h" -# include "sha256.h" +# ifdef USE_SHA256_KEY +# include "sha256.h" +# endif # endif # ifdef USE_RED_AES_256 # include "aes.h" # endif -#define MAX_KEY_LEN 128 +# define MAX_KEY_LEN 128 enum red_crypto_keys { RED_CRY_M = SAFE_RANGE + 0x80, // added safe range offset