@@ -113,24 +113,53 @@ static void gen_keys(secp256k1_context *ctx,
113113 memcpy (pubkey , tmp + 1 , sizeof (* pubkey ));
114114}
115115
116- int main (int argc , char * argv [] )
116+ void print_keypair (int pub , int priv )
117117{
118118 secp256k1_context * ctx ;
119119 struct seckey seckey ;
120120 struct onion_pubkey pubkey ;
121121 char sechex [hex_str_size (sizeof (seckey ))];
122122 char pubhex [hex_str_size (sizeof (pubkey ))];
123123
124- if (argv [1 ])
125- srandom (atoi (argv [1 ]));
126- else
127- srandom (time (NULL ) + getpid ());
124+ assert (pub || priv );
128125
129126 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN );
130127 gen_keys (ctx , & seckey , & pubkey );
131128
132129 hex_encode (& seckey , sizeof (seckey ), sechex , sizeof (sechex ));
133130 hex_encode (& pubkey , sizeof (pubkey ), pubhex , sizeof (pubhex ));
134- printf ("%s:%s\n" , sechex , pubhex );
131+
132+ if (pub && priv ) {
133+ printf ("%s:%s\n" , sechex , pubhex );
134+ } else {
135+ printf ("%s\n" , (priv ? sechex : pubhex ));
136+ }
137+ }
138+
139+ int main (int argc , char * argv [])
140+ {
141+ int pub = 1 , priv = 1 ;
142+
143+ if (argc >= 1 ) {
144+ if (strcmp (argv [1 ], "--pub" ) == 0 ) {
145+ pub = 1 ; priv = 0 ;
146+ argc -- ; argv ++ ;
147+ } else if (strcmp (argv [1 ], "--priv" ) == 0 ) {
148+ pub = 0 ; priv = 1 ;
149+ argc -- ; argv ++ ;
150+ }
151+ }
152+
153+ if (argc <= 1 ) {
154+ srandom (time (NULL ) + getpid ());
155+ print_keypair (pub , priv );
156+ } else {
157+ int i ;
158+ for (i = 1 ; i < argc ; i ++ ) {
159+ srandom (atoi (argv [i ]));
160+ print_keypair (pub , priv );
161+ }
162+ }
163+
135164 return 0 ;
136165}
0 commit comments