diff options
author | Maxim Biro <nurupo.contributions@gmail.com> | 2014-06-20 23:10:12 -0400 |
---|---|---|
committer | Maxim Biro <nurupo.contributions@gmail.com> | 2014-06-20 23:10:12 -0400 |
commit | 2037d272106f625382d0c1cd2dd74acf2838db90 (patch) | |
tree | bebe4a7aa991b7b9e004af5d8d99f4b014d4d4da /other/fun | |
parent | b85f192b795b0c79800b1f578da6d7dccd68e1b5 (diff) |
Fixed a case when public key contained null bytes
Diffstat (limited to 'other/fun')
-rw-r--r-- | other/fun/strkey.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/other/fun/strkey.c b/other/fun/strkey.c index fd1caa87..7e5a1e1c 100644 --- a/other/fun/strkey.c +++ b/other/fun/strkey.c | |||
@@ -57,11 +57,11 @@ void print_key(unsigned char *key) | |||
57 | 57 | ||
58 | int main(int argc, char *argv[]) | 58 | int main(int argc, char *argv[]) |
59 | { | 59 | { |
60 | unsigned char public_key[crypto_box_PUBLICKEYBYTES + 1]; // null terminator | 60 | unsigned char public_key[crypto_box_PUBLICKEYBYTES]; // null terminator |
61 | unsigned char secret_key[crypto_box_SECRETKEYBYTES]; | 61 | unsigned char secret_key[crypto_box_SECRETKEYBYTES]; |
62 | int offset = 0; | 62 | int offset = 0; |
63 | size_t len; | 63 | size_t len; |
64 | unsigned char desired_bin[crypto_box_PUBLICKEYBYTES + 1]; // null terminator | 64 | unsigned char desired_bin[crypto_box_PUBLICKEYBYTES]; // null terminator |
65 | 65 | ||
66 | if (argc == 3) { | 66 | if (argc == 3) { |
67 | offset = atoi(argv[1]); | 67 | offset = atoi(argv[1]); |
@@ -89,23 +89,30 @@ int main(int argc, char *argv[]) | |||
89 | exit(1); | 89 | exit(1); |
90 | } | 90 | } |
91 | 91 | ||
92 | desired_bin[len/2] = '\0'; | 92 | len /= 2; |
93 | public_key[crypto_box_PUBLICKEYBYTES + 1] = '\0'; | ||
94 | 93 | ||
95 | #ifdef PRINT_TRIES_COUNT | 94 | #ifdef PRINT_TRIES_COUNT |
96 | long long unsigned int tries = 0; | 95 | long long unsigned int tries = 0; |
97 | #endif | 96 | #endif |
98 | 97 | ||
99 | if (offset < 0) { | 98 | if (offset < 0) { |
99 | int found = 0; | ||
100 | do { | 100 | do { |
101 | #ifdef PRINT_TRIES_COUNT | 101 | #ifdef PRINT_TRIES_COUNT |
102 | tries ++; | 102 | tries ++; |
103 | #endif | 103 | #endif |
104 | crypto_box_keypair(public_key, secret_key); | 104 | crypto_box_keypair(public_key, secret_key); |
105 | } while (strstr(public_key, desired_bin) == 0); | 105 | int i; |
106 | for (i = 0; i <= crypto_box_PUBLICKEYBYTES - len; i ++) { | ||
107 | if (memcmp(public_key + i, desired_bin, len) == 0) { | ||
108 | found = 1; | ||
109 | break; | ||
110 | } | ||
111 | } | ||
112 | } while (!found); | ||
106 | } else { | 113 | } else { |
107 | unsigned char *p = public_key + offset; | 114 | unsigned char *p = public_key + offset; |
108 | len /= 2; | 115 | |
109 | do { | 116 | do { |
110 | #ifdef PRINT_TRIES_COUNT | 117 | #ifdef PRINT_TRIES_COUNT |
111 | tries ++; | 118 | tries ++; |
@@ -127,4 +134,4 @@ int main(int argc, char *argv[]) | |||
127 | #endif | 134 | #endif |
128 | 135 | ||
129 | return 0; | 136 | return 0; |
130 | } \ No newline at end of file | 137 | } |