mirror of
https://gitlab.kit.edu/kit/scc/sys/mail/exim-encrypt-dlfunc.git
synced 2025-12-06 10:03: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>
|
#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);
|
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]);
|
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);
|
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 header_filename[4096];
|
||||||
char raw_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
|
// open header file
|
||||||
FILE *hfile = fopen(header_filename, "w+");
|
FILE *hfile = fopen(header_filename, "w+");
|
||||||
if (hfile == NULL) {
|
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);
|
exit(129);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write key as C code
|
// write key as C code
|
||||||
dump_key_as_c_code(hfile, varname, key, keylen);
|
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);
|
fprintf(stderr, "Unable to open %s for writing", raw_filename);
|
||||||
exit(129);
|
exit(129);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write key
|
// write key
|
||||||
fwrite(key, sizeof(key[0]), keylen, rfile);
|
fwrite(key, sizeof(key[0]), keylen, rfile);
|
||||||
|
|
||||||
@ -58,9 +63,10 @@ int main(void)
|
|||||||
unsigned char recipient_sk[crypto_box_SECRETKEYBYTES];
|
unsigned char recipient_sk[crypto_box_SECRETKEYBYTES];
|
||||||
crypto_box_keypair(recipient_pk, recipient_sk);
|
crypto_box_keypair(recipient_pk, recipient_sk);
|
||||||
|
|
||||||
write_key_files("recipient_pk", "recipient_pk", recipient_pk, crypto_box_PUBLICKEYBYTES);
|
write_key_files("recipient_pk", "recipient_pk", recipient_pk,
|
||||||
write_key_files("recipient_sk", "recipient_sk", recipient_sk, crypto_box_SECRETKEYBYTES);
|
crypto_box_PUBLICKEYBYTES);
|
||||||
|
write_key_files("recipient_sk", "recipient_sk", recipient_sk,
|
||||||
|
crypto_box_SECRETKEYBYTES);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,8 @@
|
|||||||
/*
|
/*
|
||||||
* Encrypt first argument with fixed public key from recipient_pk.h
|
* 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;
|
size_t messagelen;
|
||||||
unsigned char *message;
|
unsigned char *message;
|
||||||
|
|
||||||
@ -21,10 +22,11 @@ int sodium_crypto_box_seal_kit(uschar **yield, int argc, uschar *argv[]) {
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
if (argc != 1) {
|
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;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get cleartext message
|
// get cleartext message
|
||||||
message = argv[0];
|
message = argv[0];
|
||||||
messagelen = strlen((const char *)message);
|
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);
|
crypto_box_seal(ciphertext, message, messagelen, recipient_pk);
|
||||||
|
|
||||||
// base64-encode the ciphertext
|
// 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);
|
unsigned char *outstring = malloc(outputsize);
|
||||||
sodium_memzero(outstring, outputsize);
|
sodium_memzero(outstring, outputsize);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user