Skip to content

Commit

Permalink
better keys
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 7, 2023
1 parent 410fe78 commit 473cdf7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions helpers/flipbip_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define FLIPBIP_SETTINGS_PATH_BAK FLIPBIP_APP_BASE_FOLDER "/" FLIPBIP_SETTINGS_FILE_NAME_BAK

const size_t FILE_HLEN = 4;
const size_t FILE_KLEN = 128;
const size_t FILE_KLEN = 256;
const size_t FILE_SLEN = 512;
const char* FILE_HSTR = "fb01";
const char* FILE_K1 = "fb0131d5cf688221c109163908ebe51debb46227c6cc8b37641910833222772a"
Expand Down Expand Up @@ -113,15 +113,15 @@ bool flipbip_load_settings_secure(char* settings) {
data += FILE_HLEN;

// load k2 from file using k1
//uint8_t k1[64];
//uint8_t k1[16] = {0};
//flipbip_xtob(FILE_K1, k1, 64);
uint8_t k2[64];
//flipbip_cipher(k1, data, data, FILE_KLEN);
flipbip_xtob(data, k2, 64);
uint8_t k2[128];
//flipbip_cipher(k1, 16, data, data, FILE_KLEN);
flipbip_xtob(data, k2, 128);
data += FILE_KLEN;

// load settings from file using k2
flipbip_cipher(k2, data, data, FILE_SLEN);
flipbip_cipher(k2, 128, data, data, FILE_SLEN);
flipbip_xtob(data, (unsigned char*)settings, 256);

data = data - FILE_KLEN - FILE_HLEN;
Expand All @@ -142,30 +142,30 @@ bool flipbip_save_settings_secure(const char* settings) {

// allocate memory for data
char *data = malloc(dlen + 1);
memzero(data, dlen + 1);
memzero(data, dlen);

// write header
strncpy(data, FILE_HSTR, FILE_HLEN);
data += FILE_HLEN;

// generate key
//uint8_t k1[64];
//uint8_t k1[16] = {0};
//flipbip_xtob(FILE_K1, k1, 64);
uint8_t k2[64];
random_buffer(k2, 64);
uint8_t k2[128];
random_buffer(k2, 128);

// write k2 to file (secured by k1)
for (size_t i = 0; i < 64; i++) {
for (size_t i = 0; i < 128; i++) {
flipbip_btox(k2[i], data + (i * 2));
}
//flipbip_cipher(k1, data, data, FILE_KLEN);
//flipbip_cipher(k1, 16, data, data, FILE_KLEN);
data += FILE_KLEN;

// write settings to file (secured by k2)
for (size_t i = 0; i < len; i++) {
flipbip_btox(settings[i], data + (i * 2));
}
flipbip_cipher(k2, data, data, FILE_SLEN);
flipbip_cipher(k2, 128, data, data, FILE_SLEN);

data = data - FILE_KLEN - FILE_HLEN;

Expand Down
6 changes: 3 additions & 3 deletions helpers/flipbip_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ flipbip_xtob(const char *str, unsigned char *out, int out_len)
}

void
flipbip_cipher(const unsigned char* key_in, const char* in, char* out, const unsigned int io_len)
flipbip_cipher(const unsigned char* key_in, const unsigned int key_len, const char* in, char* out, const unsigned int io_len)
{
if (io_len > 512) return;

RC4_CTX ctx;
uint8_t buf[256];

memzero(buf, 256);

flipbip_xtob(in, buf, io_len / 2);

rc4_init(&ctx, key_in, 64);
rc4_init(&ctx, key_in, key_len);
rc4_encrypt(&ctx, buf, 256);

for (size_t i = 0; i < (io_len / 2); i++) {
Expand Down
2 changes: 1 addition & 1 deletion helpers/flipbip_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ char * flipbip_strtok_r(char *s, const char *delim, char **last);
void flipbip_btox(const unsigned char i, char *str);
void flipbip_xtob(const char *str, unsigned char *out, int out_len);

void flipbip_cipher(const unsigned char* key_in, const char* in, char* out, const unsigned int io_len);
void flipbip_cipher(const unsigned char* key_in, const unsigned int key_len, const char* in, char* out, const unsigned int io_len);

0 comments on commit 473cdf7

Please sign in to comment.