-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeygen.c
More file actions
23 lines (20 loc) · 911 Bytes
/
keygen.c
File metadata and controls
23 lines (20 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "keygen.h"
// Random master key generator
// void generate_master_key(char *master_key) {
// const char charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// srand(time(NULL));
// for (int i = 0; i < MASTER_KEY_LEN; i++) {
// master_key[i] = charset[rand() % (sizeof(charset) - 1)];
// }
// master_key[MASTER_KEY_LEN] = '\0';
// }
// Simple key derivation - just split the master key in half
// First 16 bytes = encryption key, Last 16 bytes = hash key
void derive_keys(const char *master_key, char *enc_key, char *hash_key) {
// Copy first 16 bytes to encryption key
memcpy(enc_key, master_key, DERIVED_KEY_LEN);
enc_key[DERIVED_KEY_LEN] = '\0'; // Null terminate
// Copy last 16 bytes to hash key
memcpy(hash_key, master_key + DERIVED_KEY_LEN, DERIVED_KEY_LEN);
hash_key[DERIVED_KEY_LEN] = '\0'; // Null terminate
}