diff options
Diffstat (limited to 'other/fun')
-rw-r--r-- | other/fun/cracker.c | 13 | ||||
-rw-r--r-- | other/fun/sign.c | 17 |
2 files changed, 19 insertions, 11 deletions
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 @@ | |||
13 | #include <time.h> | 13 | #include <time.h> |
14 | 14 | ||
15 | /* NaCl includes*/ | 15 | /* NaCl includes*/ |
16 | #include <crypto_scalarmult_curve25519.h> | 16 | #include <sodium/crypto_scalarmult_curve25519.h> |
17 | #include <randombytes.h> | 17 | #include <sodium/randombytes.h> |
18 | 18 | ||
19 | /* Sodium include*/ | 19 | /* Sodium include*/ |
20 | //#include <sodium.h> | 20 | //#include <sodium.h> |
@@ -42,8 +42,9 @@ int main(int argc, char *argv[]) | |||
42 | unsigned char *key = hex_string_to_bin(argv[1]); | 42 | unsigned char *key = hex_string_to_bin(argv[1]); |
43 | uint8_t pub_key[32], priv_key[32], c_key[32]; | 43 | uint8_t pub_key[32], priv_key[32], c_key[32]; |
44 | 44 | ||
45 | if (len > 32) | 45 | if (len > 32) { |
46 | len = 32; | 46 | len = 32; |
47 | } | ||
47 | 48 | ||
48 | memcpy(c_key, key, len); | 49 | memcpy(c_key, key, len); |
49 | free(key); | 50 | free(key); |
@@ -53,14 +54,16 @@ int main(int argc, char *argv[]) | |||
53 | crypto_scalarmult_curve25519_base(pub_key, priv_key); | 54 | crypto_scalarmult_curve25519_base(pub_key, priv_key); |
54 | uint32_t i; | 55 | uint32_t i; |
55 | 56 | ||
56 | if (memcmp(c_key, pub_key, len) == 0) | 57 | if (memcmp(c_key, pub_key, len) == 0) { |
57 | break; | 58 | break; |
59 | } | ||
58 | 60 | ||
59 | for (i = 32; i != 0; --i) { | 61 | for (i = 32; i != 0; --i) { |
60 | priv_key[i - 1] += 1; | 62 | priv_key[i - 1] += 1; |
61 | 63 | ||
62 | if (priv_key[i - 1] != 0) | 64 | if (priv_key[i - 1] != 0) { |
63 | break; | 65 | break; |
66 | } | ||
64 | } | 67 | } |
65 | 68 | ||
66 | ++num_tries; | 69 | ++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 @@ | |||
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, |