]> andersk Git - openssh.git/blobdiff - key.c
- deraadt@cvs.openbsd.org 2002/06/23 03:30:58
[openssh.git] / key.c
diff --git a/key.c b/key.c
index cda91571affd8c4168746459d2a8139cd29ae34c..fb1f8410a19000be4f34c688cf98dc68684e8b8d 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.41 2002/02/28 15:46:33 markus Exp $");
+RCSID("$OpenBSD: key.c,v 1.45 2002/06/23 03:26:19 deraadt Exp $");
 
 #include <openssl/evp.h>
 
@@ -89,6 +89,7 @@ key_new(int type)
        }
        return k;
 }
+
 Key *
 key_new_private(int type)
 {
@@ -120,6 +121,7 @@ key_new_private(int type)
        }
        return k;
 }
+
 void
 key_free(Key *k)
 {
@@ -359,6 +361,7 @@ read_bignum(char **cpp, BIGNUM * value)
        *cpp = cp;
        return 1;
 }
+
 static int
 write_bignum(FILE *f, BIGNUM *num)
 {
@@ -485,6 +488,7 @@ key_read(Key *ret, char **cpp)
        }
        return success;
 }
+
 int
 key_write(Key *key, FILE *f)
 {
@@ -516,6 +520,7 @@ key_write(Key *key, FILE *f)
        }
        return success;
 }
+
 char *
 key_type(Key *k)
 {
@@ -532,6 +537,7 @@ key_type(Key *k)
        }
        return "unknown";
 }
+
 char *
 key_ssh_name(Key *k)
 {
@@ -545,6 +551,7 @@ key_ssh_name(Key *k)
        }
        return "ssh-unknown";
 }
+
 u_int
 key_size(Key *k)
 {
@@ -779,6 +786,10 @@ key_sign(
        }
 }
 
+/*
+ * key_verify returns 1 for a correct signature, 0 for an incorrect signature
+ * and -1 on error.
+ */
 int
 key_verify(
     Key *key,
@@ -801,3 +812,45 @@ 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.062923 seconds and 4 git commands to generate.