]> andersk Git - openssh.git/blobdiff - key.c
- itojun@cvs.openbsd.org 2002/05/13 02:37:39
[openssh.git] / key.c
diff --git a/key.c b/key.c
index d1355e871f5d15e92f404a5ee6ba36f2c0484771..1ce0a87a33bdedf23aebb915ec3307fd2c7e25fe 100644 (file)
--- a/key.c
+++ b/key.c
@@ -32,7 +32,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: key.c,v 1.40 2002/02/24 19:14:59 markus Exp $");
+RCSID("$OpenBSD: key.c,v 1.43 2002/03/19 10:49:35 markus Exp $");
 
 #include <openssl/evp.h>
 
@@ -172,7 +172,7 @@ key_equal(Key *a, Key *b)
 static u_char*
 key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length)
 {
-       EVP_MD *md = NULL;
+       const EVP_MD *md = NULL;
        EVP_MD_CTX ctx;
        u_char *blob = NULL;
        u_char *retval = NULL;
@@ -801,3 +801,46 @@ key_verify(
                break;
        }
 }
+
+/* Converts a private to a public key */
+
+Key *
+key_demote(Key *k)
+{
+       Key *pk;
+
+       pk = xmalloc(sizeof(*pk));
+       pk->type = k->type;
+       pk->flags = k->flags;
+       pk->dsa = NULL;
+       pk->rsa = NULL;
+
+       switch (k->type) {
+       case KEY_RSA1:
+       case KEY_RSA:
+               if ((pk->rsa = RSA_new()) == NULL)
+                       fatal("key_demote: RSA_new failed");
+               if ((pk->rsa->e = BN_dup(k->rsa->e)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->rsa->n = BN_dup(k->rsa->n)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               break;
+       case KEY_DSA:
+               if ((pk->dsa = DSA_new()) == NULL)
+                       fatal("key_demote: DSA_new failed");
+               if ((pk->dsa->p = BN_dup(k->dsa->p)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->dsa->q = BN_dup(k->dsa->q)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->dsa->g = BN_dup(k->dsa->g)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               if ((pk->dsa->pub_key = BN_dup(k->dsa->pub_key)) == NULL)
+                       fatal("key_demote: BN_dup failed");
+               break;
+       default:
+               fatal("key_free: bad key type %d", k->type);
+               break;
+       }
+
+       return (pk);
+}
This page took 0.035744 seconds and 4 git commands to generate.