File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,11 @@ void print_key(unsigned char *key)
57
57
58
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
61
unsigned char secret_key [crypto_box_SECRETKEYBYTES ];
62
62
int offset = 0 ;
63
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
66
if (argc == 3 ) {
67
67
offset = atoi (argv [1 ]);
@@ -89,23 +89,30 @@ int main(int argc, char *argv[])
89
89
exit (1 );
90
90
}
91
91
92
- desired_bin [len /2 ] = '\0' ;
93
- public_key [crypto_box_PUBLICKEYBYTES + 1 ] = '\0' ;
92
+ len /= 2 ;
94
93
95
94
#ifdef PRINT_TRIES_COUNT
96
95
long long unsigned int tries = 0 ;
97
96
#endif
98
97
99
98
if (offset < 0 ) {
99
+ int found = 0 ;
100
100
do {
101
101
#ifdef PRINT_TRIES_COUNT
102
- tries ++ ;
102
+ tries ++ ;
103
103
#endif
104
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
113
} else {
107
- unsigned char * p = public_key + offset ;
108
- len /= 2 ;
114
+ unsigned char * p = public_key + offset ;
115
+
109
116
do {
110
117
#ifdef PRINT_TRIES_COUNT
111
118
tries ++ ;
@@ -127,4 +134,4 @@ int main(int argc, char *argv[])
127
134
#endif
128
135
129
136
return 0 ;
130
- }
137
+ }
You can’t perform that action at this time.
0 commit comments