From 406d292107f66a06f8db695645345b13ae8acc8b Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 9 Sep 2016 15:02:45 +0100 Subject: Minor cleanups: header reordering, adding {}. I hadn't done this for the "fun" code, yet. Also, we should include system headers after our own headers. "In general, a module should be implemented by one or more .cpp files. Each of these .cpp files should include the header that defines their interface first. This ensures that all of the dependences of the module header have been properly added to the module header itself, and are not implicit. System headers should be included after user headers for a translation unit." -- http://llvm.org/docs/CodingStandards.html#a-public-header-file-is-a-module --- other/fun/cracker.c | 13 ++++++++----- other/fun/sign.c | 17 +++++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'other/fun') diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 843b9359..7b020bb7 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c @@ -13,8 +13,8 @@ #include /* NaCl includes*/ -#include -#include +#include +#include /* Sodium include*/ //#include @@ -42,8 +42,9 @@ int main(int argc, char *argv[]) unsigned char *key = hex_string_to_bin(argv[1]); uint8_t pub_key[32], priv_key[32], c_key[32]; - if (len > 32) + if (len > 32) { len = 32; + } memcpy(c_key, key, len); free(key); @@ -53,14 +54,16 @@ int main(int argc, char *argv[]) crypto_scalarmult_curve25519_base(pub_key, priv_key); uint32_t i; - if (memcmp(c_key, pub_key, len) == 0) + if (memcmp(c_key, pub_key, len) == 0) { break; + } for (i = 32; i != 0; --i) { priv_key[i - 1] += 1; - if (priv_key[i - 1] != 0) + if (priv_key[i - 1] != 0) { break; + } } ++num_tries; diff --git a/other/fun/sign.c b/other/fun/sign.c index 56a9d1e2..0cd8f38e 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -15,9 +15,9 @@ * * NOTE: The signature is appended to the end of the file. */ +#include "../../testing/misc_tools.c" // hex_string_to_bin #include #include -#include "../../testing/misc_tools.c" // hex_string_to_bin int load_file(char *filename, char **result) { @@ -73,26 +73,30 @@ int main(int argc, char *argv[]) char *data; int size = load_file(argv[3], &data); - if (size < 0) + if (size < 0) { goto fail; + } unsigned long long smlen; char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); crypto_sign_ed25519(sm, &smlen, data, size, secret_key); free(secret_key); - if (smlen - size != crypto_sign_ed25519_BYTES) + if (smlen - size != crypto_sign_ed25519_BYTES) { goto fail; + } FILE *f = fopen(argv[4], "wb"); - if (f == NULL) + if (f == NULL) { goto fail; + } memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. - if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) + if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) { goto fail; + } fclose(f); printf("Signed successfully.\n"); @@ -103,8 +107,9 @@ int main(int argc, char *argv[]) char *data; int size = load_file(argv[3], &data); - if (size < 0) + if (size < 0) { goto fail; + } char *signe = malloc(size + crypto_sign_ed25519_BYTES); memcpy(signe, data + size - crypto_sign_ed25519_BYTES, -- cgit v1.2.3