Add ecdsa_from_keypair()

Also fix bug/limitation in mpi_copy: would segfault if src just initialised
and not set to a value yet. (This case occurs when copying a context which
contains only the public part of the key, eg.)
diff --git a/library/bignum.c b/library/bignum.c
index cc4b1f3..b0bbf8f 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -130,6 +130,12 @@
     if( X == Y )
         return( 0 );
 
+    if( Y->p == NULL )
+    {
+        mpi_free( X );
+        return( 0 );
+    }
+
     for( i = Y->n - 1; i > 0; i-- )
         if( Y->p[i] != 0 )
             break;
diff --git a/library/ecdsa.c b/library/ecdsa.c
index 6746233..bdb3567 100644
--- a/library/ecdsa.c
+++ b/library/ecdsa.c
@@ -283,6 +283,20 @@
             ecp_gen_keypair( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) );
 }
 
+/*
+ * Set context from an ecp_keypair
+ */
+int ecdsa_from_keypair( ecdsa_context *ctx, const ecp_keypair *key )
+{
+    int ret = ecp_group_copy( &ctx->grp, &key->grp ) ||
+              mpi_copy( &ctx->d, &key->d ) ||
+              ecp_copy( &ctx->Q, &key->Q );
+
+    if( ret != 0 )
+        ecdsa_free( ctx );
+
+    return( ret );
+}
 
 /*
  * Initialize context