Use generic x509_get_pubkey() for RSA functions
diff --git a/library/pk.c b/library/pk.c
index 0591b3f..6762c75 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -46,6 +46,7 @@
ctx->type = POLARSSL_PK_NONE;
ctx->data = NULL;
+ ctx->dont_free = 0;
}
/*
@@ -75,7 +76,8 @@
#endif
}
- free( ctx-> data );
+ if( ! ctx->dont_free )
+ free( ctx->data );
ctx->type = POLARSSL_PK_NONE;
ctx->data = NULL;
@@ -121,3 +123,20 @@
return( 0 );
}
+
+#if defined(POLARSSL_RSA_C)
+/*
+ * Wrap an RSA context in a PK context
+ */
+int pk_wrap_rsa( pk_context *ctx, const rsa_context *rsa)
+{
+ if( ctx->type != POLARSSL_PK_NONE )
+ return( POLARSSL_ERR_PK_TYPE_MISMATCH );
+
+ ctx->type = POLARSSL_PK_RSA;
+ ctx->data = (rsa_context *) rsa;
+ ctx->dont_free = 1;
+
+ return( 0 );
+}
+#endif