mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 12:03:55 +01:00
fix: Standardized indention using "indent -linux"
This commit is contained in:
30
src/genkey.c
30
src/genkey.c
@ -1,10 +1,13 @@
|
||||
#include <sodium.h>
|
||||
|
||||
void dump_key_as_c_code(FILE* f, const char * name, unsigned char * key, unsigned int keylen) {
|
||||
void
|
||||
dump_key_as_c_code(FILE * f, const char *name, unsigned char *key,
|
||||
unsigned int keylen)
|
||||
{
|
||||
fprintf(f, "const unsigned char %s[] = { ", name);
|
||||
for(int i=0; i < keylen; i++) {
|
||||
for (int i = 0; i < keylen; i++) {
|
||||
fprintf(f, "0x%02x", key[i]);
|
||||
if (i < keylen-1) {
|
||||
if (i < keylen - 1) {
|
||||
fprintf(f, ", ");
|
||||
}
|
||||
}
|
||||
@ -12,20 +15,23 @@ void dump_key_as_c_code(FILE* f, const char * name, unsigned char * key, unsigne
|
||||
fprintf(f, "const unsigned int %s_length = %d;\n", name, keylen);
|
||||
}
|
||||
|
||||
void write_key_files(const char * filebase, const char * varname, unsigned char * key, unsigned int keylen) {
|
||||
void
|
||||
write_key_files(const char *filebase, const char *varname,
|
||||
unsigned char *key, unsigned int keylen)
|
||||
{
|
||||
char header_filename[4096];
|
||||
char raw_filename[4096];
|
||||
|
||||
sprintf(header_filename, "%s.h", filebase);
|
||||
sprintf(raw_filename, "%s.raw", filebase);
|
||||
sprintf(header_filename, "%s.h", filebase);
|
||||
sprintf(raw_filename, "%s.raw", filebase);
|
||||
|
||||
// open header file
|
||||
FILE *hfile = fopen(header_filename, "w+");
|
||||
if (hfile == NULL) {
|
||||
fprintf(stderr, "Unable to open %s for writing", header_filename);
|
||||
fprintf(stderr, "Unable to open %s for writing",
|
||||
header_filename);
|
||||
exit(129);
|
||||
}
|
||||
|
||||
// write key as C code
|
||||
dump_key_as_c_code(hfile, varname, key, keylen);
|
||||
|
||||
@ -38,7 +44,6 @@ void write_key_files(const char * filebase, const char * varname, unsigned char
|
||||
fprintf(stderr, "Unable to open %s for writing", raw_filename);
|
||||
exit(129);
|
||||
}
|
||||
|
||||
// write key
|
||||
fwrite(key, sizeof(key[0]), keylen, rfile);
|
||||
|
||||
@ -58,9 +63,10 @@ int main(void)
|
||||
unsigned char recipient_sk[crypto_box_SECRETKEYBYTES];
|
||||
crypto_box_keypair(recipient_pk, recipient_sk);
|
||||
|
||||
write_key_files("recipient_pk", "recipient_pk", recipient_pk, crypto_box_PUBLICKEYBYTES);
|
||||
write_key_files("recipient_sk", "recipient_sk", recipient_sk, crypto_box_SECRETKEYBYTES);
|
||||
write_key_files("recipient_pk", "recipient_pk", recipient_pk,
|
||||
crypto_box_PUBLICKEYBYTES);
|
||||
write_key_files("recipient_sk", "recipient_sk", recipient_sk,
|
||||
crypto_box_SECRETKEYBYTES);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user