summaryrefslogtreecommitdiffstats
path: root/crypto/dh/dh_ameth.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2006-03-28 14:35:32 +0000
committerDr. Stephen Henson <steve@openssl.org>2006-03-28 14:35:32 +0000
commit3e4585c8fd0b23f884d775462736502599146af6 (patch)
tree27b73970dedcc4215d6f7c4def10ee3990674143 /crypto/dh/dh_ameth.c
parent3e84b6e15fe6a580177b9e242c66e1d1ab6c2164 (diff)
New utility pkeyparam. Enhance and bugfix algorithm specific parameter
functions to support it.
Diffstat (limited to 'crypto/dh/dh_ameth.c')
-rw-r--r--crypto/dh/dh_ameth.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c
index bcc56a166e..ba3ff562a1 100644
--- a/crypto/dh/dh_ameth.c
+++ b/crypto/dh/dh_ameth.c
@@ -67,6 +67,82 @@ static void int_dh_free(EVP_PKEY *pkey)
DH_free(pkey->pkey.dh);
}
+static int dh_param_decode(EVP_PKEY *pkey,
+ const unsigned char **pder, int derlen)
+ {
+ DH *dh;
+ if (!(dh = d2i_DHparams(NULL, pder, derlen)))
+ {
+ DHerr(DH_F_DH_PARAM_DECODE, ERR_R_DH_LIB);
+ return 0;
+ }
+ EVP_PKEY_assign_DH(pkey, dh);
+ return 1;
+ }
+
+static int dh_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
+ {
+ return i2d_DHparams(pkey->pkey.dh, pder);
+ }
+
+static int do_dhparam_print(BIO *bp, const DH *x, int indent,
+ ASN1_PCTX *ctx)
+ {
+ unsigned char *m=NULL;
+ int reason=ERR_R_BUF_LIB,ret=0;
+ size_t buf_len=0, i;
+
+ if (x->p)
+ buf_len = (size_t)BN_num_bytes(x->p);
+ else
+ {
+ reason = ERR_R_PASSED_NULL_PARAMETER;
+ goto err;
+ }
+ if (x->g)
+ if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
+ buf_len = i;
+ m=(unsigned char *)OPENSSL_malloc(buf_len+10);
+ if (m == NULL)
+ {
+ reason=ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+
+ BIO_indent(bp, indent, 128);
+ if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n",
+ BN_num_bits(x->p)) <= 0)
+ goto err;
+ indent += 4;
+ if (!ASN1_bn_print(bp,"prime:",x->p,m,indent)) goto err;
+ if (!ASN1_bn_print(bp,"generator:",x->g,m,indent)) goto err;
+ if (x->length != 0)
+ {
+ BIO_indent(bp, indent, 128);
+ if (BIO_printf(bp,"recommended-private-length: %d bits\n",
+ (int)x->length) <= 0) goto err;
+ }
+ ret=1;
+ if (0)
+ {
+err:
+ DHerr(DH_F_DHPARAMS_PRINT,reason);
+ }
+ if (m != NULL) OPENSSL_free(m);
+ return(ret);
+ }
+
+static int dh_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_dhparam_print(bp, pkey->pkey.dh, indent, ctx);
+ }
+
+int DHparams_print(BIO *bp, const DH *x)
+ {
+ return do_dhparam_print(bp, x, 4, NULL);
+ }
+
const EVP_PKEY_ASN1_METHOD dh_asn1_meth =
{
EVP_PKEY_DH,
@@ -88,7 +164,10 @@ const EVP_PKEY_ASN1_METHOD dh_asn1_meth =
0,
0,
- 0,0,0,0,0,0,
+ dh_param_decode,
+ dh_param_encode,
+ 0,0,0,
+ dh_param_print,
int_dh_free,
0