mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 08:33:56 +01:00
fix: Standardized indention using "indent -linux"
This commit is contained in:
22
src/genkey.c
22
src/genkey.c
@ -1,6 +1,9 @@
|
||||
#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++) {
|
||||
fprintf(f, "0x%02x", key[i]);
|
||||
@ -12,7 +15,10 @@ 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];
|
||||
|
||||
@ -22,10 +28,10 @@ void write_key_files(const char * filebase, const char * varname, unsigned char
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,8 @@
|
||||
/*
|
||||
* Encrypt first argument with fixed public key from recipient_pk.h
|
||||
*/
|
||||
int sodium_crypto_box_seal_kit(uschar **yield, int argc, uschar *argv[]) {
|
||||
int sodium_crypto_box_seal_kit(uschar ** yield, int argc, uschar * argv[])
|
||||
{
|
||||
size_t messagelen;
|
||||
unsigned char *message;
|
||||
|
||||
@ -21,10 +22,11 @@ int sodium_crypto_box_seal_kit(uschar **yield, int argc, uschar *argv[]) {
|
||||
return ERROR;
|
||||
}
|
||||
if (argc != 1) {
|
||||
*yield = string_sprintf("Wrong number of arguments (got %i, expected 1)", argc);
|
||||
*yield =
|
||||
string_sprintf
|
||||
("Wrong number of arguments (got %i, expected 1)", argc);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
// get cleartext message
|
||||
message = argv[0];
|
||||
messagelen = strlen((const char *)message);
|
||||
@ -38,7 +40,9 @@ int sodium_crypto_box_seal_kit(uschar **yield, int argc, uschar *argv[]) {
|
||||
crypto_box_seal(ciphertext, message, messagelen, recipient_pk);
|
||||
|
||||
// base64-encode the ciphertext
|
||||
unsigned int outputsize = sodium_base64_ENCODED_LEN(cipherlen, sodium_base64_VARIANT_ORIGINAL);
|
||||
unsigned int outputsize =
|
||||
sodium_base64_ENCODED_LEN(cipherlen,
|
||||
sodium_base64_VARIANT_ORIGINAL);
|
||||
unsigned char *outstring = malloc(outputsize);
|
||||
sodium_memzero(outstring, outputsize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user