comparison keyimport.c @ 299:740e782679be ucc-axis-hack

Various changes to compile+kind of run on UCC's axis board. Note that fprintf(stdin -> printf( accounts for many of the changes
author Matt Johnston <matt@ucc.asn.au>
date Sat, 25 Mar 2006 12:57:09 +0000
parents ac890087b8c1
children
comparison
equal deleted inserted replaced
266:e37b160c414c 299:740e782679be
481 } 481 }
482 memset(&ret, 0, sizeof(ret)); 482 memset(&ret, 0, sizeof(ret));
483 m_free(ret); 483 m_free(ret);
484 } 484 }
485 if (errmsg) { 485 if (errmsg) {
486 fprintf(stderr, "Error: %s\n", errmsg); 486 printf( "Error: %s\n", errmsg);
487 } 487 }
488 return NULL; 488 return NULL;
489 } 489 }
490 490
491 static int openssh_encrypted(const char *filename) 491 static int openssh_encrypted(const char *filename)
680 m_burn(key->keyblob, key->keyblob_size); 680 m_burn(key->keyblob, key->keyblob_size);
681 m_free(key->keyblob); 681 m_free(key->keyblob);
682 m_burn(key, sizeof(key)); 682 m_burn(key, sizeof(key));
683 m_free(key); 683 m_free(key);
684 if (errmsg) { 684 if (errmsg) {
685 fprintf(stderr, "Error: %s\n", errmsg); 685 printf( "Error: %s\n", errmsg);
686 } 686 }
687 return retval; 687 return retval;
688 } 688 }
689 689
690 static int openssh_write(const char *filename, sign_key *key, 690 static int openssh_write(const char *filename, sign_key *key,
736 736
737 #ifdef DROPBEAR_RSA 737 #ifdef DROPBEAR_RSA
738 if (keytype == DROPBEAR_SIGNKEY_RSA) { 738 if (keytype == DROPBEAR_SIGNKEY_RSA) {
739 739
740 if (key->rsakey->p == NULL || key->rsakey->q == NULL) { 740 if (key->rsakey->p == NULL || key->rsakey->q == NULL) {
741 fprintf(stderr, "Pre-0.33 Dropbear keys cannot be converted to OpenSSH keys.\n"); 741 printf( "Pre-0.33 Dropbear keys cannot be converted to OpenSSH keys.\n");
742 goto error; 742 goto error;
743 } 743 }
744 744
745 /* e */ 745 /* e */
746 numbers[2].bytes = buf_getint(keyblob); 746 numbers[2].bytes = buf_getint(keyblob);
773 m_mp_init(&dmq1); 773 m_mp_init(&dmq1);
774 m_mp_init(&iqmp); 774 m_mp_init(&iqmp);
775 775
776 /* dmp1 = d mod (p-1) */ 776 /* dmp1 = d mod (p-1) */
777 if (mp_sub_d(key->rsakey->p, 1, &tmpval) != MP_OKAY) { 777 if (mp_sub_d(key->rsakey->p, 1, &tmpval) != MP_OKAY) {
778 fprintf(stderr, "Bignum error for p-1\n"); 778 printf( "Bignum error for p-1\n");
779 goto error; 779 goto error;
780 } 780 }
781 if (mp_mod(key->rsakey->d, &tmpval, &dmp1) != MP_OKAY) { 781 if (mp_mod(key->rsakey->d, &tmpval, &dmp1) != MP_OKAY) {
782 fprintf(stderr, "Bignum error for dmp1\n"); 782 printf( "Bignum error for dmp1\n");
783 goto error; 783 goto error;
784 } 784 }
785 785
786 /* dmq1 = d mod (q-1) */ 786 /* dmq1 = d mod (q-1) */
787 if (mp_sub_d(key->rsakey->q, 1, &tmpval) != MP_OKAY) { 787 if (mp_sub_d(key->rsakey->q, 1, &tmpval) != MP_OKAY) {
788 fprintf(stderr, "Bignum error for q-1\n"); 788 printf( "Bignum error for q-1\n");
789 goto error; 789 goto error;
790 } 790 }
791 if (mp_mod(key->rsakey->d, &tmpval, &dmq1) != MP_OKAY) { 791 if (mp_mod(key->rsakey->d, &tmpval, &dmq1) != MP_OKAY) {
792 fprintf(stderr, "Bignum error for dmq1\n"); 792 printf( "Bignum error for dmq1\n");
793 goto error; 793 goto error;
794 } 794 }
795 795
796 /* iqmp = (q^-1) mod p */ 796 /* iqmp = (q^-1) mod p */
797 if (mp_invmod(key->rsakey->q, key->rsakey->p, &iqmp) != MP_OKAY) { 797 if (mp_invmod(key->rsakey->q, key->rsakey->p, &iqmp) != MP_OKAY) {
798 fprintf(stderr, "Bignum error for iqmp\n"); 798 printf( "Bignum error for iqmp\n");
799 goto error; 799 goto error;
800 } 800 }
801 801
802 extrablob = buf_new(2000); 802 extrablob = buf_new(2000);
803 buf_putmpint(extrablob, &dmp1); 803 buf_putmpint(extrablob, &dmp1);
922 922
923 /* 923 /*
924 * Encrypt the key. 924 * Encrypt the key.
925 */ 925 */
926 if (passphrase) { 926 if (passphrase) {
927 fprintf(stderr, "Encrypted keys aren't supported currently\n"); 927 printf( "Encrypted keys aren't supported currently\n");
928 goto error; 928 goto error;
929 #if 0 929 #if 0
930 /* 930 /*
931 * Invent an iv. Then derive encryption key from passphrase 931 * Invent an iv. Then derive encryption key from passphrase
932 * and iv/salt: 932 * and iv/salt:
970 fp = stdout; 970 fp = stdout;
971 } else { 971 } else {
972 fp = fopen(filename, "wb"); /* ensure Unix line endings */ 972 fp = fopen(filename, "wb"); /* ensure Unix line endings */
973 } 973 }
974 if (!fp) { 974 if (!fp) {
975 fprintf(stderr, "Failed opening output file\n"); 975 printf( "Failed opening output file\n");
976 goto error; 976 goto error;
977 } 977 }
978 fputs(header, fp); 978 fputs(header, fp);
979 if (passphrase) { 979 if (passphrase) {
980 fprintf(fp, "Proc-Type: 4,ENCRYPTED\nDEK-Info: DES-EDE3-CBC,"); 980 fprintf(fp, "Proc-Type: 4,ENCRYPTED\nDEK-Info: DES-EDE3-CBC,");