try to expose transcoding key codes to ascii into kc_to_ascii

This commit is contained in:
redlineo committed 2025-01-20 07:15:04 +00:00
1 parent ebc188f265
commit 5684a3747a
6 files changed
+64 -32

No files matched your search

+2 -1
View File
@@ -32,7 +32,8 @@ include keyboards/<keyboard>/<path to your keymap folder>/red_crypto/red_crypto.
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 Cipher`, then choose type `Kuznechik 34.12-2014`, not Magma. Choose mode ECB. Now, there is no CBC or CTR.
> Don't forget IV for GOST, get it from kuznechik_8bit.c. > Don't forget IV for GOST
> ```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.
+29 -8
View File
@@ -1,13 +1,34 @@
// Author: redlineo, romanov.pd@gmail.com
#include "kc_to_ascii.h" #include "kc_to_ascii.h"
void crypto_process_record_user(uint16_t keycode, keyrecord_t *record, uint8_t readed_key) { uint8_t shift_tracker = 0;
switch (keycode) {
case KC_1: uint8_t kc_to_ascii(uint16_t keycode, keyrecord_t *record, uint8_t readed_key[]) {
if (record->event.pressed) { switch (keycode) {
case KC_LEFT_SHIFT:
if (record->event.pressed) {
register_code(KC_LEFT_SHIFT);
shift_tracker = 1;
}
return 1;
break;
case KC_1:
if (record->event.pressed) {
if (shift_tracker == 1) {
unregister_code(KC_LEFT_SHIFT);
shift_tracker = 0;
readed_key[count_char_key] = ASCII_UP_1;
} else {
readed_key[count_char_key] = ASCII_LOW_1; readed_key[count_char_key] = ASCII_LOW_1;
count_char_key++;
} }
break; dprintf("%d",readed_key[count_char_key]);
default: count_char_key++;
break; }
return 1;
break;
default:
break;
}
return 0;
} }
+8
View File
@@ -1,8 +1,16 @@
// Author: redlineo, romanov.pd@gmail.com
#include QMK_KEYBOARD_H
#include "quantum.h"
#ifndef KC_TO_ASCII_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[32]);
/****************************** ASCII TABLE ******************************/ /****************************** ASCII TABLE ******************************/
// clang-format off
#define ASCII_NON_PRINTABLE 0x00 // #define ASCII_NON_PRINTABLE 0x00 //
#define ASCII_SOH 0x01 // #define ASCII_SOH 0x01 //
#define ASCII_STX 0x02 // #define ASCII_STX 0x02 //
+19 -17
View File
@@ -1,7 +1,7 @@
// Author: redlineo, romanov.pd@gmail.com
#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[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 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};
@@ -46,6 +46,11 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
} }
} }
};
// 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); // kuz_set_encrypt_key(&key,readed_key);
// for (uint8_t i=0; i<16; i++) { // for (uint8_t i=0; i<16; i++) {
// x.b[i] = pass[i]; // x.b[i] = pass[i];
@@ -53,7 +58,7 @@ void decrypt_pass_kuzn(const uint8_t encrypted_passwords[2][16]) {
// kuz_encrypt_block(&key,&x); // kuz_encrypt_block(&key,&x);
// printf("encrypted\t="); print_w128(&x); // printf("encrypted\t="); print_w128(&x);
// print_chars_w128(&x); // print_chars_w128(&x);
}; // }
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 < 16 && out[i] != 0; i++) {
@@ -61,26 +66,24 @@ void send_chars_pass(uint8_t *out) {
} }
}; };
void 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) {
// TODO: write all ASCII printable keys
// may be not printable, because we can use any byte of ASCII with QMK, HA-HA
// transcode_keycode_to_ascii();
// case KC_1: // case KC_1:
// if (record->event.pressed) { // if (record->event.pressed) {
// readed_key[count_char_key] = ASCII_LOW_1; // readed_key[count_char_key] = ASCII_LOW_1;
// count_char_key++; // count_char_key++;
// } // }
// return 1;
// break; // break;
case GET_PASS: case RED_CRY_M:
if (record->event.pressed) { if (record->event.pressed) {
crypto_mode = 0; crypto_mode = 0;
count_char_key = 0; count_char_key = 0;
decrypt_pass_kuzn(encrypted_passwords); decrypt_pass_kuzn(encrypted_passwords);
} }
default: default:
kc_to_ascii(keycode, record, &readed_key); return kc_to_ascii(keycode, record, readed_key, count_char_key);
break; break;
} }
} else { } else {
@@ -88,41 +91,40 @@ void crypto_process_record_user(uint16_t keycode, keyrecord_t *record, const uin
case RED_PASS1: case RED_PASS1:
if (record->event.pressed) { if (record->event.pressed) {
send_chars_pass(dec_pass[0]); send_chars_pass(dec_pass[0]);
// SEND_STRING(dec_pass[0]);
} }
break; break;
case RED_PASS2: case RED_PASS2:
if (record->event.pressed) { if (record->event.pressed) {
send_chars_pass(dec_pass[1]); send_chars_pass(dec_pass[1]);
// SEND_STRING(dec_pass[1]);
} }
break; break;
case RED_RNG: case RED_RNG:
if (record->event.pressed) { if (record->event.pressed) {
//TODO: change seed // TODO: change seed
for (uint8_t i = 0; i < 32; i++){ for (uint8_t i = 0; i < 32; i++) {
tap_random_base64(); tap_random_base64();
} }
} }
break; break;
case RED_TEST: case RED_TEST:
#ifdef TEST_FUNCTIONS_ENABLED #ifdef TEST_FUNCTIONS_ENABLED
if (record->event.pressed) { if (record->event.pressed) {
exec_sha256_test(); exec_sha256_test();
exec_kuznechik_test(); exec_kuznechik_test();
exec_aes_test(); exec_aes_test();
} }
#endif #endif
break; break;
case GET_PASS: case RED_CRY_M:
if (record->event.pressed) { if (record->event.pressed) {
crypto_mode = 1; crypto_mode = 1;
for (uint8_t i = 0; i < 32; i++) { for (uint8_t i = 0; i < 32; i++) {
readed_key[i] = 0; readed_key[i] = 0;
} }
dprintf("%d", keycode); // dprintf("%d", keycode);
} }
break; break;
} }
} }
return 0;
} }
+4 -4
View File
@@ -1,4 +1,4 @@
// Author: redlineo, romanov.pd@gmail.com
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
#include "quantum.h" #include "quantum.h"
@@ -7,7 +7,7 @@
#ifndef RED_CRYPTO_H #ifndef RED_CRYPTO_H
#define RED_CRYPTO_H #define RED_CRYPTO_H
#include "ascii_table.c" #include "kc_to_ascii.h"
// #ifdef USE_RED_KUZNECHIK_128 // #ifdef USE_RED_KUZNECHIK_128
// #include "kuznechik_128bit.h" // #include "kuznechik_128bit.h"
@@ -26,14 +26,14 @@
enum red_crypto_keys { enum red_crypto_keys {
GET_PASS = SAFE_RANGE, RED_CRY_M = SAFE_RANGE+0x80, // added safe range offset
RED_PASS1, RED_PASS1,
RED_PASS2, RED_PASS2,
RED_RNG, RED_RNG,
RED_TEST RED_TEST
}; };
void 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
+2 -2
View File
@@ -4,8 +4,8 @@ SRC += red_crypto/red_crypto.c
SRC += red_crypto/sha256.c SRC += red_crypto/sha256.c
SRC += red_crypto/aes.c SRC += red_crypto/aes.c
SRC += red_crypto/kuznechik_8bit.c SRC += red_crypto/kuznechik_8bit.c
SRC += red_crypto/ascii_table.c SRC += red_crypto/kc_to_ascii.c
# SRC += red_crypto/kuznechik_128bit.c # you can't include this, because you may not have ARMv8 and upper, check this # SRC += red_crypto/kuznechik_128bit.c # you can't include this, because you may not have ARMv8 and upper, check this
# TODO: do something like this: # TODO: do something like this:
# ifneq ($(findstring HAL_USE_CRY TRUE,$(HALCONF)),) # ifneq ($(findstring HAL_USE_CRY TRUE,$(HALCONF)),)