diff options
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, |