feat: implement encryption

This commit is contained in:
2026-05-14 16:22:52 +02:00
parent caf67b6e74
commit a0aed7e93b
12 changed files with 336 additions and 37 deletions

61
src/encryptor.c Normal file
View File

@@ -0,0 +1,61 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <aes.h>
#include "hwinfo.h"
#include "util.h"
int main(int argc, char** argv) {
if (argc != 3) {
return 1;
}
char* input = argv[1];
char* output = argv[2];
hw_info_t hwinfo = {0};
if(get_hw_info(&hwinfo) != 0){
return 1;
}
uint8_t* key = hwinfo_to_key(hwinfo);
if(key == NULL) {
return 1;
}
fprintf(stderr, "HWINFO: %s\n", hw_info_flatten(hwinfo));
fprintf(stderr, "Key: ");
for (int i = 0; i < 16; i++)
fprintf(stderr, "%02X", key[i]);
fprintf(stderr, "\n");
struct AES_ctx ctx;
uint8_t nonce[16] = {0};
FILE* license = fopen(input, "rb");
long data_start = ftell(license);
fseek(license, 0, SEEK_END);
int license_size = ftell(license) - data_start;
fseek(license, data_start, SEEK_SET);
uint8_t* buf = malloc(license_size);
fread(buf, 1, license_size, license);
AES_init_ctx(&ctx, key);
AES_init_ctx_iv(&ctx, key, nonce);
AES_CTR_xcrypt_buffer(&ctx, buf, license_size);
FILE* encrypted_license = fopen(output, "wb+");
fwrite(&nonce, 1, sizeof(nonce), encrypted_license);
fwrite(buf, 1, license_size, encrypted_license);
fclose(license);
fclose(encrypted_license);
fprintf(stderr, "Wrote encrypted license file to %s\n", output);
return 0;
}