tools: sxtkeygen API changed;

master
Alexander Vdolainen 9 years ago
parent f6a7cd34c0
commit bab197862c

@ -36,6 +36,7 @@
#include <termios.h> #include <termios.h>
#include <sxt/errno.h> #include <sxt/errno.h>
#include <sxt/rdb.h>
#include <sxt/sxtkey.h> #include <sxt/sxtkey.h>
#include <sxt/sxt.h> #include <sxt/sxt.h>
@ -166,10 +167,10 @@ int main(int argc, char **argv)
} }
/* check type */ /* check type */
if(keytype) type = sxt_key_type_fname(keytype); if(keytype) type = sxtkey_type_fname(keytype);
else type = PPKP_ED25519; else type = PPKP_ED25519;
keytype = (char *)sxt_key_name(type); keytype = (char *)sxtkey_name(type);
if(!type) { if(!type) {
fprintf(stderr, "Illegal keytype.\nAborting.\n"); fprintf(stderr, "Illegal keytype.\nAborting.\n");
@ -228,64 +229,64 @@ int main(int argc, char **argv)
} }
/* generate a key first */ /* generate a key first */
if(!(pair = sxt_key_alloc())) { if(!(pair = sxtkey_alloc())) {
fprintf(stderr, "Not enough memory to allocate a key.\nAborting.\n"); fprintf(stderr, "Not enough memory to allocate a key.\nAborting.\n");
abort(); abort();
} }
fprintf(stdout, "Generating key pair ..."); fprintf(stdout, "Generating key pair ...");
if((r = sxt_key_generate(pair, type, 0)) != SXT_SUCCESS) { if((r = sxtkey_generate(pair, type, 0)) != SXT_SUCCESS) {
fprintf(stderr, "FAIL.\nError (%d).\nAborting.\n", r); fprintf(stderr, "FAIL.\nError (%d).\nAborting.\n", r);
sxt_key_free(pair); sxtkey_free(pair);
abort(); abort();
} else fprintf(stdout, "DONE.\n"); } else fprintf(stdout, "DONE.\n");
/* hash */ /* hash */
if(hash) sxt_key_assign_hash(pair, hash); if(hash) sxtkey_assign_hash(pair, hash);
/* duplicate private */ /* duplicate private */
if((r = sxt_key_dup_private(pair, &privkey)) != SXT_SUCCESS) { if((r = sxtkey_dup_private(pair, &privkey)) != SXT_SUCCESS) {
fprintf(stderr, "Unable to duplicate private key(%d).\nAborting.\n", r); fprintf(stderr, "Unable to duplicate private key(%d).\nAborting.\n", r);
sxt_key_free(pair); sxtkey_free(pair);
abort(); abort();
} }
/* get public duplicate */ /* get public duplicate */
if((r = sxt_key_dup_public(pair, &pubkey)) != SXT_SUCCESS) { if((r = sxtkey_dup_public(pair, &pubkey)) != SXT_SUCCESS) {
fprintf(stderr, "Unable to duplicate public key(%d).\nAborting.\n", r); fprintf(stderr, "Unable to duplicate public key(%d).\nAborting.\n", r);
sxt_key_free(pair); sxtkey_free(pair);
sxt_key_free(privkey); sxtkey_free(privkey);
abort(); abort();
} }
/* ok, output private key first */ /* ok, output private key first */
snprintf(fullpath, MAX_PATHNAME, "%s/%s", dir, privname); snprintf(fullpath, MAX_PATHNAME, "%s/%s", dir, privname);
if(!encrypt) { /* will not encrypt */ if(!encrypt) { /* will not encrypt */
r = sxt_key_export_priv_file(privkey, fullpath, NULL, NULL, NULL); r = sxtkey_export_priv_file(privkey, fullpath, NULL, NULL, NULL);
} else { } else {
r = sxt_key_export_priv_file(privkey, fullpath, NULL, __passkey_promt, r = sxtkey_export_priv_file(privkey, fullpath, NULL, __passkey_promt,
(void *)"Enter passkey phrase:"); (void *)"Enter passkey phrase:");
} }
if(r != SXT_SUCCESS) { if(r != SXT_SUCCESS) {
__failed_export: __failed_export:
fprintf(stderr, "Unable to perform key export (%d).\nAborting.\n", r); fprintf(stderr, "Unable to perform key export (%d).\nAborting.\n", r);
sxt_key_burn(pair); sxtkey_burn(pair);
sxt_key_burn(privkey); sxtkey_burn(privkey);
sxt_key_free(pair); sxtkey_free(pair);
sxt_key_free(privkey); sxtkey_free(privkey);
abort(); abort();
} }
/* ok, output public key */ /* ok, output public key */
snprintf(fullpath, MAX_PATHNAME, "%s/%s", dir, pubname); snprintf(fullpath, MAX_PATHNAME, "%s/%s", dir, pubname);
r = sxt_key_export_public_file(pubkey, fullpath); r = sxtkey_export_public_file(pubkey, fullpath);
if(r != SXT_SUCCESS) goto __failed_export; if(r != SXT_SUCCESS) goto __failed_export;
sxt_key_burn(pair); sxtkey_burn(pair);
sxt_key_burn(privkey); sxtkey_burn(privkey);
sxt_key_burn(pubkey); sxtkey_burn(pubkey);
sxt_key_free(pair); sxtkey_free(pair);
sxt_key_free(privkey); sxtkey_free(privkey);
sxt_key_free(pubkey); sxtkey_free(pubkey);
return 0; return 0;
} }

Loading…
Cancel
Save