diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-09 15:02:45 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-09 19:30:50 +0100 |
commit | 406d292107f66a06f8db695645345b13ae8acc8b (patch) | |
tree | 6ef7cf318f973b5026637815b7f56311be88e376 /other/fun/sign.c | |
parent | 769db9dd9a73208d32c22c52c8eef7446e026f81 (diff) |
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
Diffstat (limited to 'other/fun/sign.c')
-rw-r--r-- | other/fun/sign.c | 17 |
1 files changed, 11 insertions, 6 deletions
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 @@ | |||
15 | * | 15 | * |
16 | * NOTE: The signature is appended to the end of the file. | 16 | * NOTE: The signature is appended to the end of the file. |
17 | */ | 17 | */ |
18 | #include "../../testing/misc_tools.c" // hex_string_to_bin | ||
18 | #include <sodium.h> | 19 | #include <sodium.h> |
19 | #include <string.h> | 20 | #include <string.h> |
20 | #include "../../testing/misc_tools.c" // hex_string_to_bin | ||
21 | 21 | ||
22 | int load_file(char *filename, char **result) | 22 | int load_file(char *filename, char **result) |
23 | { | 23 | { |
@@ -73,26 +73,30 @@ int main(int argc, char *argv[]) | |||
73 | char *data; | 73 | char *data; |
74 | int size = load_file(argv[3], &data); | 74 | int size = load_file(argv[3], &data); |
75 | 75 | ||
76 | if (size < 0) | 76 | if (size < 0) { |
77 | goto fail; | 77 | goto fail; |
78 | } | ||
78 | 79 | ||
79 | unsigned long long smlen; | 80 | unsigned long long smlen; |
80 | char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); | 81 | char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); |
81 | crypto_sign_ed25519(sm, &smlen, data, size, secret_key); | 82 | crypto_sign_ed25519(sm, &smlen, data, size, secret_key); |
82 | free(secret_key); | 83 | free(secret_key); |
83 | 84 | ||
84 | if (smlen - size != crypto_sign_ed25519_BYTES) | 85 | if (smlen - size != crypto_sign_ed25519_BYTES) { |
85 | goto fail; | 86 | goto fail; |
87 | } | ||
86 | 88 | ||
87 | FILE *f = fopen(argv[4], "wb"); | 89 | FILE *f = fopen(argv[4], "wb"); |
88 | 90 | ||
89 | if (f == NULL) | 91 | if (f == NULL) { |
90 | goto fail; | 92 | goto fail; |
93 | } | ||
91 | 94 | ||
92 | memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. | 95 | memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. |
93 | 96 | ||
94 | if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) | 97 | if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) { |
95 | goto fail; | 98 | goto fail; |
99 | } | ||
96 | 100 | ||
97 | fclose(f); | 101 | fclose(f); |
98 | printf("Signed successfully.\n"); | 102 | printf("Signed successfully.\n"); |
@@ -103,8 +107,9 @@ int main(int argc, char *argv[]) | |||
103 | char *data; | 107 | char *data; |
104 | int size = load_file(argv[3], &data); | 108 | int size = load_file(argv[3], &data); |
105 | 109 | ||
106 | if (size < 0) | 110 | if (size < 0) { |
107 | goto fail; | 111 | goto fail; |
112 | } | ||
108 | 113 | ||
109 | char *signe = malloc(size + crypto_sign_ed25519_BYTES); | 114 | char *signe = malloc(size + crypto_sign_ed25519_BYTES); |
110 | memcpy(signe, data + size - crypto_sign_ed25519_BYTES, | 115 | memcpy(signe, data + size - crypto_sign_ed25519_BYTES, |