66 static void int_dh_free(
EVP_PKEY *pkey)
73 const unsigned char *
p, *pm;
103 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen)))
116 ASN1_INTEGER_free(public_key);
122 ASN1_INTEGER_free(public_key);
134 unsigned char *penc = NULL;
155 penclen = i2d_ASN1_INTEGER(pub_key, &penc);
157 ASN1_INTEGER_free(pub_key);
166 ptype, pval, penc, penclen))
186 const unsigned char *
p, *pm;
204 if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen)))
225 ASN1_INTEGER_free(privkey);
240 unsigned char *dp = NULL;
268 dplen = i2d_ASN1_INTEGER(prkey, &dp);
270 ASN1_INTEGER_free(prkey);
284 ASN1_INTEGER_free(prkey);
289 static void update_buflen(
const BIGNUM *
b,
size_t *pbuflen)
298 static int dh_param_decode(
EVP_PKEY *pkey,
299 const unsigned char **pder,
int derlen)
311 static int dh_param_encode(
const EVP_PKEY *pkey,
unsigned char **pder)
316 static int do_dh_print(
BIO *
bp,
const DH *x,
int indent,
319 unsigned char *m=NULL;
323 const char *ktype = NULL;
325 BIGNUM *priv_key, *pub_key;
337 update_buflen(x->
p, &buf_len);
345 update_buflen(x->
g, &buf_len);
346 update_buflen(pub_key, &buf_len);
347 update_buflen(priv_key, &buf_len);
350 ktype =
"PKCS#3 DH Private-Key";
352 ktype =
"PKCS#3 DH Public-Key";
354 ktype =
"PKCS#3 DH Parameters";
368 if (!
ASN1_bn_print(bp,
"private-key:",priv_key,m,indent))
goto err;
369 if (!
ASN1_bn_print(bp,
"public-key:",pub_key,m,indent))
goto err;
376 if (
BIO_printf(bp,
"recommended-private-length: %d bits\n",
377 (
int)x->
length) <= 0)
goto err;
391 static int int_dh_size(
const EVP_PKEY *pkey)
396 static int dh_bits(
const EVP_PKEY *pkey)
429 static int dh_missing_parameters(
const EVP_PKEY *a)
438 if (dh_cmp_parameters(a, b) == 0)
446 static int dh_param_print(
BIO *bp,
const EVP_PKEY *pkey,
int indent,
449 return do_dh_print(bp, pkey->
pkey.
dh, indent, ctx, 0);
452 static int dh_public_print(
BIO *bp,
const EVP_PKEY *pkey,
int indent,
455 return do_dh_print(bp, pkey->
pkey.
dh, indent, ctx, 1);
458 static int dh_private_print(
BIO *bp,
const EVP_PKEY *pkey,
int indent,
461 return do_dh_print(bp, pkey->
pkey.
dh, indent, ctx, 2);
466 return do_dh_print(bp, x, 4, NULL, 0);
476 "OpenSSL PKCS#3 DH method",
492 dh_missing_parameters,