OpenSSL CVS Repository
http://cvs.openssl.org/
____________________________________________________________
________________
Server: cvs.openssl.org Name: Dr.
Stephen Henson
Root: /v/openssl/cvs Email: steve openssl.org
Module: openssl Date:
22-Mar-2006 14:09:35
Branch: HEAD Handle:
2006032213093005
Modified files:
openssl CHANGES
openssl/crypto/asn1 asn1.h t_pkey.c t_req.c t_spki.c
t_x509.c
openssl/crypto/dsa dsa_ameth.c
openssl/crypto/ec ec_ameth.c
openssl/crypto/evp evp.h evp_pkey.c p_lib.c
openssl/crypto/rsa rsa_ameth.c
Log:
Gather printing routines into EVP_PKEY_ASN1_METHOD.
Summary:
Revision Changes Path
1.1293 +6 -0 openssl/CHANGES
1.142 +3 -1 openssl/crypto/asn1/asn1.h
1.40 +49 -526 openssl/crypto/asn1/t_pkey.c
1.24 +2 -26 openssl/crypto/asn1/t_req.c
1.10 +3 -28 openssl/crypto/asn1/t_spki.c
1.39 +2 -26 openssl/crypto/asn1/t_x509.c
1.3 +98 -3 openssl/crypto/dsa/dsa_ameth.c
1.3 +368 -4 openssl/crypto/ec/ec_ameth.c
1.117 +7 -0 openssl/crypto/evp/evp.h
1.42 +0 -6 openssl/crypto/evp/evp_pkey.c
1.35 +34 -0 openssl/crypto/evp/p_lib.c
1.3 +97 -2 openssl/crypto/rsa/rsa_ameth.c
____________________________________________________________
________________
patch -p0 <<' .'
Index: openssl/CHANGES
============================================================
================
$ cvs diff -u -r1.1292 -r1.1293 CHANGES
--- openssl/CHANGES 20 Mar 2006 12:22:18 -0000 1.1292
+++ openssl/CHANGES 22 Mar 2006 13:09:30 -0000 1.1293
 -4,6 +4,12 
Changes between 0.9.8a and 0.9.9 [xx XXX xxxx]
+ *) Transfer public key printing routines to
EVP_PKEY_ASN1_METHOD. New
+ functions EVP_PKEY_print_public(),
EVP_PKEY_print_private(),
+ EVP_PKEY_print_param() to print public key data from
an EVP_PKEY
+ structure.
+ [Steve Henson]
+
*) Initial support for pluggable public key ASN1.
De-spaghettify the public key ASN1 handling. Move
public and private
key ASN1 handling to a new EVP_PKEY_ASN1_METHOD
structure. Relocate
 .
patch -p0 <<' .'
Index: openssl/crypto/asn1/asn1.h
============================================================
================
$ cvs diff -u -r1.141 -r1.142 asn1.h
--- openssl/crypto/asn1/asn1.h 20 Mar 2006 17:56:03
-0000 1.141
+++ openssl/crypto/asn1/asn1.h 22 Mar 2006 13:09:31
-0000 1.142
 -300,7 +300,7 
int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO
*p8inf);
int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const
EVP_PKEY *pk);
- int (*priv_print)(BIO *out, EVP_PKEY *pkey, int indent,
+ int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int
indent,
ASN1_PCTX *pctx);
int (*pkey_size)(const EVP_PKEY *pk);
 -981,6 +981,8 
int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a);
int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str,
unsigned long flags);
+int ASN1_bn_print(BIO *bp, const char *number, const
BIGNUM *num,
+ unsigned char *buf, int off);
int ASN1_parse(BIO *bp,const unsigned char *pp,long
len,int indent);
int ASN1_parse_dump(BIO *bp,const unsigned char *pp,long
len,int indent,int dump);
#endif
 .
patch -p0 <<' .'
Index: openssl/crypto/asn1/t_pkey.c
============================================================
================
$ cvs diff -u -r1.39 -r1.40 t_pkey.c
--- openssl/crypto/asn1/t_pkey.c 15 Mar 2006 08:37:35
-0000 1.39
+++ openssl/crypto/asn1/t_pkey.c 22 Mar 2006 13:09:31
-0000 1.40
 -66,6 +66,7 
#include <openssl/objects.h>
#include <openssl/buffer.h>
#include <openssl/bn.h>
+#include <openssl/evp.h>
#ifndef OPENSSL_NO_RSA
#include <openssl/rsa.h>
#endif
 -79,12 +80,6 
#include <openssl/ec.h>
#endif
-static int print(BIO *fp,const char *str, const BIGNUM
*num,
- unsigned char *buf,int off);
-#ifndef OPENSSL_NO_EC
-static int print_bin(BIO *fp, const char *str, const
unsigned char *num,
- size_t len, int off);
-#endif
#ifndef OPENSSL_NO_RSA
#ifndef OPENSSL_NO_FP_API
int RSA_print_fp(FILE *fp, const RSA *x, int off)
 -106,79 +101,16 
int RSA_print(BIO *bp, const RSA *x, int off)
{
- char str[128];
- const char *s;
- unsigned char *m=NULL;
- int ret=0, mod_len = 0;
- size_t buf_len=0, i;
-
- if (x->n)
- buf_len = (size_t)BN_num_bytes(x->n);
- if (x->e)
- if (buf_len < (i = (size_t)BN_num_bytes(x->e)))
- buf_len = i;
- if (x->d)
- if (buf_len < (i = (size_t)BN_num_bytes(x->d)))
- buf_len = i;
- if (x->p)
- if (buf_len < (i = (size_t)BN_num_bytes(x->p)))
- buf_len = i;
- if (x->q)
- if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
- buf_len = i;
- if (x->dmp1)
- if (buf_len < (i =
(size_t)BN_num_bytes(x->dmp1)))
- buf_len = i;
- if (x->dmq1)
- if (buf_len < (i =
(size_t)BN_num_bytes(x->dmq1)))
- buf_len = i;
- if (x->iqmp)
- if (buf_len < (i =
(size_t)BN_num_bytes(x->iqmp)))
- buf_len = i;
-
- m=(unsigned char *)OPENSSL_malloc(buf_len+10);
- if (m == NULL)
- {
- RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
- goto err;
- }
-
- if (x->n != NULL)
- mod_len = BN_num_bits(x->n);
-
- if (x->d != NULL)
- {
- if(!BIO_indent(bp,off,128))
- goto err;
- if (BIO_printf(bp,"Private-Key: (%d
bit)\n", mod_len)
- <= 0) goto err;
- }
-
- if (x->d == NULL)
- BIO_snprintf(str,sizeof str,"Modulus (%d
bit):", mod_len);
- else
- BUF_strlcpy(str,"modulus:",sizeof str);
- if (!print(bp,str,x->n,m,off)) goto err;
- s=(x->d ==
NULL)?"Exponent:":"publicExponent:";
- if ((x->e != NULL) &&
!print(bp,s,x->e,m,off))
- goto err;
- if ((x->d != NULL) &&
!print(bp,"privateExponent:",x->d,m,off))
- goto err;
- if ((x->p != NULL) &&
!print(bp,"prime1:",x->p,m,off))
- goto err;
- if ((x->q != NULL) &&
!print(bp,"prime2:",x->q,m,off))
- goto err;
- if ((x->dmp1 != NULL) &&
!print(bp,"exponent1:",x->dmp1,m,off))
- goto err;
- if ((x->dmq1 != NULL) &&
!print(bp,"exponent2:",x->dmq1,m,off))
- goto err;
- if ((x->iqmp != NULL) &&
!print(bp,"coefficient:",x->iqmp,m,off))
- goto err;
- ret=1;
-err:
- if (m != NULL) OPENSSL_free(m);
- return(ret);
+ EVP_PKEY *pk;
+ int ret;
+ pk = EVP_PKEY_new();
+ if (!pk || !EVP_PKEY_set1_RSA(pk, (RSA *)x))
+ return 0;
+ ret = EVP_PKEY_print_private(bp, pk, off, NULL);
+ EVP_PKEY_free(pk);
+ return ret;
}
+
#endif /* OPENSSL_NO_RSA */
#ifndef OPENSSL_NO_DSA
 -202,57 +134,16 
int DSA_print(BIO *bp, const DSA *x, int off)
{
- unsigned char *m=NULL;
- int ret=0;
- size_t buf_len=0,i;
-
- if (x->p)
- buf_len = (size_t)BN_num_bytes(x->p);
- else
- {
- DSAerr(DSA_F_DSA_PRINT,DSA_R_MISSING_PARAMETERS);
- goto err;
- }
- if (x->q)
- if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
- buf_len = i;
- if (x->g)
- if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
- buf_len = i;
- if (x->priv_key)
- if (buf_len < (i =
(size_t)BN_num_bytes(x->priv_key)))
- buf_len = i;
- if (x->pub_key)
- if (buf_len < (i =
(size_t)BN_num_bytes(x->pub_key)))
- buf_len = i;
-
- m=(unsigned char *)OPENSSL_malloc(buf_len+10);
- if (m == NULL)
- {
- DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
- goto err;
- }
-
- if (x->priv_key != NULL)
- {
- if(!BIO_indent(bp,off,128))
- goto err;
- if (BIO_printf(bp,"Private-Key: (%d
bit)\n",BN_num_bits(x->p))
- <= 0) goto err;
- }
-
- if ((x->priv_key != NULL) &&
!print(bp,"priv:",x->priv_key,m,off))
- goto err;
- if ((x->pub_key != NULL) &&
!print(bp,"pub: ",x->pub_key,m,off))
- goto err;
- if ((x->p != NULL) && !print(bp,"P:
",x->p,m,off)) goto err;
- if ((x->q != NULL) && !print(bp,"Q:
",x->q,m,off)) goto err;
- if ((x->g != NULL) && !print(bp,"G:
",x->g,m,off)) goto err;
- ret=1;
-err:
- if (m != NULL) OPENSSL_free(m);
- return(ret);
+ EVP_PKEY *pk;
+ int ret;
+ pk = EVP_PKEY_new();
+ if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
+ return 0;
+ ret = EVP_PKEY_print_private(bp, pk, off, NULL);
+ EVP_PKEY_free(pk);
+ return ret;
}
+
#endif /* !OPENSSL_NO_DSA */
#ifndef OPENSSL_NO_EC
 -290,299 +181,22 
}
#endif
-int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int
off)
- {
- unsigned char *buffer=NULL;
- size_t buf_len=0, i;
- int ret=0, reason=ERR_R_BIO_LIB;
- BN_CTX *ctx=NULL;
- const EC_POINT *point=NULL;
- BIGNUM *p=NULL, *a=NULL, *b=NULL, *gen=NULL,
- *order=NULL, *cofactor=NULL;
- const unsigned char *seed;
- size_t seed_len=0;
-
- static const char *gen_compressed = "Generator
(compressed):";
- static const char *gen_uncompressed = "Generator
(uncompressed):";
- static const char *gen_hybrid = "Generator
(hybrid):";
-
- if (!x)
- {
- reason = ERR_R_PASSED_NULL_PARAMETER;
- goto err;
- }
-
- ctx = BN_CTX_new();
- if (ctx == NULL)
- {
- reason = ERR_R_MALLOC_FAILURE;
- goto err;
- }
-
- if (EC_GROUP_get_asn1_flag(x))
- {
- /* the curve parameter are given by an asn1 OID */
- int nid;
-
- if (!BIO_indent(bp, off, 128))
- goto err;
-
- nid = EC_GROUP_get_curve_name(x);
- if (nid == 0)
- goto err;
-
- if (BIO_printf(bp, "ASN1 OID: %s",
OBJ_nid2sn(nid)) <= 0)
- goto err;
- if (BIO_printf(bp, "\n") <= 0)
- goto err;
- }
- else
- {
- /* explicit parameters */
- int is_char_two = 0;
- point_conversion_form_t form;
- int tmp_nid =
EC_METHOD_get_field_type(EC_GROUP_method_of(x));
-
- if (tmp_nid == NID_X9_62_characteristic_two_field)
- is_char_two = 1;
-
- if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
- (b = BN_new()) == NULL || (order = BN_new()) == NULL
||
- (cofactor = BN_new()) == NULL)
- {
- reason = ERR_R_MALLOC_FAILURE;
- goto err;
- }
-
- if (is_char_two)
- {
- if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx))
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
- }
- else /* prime field */
- {
- if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx))
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
- }
-
- if ((point = EC_GROUP_get0_generator(x)) == NULL)
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
- if (!EC_GROUP_get_order(x, order, NULL) ||
- !EC_GROUP_get_cofactor(x, cofactor, NULL))
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
-
- form = EC_GROUP_get_point_conversion_form(x);
-
- if ((gen = EC_POINT_point2bn(x, point,
- form, NULL, ctx)) == NULL)
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
-
- buf_len = (size_t)BN_num_bytes(p);
- if (buf_len < (i = (size_t)BN_num_bytes(a)))
- buf_len = i;
- if (buf_len < (i = (size_t)BN_num_bytes(b)))
- buf_len = i;
- if (buf_len < (i = (size_t)BN_num_bytes(gen)))
- buf_len = i;
- if (buf_len < (i = (size_t)BN_num_bytes(order)))
- buf_len = i;
- if (buf_len < (i = (size_t)BN_num_bytes(cofactor)))
- buf_len = i;
-
- if ((seed = EC_GROUP_get0_seed(x)) != NULL)
- seed_len = EC_GROUP_get_seed_len(x);
-
- buf_len += 10;
- if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
- {
- reason = ERR_R_MALLOC_FAILURE;
- goto err;
- }
-
- if (!BIO_indent(bp, off, 128))
- goto err;
-
- /* print the 'short name' of the field type */
- if (BIO_printf(bp, "Field Type: %s\n",
OBJ_nid2sn(tmp_nid))
- <= 0)
- goto err;
-
- if (is_char_two)
- {
- /* print the 'short name' of the base type OID */
- int basis_type = EC_GROUP_get_basis_type(x);
- if (basis_type == 0)
- goto err;
-
- if (!BIO_indent(bp, off, 128))
- goto err;
-
- if (BIO_printf(bp, "Basis Type: %s\n",
- OBJ_nid2sn(basis_type)) <= 0)
- goto err;
-
- /* print the polynomial */
- if ((p != NULL) && !print(bp,
"Polynomial:", p, buffer,
- off))
- goto err;
- }
- else
- {
- if ((p != NULL) && !print(bp,
"Prime:", p, buffer,off))
- goto err;
- }
- if ((a != NULL) && !print(bp, "A:
", a, buffer, off))
- goto err;
- if ((b != NULL) && !print(bp, "B:
", b, buffer, off))
- goto err;
- if (form == POINT_CONVERSION_COMPRESSED)
- {
- if ((gen != NULL) && !print(bp,
gen_compressed, gen,
- buffer, off))
- goto err;
- }
- else if (form == POINT_CONVERSION_UNCOMPRESSED)
- {
- if ((gen != NULL) && !print(bp,
gen_uncompressed, gen,
- buffer, off))
- goto err;
- }
- else /* form == POINT_CONVERSION_HYBRID */
- {
- if ((gen != NULL) && !print(bp, gen_hybrid,
gen,
- buffer, off))
- goto err;
- }
- if ((order != NULL) && !print(bp, "Order:
", order,
- buffer, off)) goto err;
- if ((cofactor != NULL) && !print(bp,
"Cofactor: ", cofactor,
- buffer, off)) goto err;
- if (seed && !print_bin(bp, "Seed:",
seed, seed_len, off))
- goto err;
- }
- ret=1;
-err:
- if (!ret)
- ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
- if (p)
- BN_free(p);
- if (a)
- BN_free(a);
- if (b)
- BN_free(b);
- if (gen)
- BN_free(gen);
- if (order)
- BN_free(order);
- if (cofactor)
- BN_free(cofactor);
- if (ctx)
- BN_CTX_free(ctx);
- if (buffer != NULL)
- OPENSSL_free(buffer);
- return(ret);
- }
-
int EC_KEY_print(BIO *bp, const EC_KEY *x, int off)
{
- unsigned char *buffer=NULL;
- size_t buf_len=0, i;
- int ret=0, reason=ERR_R_BIO_LIB;
- BIGNUM *pub_key=NULL, *order=NULL;
- BN_CTX *ctx=NULL;
- const EC_GROUP *group;
- const EC_POINT *public_key;
- const BIGNUM *priv_key;
-
- if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
- {
- reason = ERR_R_PASSED_NULL_PARAMETER;
- goto err;
- }
-
- ctx = BN_CTX_new();
- if (ctx == NULL)
- {
- reason = ERR_R_MALLOC_FAILURE;
- goto err;
- }
-
- public_key = EC_KEY_get0_public_key(x);
- if ((pub_key = EC_POINT_point2bn(group, public_key,
- EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
-
- buf_len = (size_t)BN_num_bytes(pub_key);
- priv_key = EC_KEY_get0_private_key(x);
- if (priv_key != NULL)
- {
- if ((i = (size_t)BN_num_bytes(priv_key)) > buf_len)
- buf_len = i;
- }
-
- buf_len += 10;
- if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
- {
- reason = ERR_R_MALLOC_FAILURE;
- goto err;
- }
-
- if (priv_key != NULL)
- {
- if (!BIO_indent(bp, off, 128))
- goto err;
- if ((order = BN_new()) == NULL)
- goto err;
- if (!EC_GROUP_get_order(group, order, NULL))
- goto err;
- if (BIO_printf(bp, "Private-Key: (%d
bit)\n",
- BN_num_bits(order)) <= 0) goto err;
- }
-
- if ((priv_key != NULL) && !print(bp,
"priv:", priv_key,
- buffer, off))
- goto err;
- if ((pub_key != NULL) && !print(bp, "pub:
", pub_key,
- buffer, off))
- goto err;
- if (!ECPKParameters_print(bp, group, off))
- goto err;
- ret=1;
-err:
- if (!ret)
- ECerr(EC_F_EC_KEY_PRINT, reason);
- if (pub_key)
- BN_free(pub_key);
- if (order)
- BN_free(order);
- if (ctx)
- BN_CTX_free(ctx);
- if (buffer != NULL)
- OPENSSL_free(buffer);
- return(ret);
+ EVP_PKEY *pk;
+ int ret;
+ pk = EVP_PKEY_new();
+ if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x))
+ return 0;
+ ret = EVP_PKEY_print_private(bp, pk, off, NULL);
+ EVP_PKEY_free(pk);
+ return ret;
}
+
#endif /* OPENSSL_NO_EC */
-static int print(BIO *bp, const char *number, const
BIGNUM *num, unsigned char *buf,
- int off)
+int ASN1_bn_print(BIO *bp, const char *number, const
BIGNUM *num,
+ unsigned char *buf, int off)
{
int n,i;
const char *neg;
 -632,46 +246,6 
return(1);
}
-#ifndef OPENSSL_NO_EC
-static int print_bin(BIO *fp, const char *name, const
unsigned char *buf,
- size_t len, int off)
- {
- size_t i;
- char str[128];
-
- if (buf == NULL)
- return 1;
- if (off)
- {
- if (off > 128)
- off=128;
- memset(str,' ',off);
- if (BIO_write(fp, str, off) <= 0)
- return 0;
- }
-
- if (BIO_printf(fp,"%s", name) <= 0)
- return 0;
-
- for (i=0; i<len; i++)
- {
- if ((i%15) == 0)
- {
- str[0]='\n';
- memset(&(str[1]),' ',off+4);
- if (BIO_write(fp, str, off+1+4) <= 0)
- return 0;
- }
- if (BIO_printf(fp,"%02x%s",buf[i],((i+1) ==
len)?"":":") <= 0)
- return 0;
- }
- if (BIO_write(fp,"\n",1) <= 0)
- return 0;
-
- return 1;
- }
-#endif
-
#ifndef OPENSSL_NO_DH
#ifndef OPENSSL_NO_FP_API
int DHparams_print_fp(FILE *fp, const DH *x)
 -717,8 +291,8 
if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d
bit)\n",
BN_num_bits(x->p)) <= 0)
goto err;
- if (!print(bp,"prime:",x->p,m,4)) goto
err;
- if (!print(bp,"generator:",x->g,m,4))
goto err;
+ if (!ASN1_bn_print(bp,"prime:",x->p,m,4))
goto err;
+ if
(!ASN1_bn_print(bp,"generator:",x->g,m,4))
goto err;
if (x->length != 0)
{
if (BIO_printf(bp,"
recommended-private-length: %d bits\n",
 -756,40 +330,14 
int DSAparams_print(BIO *bp, const DSA *x)
{
- unsigned char *m=NULL;
- int ret=0;
- size_t buf_len=0,i;
-
- if (x->p)
- buf_len = (size_t)BN_num_bytes(x->p);
- else
- {
- DSAerr(DSA_F_DSAPARAMS_PRINT,DSA_R_MISSING_PARAMETERS);
- goto err;
- }
- if (x->q)
- if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
- buf_len = i;
- 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)
- {
- DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
- goto err;
- }
-
- if (BIO_printf(bp,"DSA-Parameters: (%d
bit)\n",
- BN_num_bits(x->p)) <= 0)
- goto err;
- if (!print(bp,"p:",x->p,m,4)) goto err;
- if ((x->q != NULL) &&
!print(bp,"q:",x->q,m,4)) goto err;
- if ((x->g != NULL) &&
!print(bp,"g:",x->g,m,4)) goto err;
- ret=1;
-err:
- if (m != NULL) OPENSSL_free(m);
- return(ret);
+ EVP_PKEY *pk;
+ int ret;
+ pk = EVP_PKEY_new();
+ if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
+ return 0;
+ ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
+ EVP_PKEY_free(pk);
+ return ret;
}
#endif /* !OPENSSL_NO_DSA */
 -815,39 +363,14 
int ECParameters_print(BIO *bp, const EC_KEY *x)
{
- int reason=ERR_R_EC_LIB, ret=0;
- BIGNUM *order=NULL;
- const EC_GROUP *group;
-
- if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
- {
- reason = ERR_R_PASSED_NULL_PARAMETER;;
- goto err;
- }
-
- if ((order = BN_new()) == NULL)
- {
- reason = ERR_R_MALLOC_FAILURE;
- goto err;
- }
-
- if (!EC_GROUP_get_order(group, order, NULL))
- {
- reason = ERR_R_EC_LIB;
- goto err;
- }
-
- if (BIO_printf(bp, "ECDSA-Parameters: (%d
bit)\n",
- BN_num_bits(order)) <= 0)
- goto err;
- if (!ECPKParameters_print(bp, group, 4))
- goto err;
- ret=1;
-err:
- if (order)
- BN_free(order);
- ECerr(EC_F_ECPARAMETERS_PRINT, reason);
- return(ret);
+ EVP_PKEY *pk;
+ int ret;
+ pk = EVP_PKEY_new();
+ if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *)x))
+ return 0;
+ ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
+ EVP_PKEY_free(pk);
+ return ret;
}
-
+
#endif
 .
patch -p0 <<' .'
Index: openssl/crypto/asn1/t_req.c
============================================================
================
$ cvs diff -u -r1.23 -r1.24 t_req.c
--- openssl/crypto/asn1/t_req.c 16 Jul 2005 12:37:30
-0000 1.23
+++ openssl/crypto/asn1/t_req.c 22 Mar 2006 13:09:31
-0000 1.24
 -149,34 +149,10 
ERR_print_errors(bp);
}
else
-#ifndef OPENSSL_NO_RSA
- if (pkey->type == EVP_PKEY_RSA)
{
- BIO_printf(bp,"%12sRSA Public Key: (%d
bit)\n","",
- BN_num_bits(pkey->pkey.rsa->n));
- RSA_print(bp,pkey->pkey.rsa,16);
+ EVP_PKEY_print_public(bp, pkey, 16, NULL);
+ EVP_PKEY_free(pkey);
}
- else
-#endif
-#ifndef OPENSSL_NO_DSA
- if (pkey->type == EVP_PKEY_DSA)
- {
- BIO_printf(bp,"%12sDSA Public
Key:\n","");
- DSA_print(bp,pkey->pkey.dsa,16);
- }
- else
-#endif
-#ifndef OPENSSL_NO_EC
- if (pkey->type == EVP_PKEY_EC)
- {
- BIO_printf(bp, "%12sEC Public Key:
\n","");
- EC_KEY_print(bp, pkey->pkey.ec, 16);
- }
- else
-#endif
- BIO_printf(bp,"%12sUnknown Public
Key:\n","");
-
- EVP_PKEY_free(pkey);
}
if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
 .
patch -p0 <<' .'
Index: openssl/crypto/asn1/t_spki.c
============================================================
================
$ cvs diff -u -r1.9 -r1.10 t_spki.c
--- openssl/crypto/asn1/t_spki.c 16 Jul 2005 12:37:30
-0000 1.9
+++ openssl/crypto/asn1/t_spki.c 22 Mar 2006 13:09:32
-0000 1.10
 -82,36 +82,11 
(i ==
NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
pkey = X509_PUBKEY_get(spki->spkac->pubkey);
if(!pkey) BIO_printf(out, " Unable to load public
key\n");
- else {
-#ifndef OPENSSL_NO_RSA
- if (pkey->type == EVP_PKEY_RSA)
- {
- BIO_printf(out," RSA Public Key: (%d
bit)\n",
- BN_num_bits(pkey->pkey.rsa->n));
- RSA_print(out,pkey->pkey.rsa,2);
- }
- else
-#endif
-#ifndef OPENSSL_NO_DSA
- if (pkey->type == EVP_PKEY_DSA)
+ else
{
- BIO_printf(out," DSA Public Key:\n");
- DSA_print(out,pkey->pkey.dsa,2);
- }
- else
-#endif
-#ifndef OPENSSL_NO_EC
- if (pkey->type == EVP_PKEY_EC)
- {
- BIO_printf(out, " EC Public Key:\n");
- EC_KEY_print(out, pkey->pkey.ec,2);
- }
- else
-#endif
-
- BIO_printf(out," Unknown Public
Key:\n");
+ EVP_PKEY_print_public(out, pkey, 4, NULL);
EVP_PKEY_free(pkey);
- }
+ }
chal = spki->spkac->challenge;
if(chal->length)
BIO_printf(out, " Challenge String:
%s\n", chal->data);
 .
patch -p0 <<' .'
Index: openssl/crypto/asn1/t_x509.c
============================================================
================
$ cvs diff -u -r1.38 -r1.39 t_x509.c
--- openssl/crypto/asn1/t_x509.c 15 Mar 2006 17:45:41
-0000 1.38
+++ openssl/crypto/asn1/t_x509.c 22 Mar 2006 13:09:32
-0000 1.39
 -214,34 +214,10 
ERR_print_errors(bp);
}
else
-#ifndef OPENSSL_NO_RSA
- if (pkey->type == EVP_PKEY_RSA)
{
- BIO_printf(bp,"%12sRSA Public Key: (%d
bit)\n","",
- BN_num_bits(pkey->pkey.rsa->n));
- RSA_print(bp,pkey->pkey.rsa,16);
+ EVP_PKEY_print_public(bp, pkey, 16, NULL);
+ EVP_PKEY_free(pkey);
}
- else
-#endif
-#ifndef OPENSSL_NO_DSA
- if (pkey->type == EVP_PKEY_DSA)
- {
- BIO_printf(bp,"%12sDSA Public
Key:\n","");
- DSA_print(bp,pkey->pkey.dsa,16);
- }
- else
-#endif
-#ifndef OPENSSL_NO_EC
- if (pkey->type == EVP_PKEY_EC)
- {
- BIO_printf(bp, "%12sEC Public
Key:\n","");
- EC_KEY_print(bp, pkey->pkey.ec, 16);
- }
- else
-#endif
- BIO_printf(bp,"%12sUnknown Public
Key:\n","");
-
- EVP_PKEY_free(pkey);
}
if (!(cflag & X509_FLAG_NO_EXTENSIONS))
 .
patch -p0 <<' .'
Index: openssl/crypto/dsa/dsa_ameth.c
============================================================
================
$ cvs diff -u -r1.2 -r1.3 dsa_ameth.c
--- openssl/crypto/dsa/dsa_ameth.c 20 Mar 2006 17:56:04
-0000 1.2
+++ openssl/crypto/dsa/dsa_ameth.c 22 Mar 2006 13:09:33
-0000 1.3
 -396,6 +396,101 
DSA_free(pkey->pkey.dsa);
}
+static void update_buflen(const BIGNUM *b, size_t
*pbuflen)
+ {
+ int i;
+ if (!b)
+ return;
+ if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
+ *pbuflen = i;
+ }
+
+int do_dsa_print(BIO *bp, const DSA *x, int off, int
ptype)
+ {
+ unsigned char *m=NULL;
+ int ret=0;
+ size_t buf_len=0;
+ const char *ktype = NULL;
+
+ const BIGNUM *priv_key, *pub_key;
+
+ if (ptype == 2)
+ priv_key = x->priv_key;
+ else
+ priv_key = NULL;
+
+ if (ptype > 0)
+ pub_key = x->pub_key;
+ else
+ pub_key = NULL;
+
+ if (ptype == 2)
+ ktype = "Private-Key";
+ else if (ptype == 1)
+ ktype = "Public-Key";
+ else
+ ktype = "DSA-Parameters";
+
+ if (x->p == NULL)
+ {
+ DSAerr(DSA_F_DSA_PRINT,DSA_R_MISSING_PARAMETERS);
+ goto err;
+ }
+
+ update_buflen(x->p, &buf_len);
+ update_buflen(x->q, &buf_len);
+ update_buflen(x->g, &buf_len);
+ update_buflen(priv_key, &buf_len);
+ update_buflen(pub_key, &buf_len);
+
+ m=(unsigned char *)OPENSSL_malloc(buf_len+10);
+ if (m == NULL)
+ {
+ DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ if (priv_key)
+ {
+ if(!BIO_indent(bp,off,128))
+ goto err;
+ if (BIO_printf(bp,"%s: (%d bit)\n",ktype,
BN_num_bits(x->p))
+ <= 0) goto err;
+ }
+
+ if
(!ASN1_bn_print(bp,"priv:",priv_key,m,off))
+ goto err;
+ if (!ASN1_bn_print(bp,"pub:
",pub_key,m,off))
+ goto err;
+ if (!ASN1_bn_print(bp,"P:
",x->p,m,off)) goto err;
+ if (!ASN1_bn_print(bp,"Q:
",x->q,m,off)) goto err;
+ if (!ASN1_bn_print(bp,"G:
",x->g,m,off)) goto err;
+ ret=1;
+err:
+ if (m != NULL) OPENSSL_free(m);
+ return(ret);
+ }
+
+
+static int dsa_param_print(BIO *bp, const EVP_PKEY *pkey,
int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
+ }
+
+static int dsa_pub_print(BIO *bp, const EVP_PKEY *pkey,
int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
+ }
+
+
+static int dsa_priv_print(BIO *bp, const EVP_PKEY *pkey,
int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
+ }
+
/* NB these are sorted in pkey_id order, lowest first */
const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] =
 -433,11 +528,11 
dsa_pub_decode,
dsa_pub_encode,
dsa_pub_cmp,
- 0,
+ dsa_pub_print,
dsa_priv_decode,
dsa_priv_encode,
- 0,
+ dsa_priv_print,
int_dsa_size,
dsa_bits,
 -446,7 +541,7 
dsa_missing_parameters,
dsa_copy_parameters,
dsa_cmp_parameters,
- 0,
+ dsa_param_print,
int_dsa_free,
0
 .
patch -p0 <<' .'
Index: openssl/crypto/ec/ec_ameth.c
============================================================
================
$ cvs diff -u -r1.2 -r1.3 ec_ameth.c
--- openssl/crypto/ec/ec_ameth.c 20 Mar 2006 17:56:04
-0000 1.2
+++ openssl/crypto/ec/ec_ameth.c 22 Mar 2006 13:09:33
-0000 1.3
 -2,7 +2,7 
* project 2006.
*/
/*
============================================================
========
- * Copyright (c) 2005 The OpenSSL Project. All rights
reserved.
+ * Copyright (c) 2006 The OpenSSL Project. All rights
reserved.
*
* Redistribution and use in source and binary forms,
with or without
* modification, are permitted provided that the
following conditions
 -419,6 +419,121 
EC_KEY_free(pkey->pkey.ec);
}
+static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int
off, int ktype)
+ {
+ unsigned char *buffer=NULL;
+ const char *ecstr;
+ size_t buf_len=0, i;
+ int ret=0, reason=ERR_R_BIO_LIB;
+ BIGNUM *pub_key=NULL, *order=NULL;
+ BN_CTX *ctx=NULL;
+ const EC_GROUP *group;
+ const EC_POINT *public_key;
+ const BIGNUM *priv_key;
+
+ if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
+ {
+ reason = ERR_R_PASSED_NULL_PARAMETER;
+ goto err;
+ }
+
+ ctx = BN_CTX_new();
+ if (ctx == NULL)
+ {
+ reason = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+
+
+ if (ktype > 0)
+ {
+ public_key = EC_KEY_get0_public_key(x);
+ if ((pub_key = EC_POINT_point2bn(group, public_key,
+ EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
+ {
+ reason = ERR_R_EC_LIB;
+ goto err;
+ }
+ buf_len = (size_t)BN_num_bytes(pub_key);
+ }
+ else
+
+ if (ktype == 2)
+ {
+ if ((i = (size_t)BN_num_bytes(priv_key)) > buf_len)
+ buf_len = i;
+ priv_key = EC_KEY_get0_private_key(x);
+ }
+ else
+ priv_key = NULL;
+
+ if (ktype > 0)
+ {
+ buf_len += 10;
+ if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
+ {
+ reason = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+ }
+ if (ktype == 2)
+ ecstr = "Private-Key";
+ else if (ktype == 1)
+ ecstr = "Public-Key";
+ else
+ ecstr = "ECDSA-Parameters";
+
+ if (!BIO_indent(bp, off, 128))
+ goto err;
+ if ((order = BN_new()) == NULL)
+ goto err;
+ if (!EC_GROUP_get_order(group, order, NULL))
+ goto err;
+ if (BIO_printf(bp, "%s: (%d bit)\n", ecstr,
+ BN_num_bits(order)) <= 0) goto err;
+
+ if ((priv_key != NULL) && !ASN1_bn_print(bp,
"priv:", priv_key,
+ buffer, off))
+ goto err;
+ if ((pub_key != NULL) && !ASN1_bn_print(bp,
"pub: ", pub_key,
+ buffer, off))
+ goto err;
+ if (!ECPKParameters_print(bp, group, off))
+ goto err;
+ ret=1;
+err:
+ if (!ret)
+ ECerr(EC_F_EC_KEY_PRINT, reason);
+ if (pub_key)
+ BN_free(pub_key);
+ if (order)
+ BN_free(order);
+ if (ctx)
+ BN_CTX_free(ctx);
+ if (buffer != NULL)
+ OPENSSL_free(buffer);
+ return(ret);
+ }
+
+static int eckey_param_print(BIO *bp, const EVP_PKEY
*pkey, int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 0);
+ }
+
+static int eckey_pub_print(BIO *bp, const EVP_PKEY *pkey,
int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 1);
+ }
+
+
+static int eckey_priv_print(BIO *bp, const EVP_PKEY
*pkey, int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_EC_KEY_print(bp, pkey->pkey.ec, indent, 2);
+ }
+
EVP_PKEY_ASN1_METHOD eckey_asn1_meth =
{
EVP_PKEY_EC,
 -428,11 +543,11 
eckey_pub_decode,
eckey_pub_encode,
eckey_pub_cmp,
- 0,
+ eckey_pub_print,
eckey_priv_decode,
eckey_priv_encode,
- 0,
+ eckey_priv_print,
int_ec_size,
ec_bits,
 -441,8 +556,257 
ec_missing_parameters,
ec_copy_parameters,
ec_cmp_parameters,
- 0,
+ eckey_param_print,
int_ec_free,
0
};
+
+static int print_bin(BIO *fp, const char *str, const
unsigned char *num,
+ size_t len, int off);
+
+int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int
off)
+ {
+ unsigned char *buffer=NULL;
+ size_t buf_len=0, i;
+ int ret=0, reason=ERR_R_BIO_LIB;
+ BN_CTX *ctx=NULL;
+ const EC_POINT *point=NULL;
+ BIGNUM *p=NULL, *a=NULL, *b=NULL, *gen=NULL,
+ *order=NULL, *cofactor=NULL;
+ const unsigned char *seed;
+ size_t seed_len=0;
+
+ static const char *gen_compressed = "Generator
(compressed):";
+ static const char *gen_uncompressed = "Generator
(uncompressed):";
+ static const char *gen_hybrid = "Generator
(hybrid):";
+
+ if (!x)
+ {
+ reason = ERR_R_PASSED_NULL_PARAMETER;
+ goto err;
+ }
+
+ ctx = BN_CTX_new();
+ if (ctx == NULL)
+ {
+ reason = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+
+ if (EC_GROUP_get_asn1_flag(x))
+ {
+ /* the curve parameter are given by an asn1 OID */
+ int nid;
+
+ if (!BIO_indent(bp, off, 128))
+ goto err;
+
+ nid = EC_GROUP_get_curve_name(x);
+ if (nid == 0)
+ goto err;
+
+ if (BIO_printf(bp, "ASN1 OID: %s",
OBJ_nid2sn(nid)) <= 0)
+ goto err;
+ if (BIO_printf(bp, "\n") <= 0)
+ goto err;
+ }
+ else
+ {
+ /* explicit parameters */
+ int is_char_two = 0;
+ point_conversion_form_t form;
+ int tmp_nid =
EC_METHOD_get_field_type(EC_GROUP_method_of(x));
+
+ if (tmp_nid == NID_X9_62_characteristic_two_field)
+ is_char_two = 1;
+
+ if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
+ (b = BN_new()) == NULL || (order = BN_new()) == NULL
||
+ (cofactor = BN_new()) == NULL)
+ {
+ reason = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+
+ if (is_char_two)
+ {
+ if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx))
+ {
+ reason = ERR_R_EC_LIB;
+ goto err;
+ }
+ }
+ else /* prime field */
+ {
+ if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx))
+ {
+ reason = ERR_R_EC_LIB;
+ goto err;
+ }
+ }
+
+ if ((point = EC_GROUP_get0_generator(x)) == NULL)
+ {
+ reason = ERR_R_EC_LIB;
+ goto err;
+ }
+ if (!EC_GROUP_get_order(x, order, NULL) ||
+ !EC_GROUP_get_cofactor(x, cofactor, NULL))
+ {
+ reason = ERR_R_EC_LIB;
+ goto err;
+ }
+
+ form = EC_GROUP_get_point_conversion_form(x);
+
+ if ((gen = EC_POINT_point2bn(x, point,
+ form, NULL, ctx)) == NULL)
+ {
+ reason = ERR_R_EC_LIB;
+ goto err;
+ }
+
+ buf_len = (size_t)BN_num_bytes(p);
+ if (buf_len < (i = (size_t)BN_num_bytes(a)))
+ buf_len = i;
+ if (buf_len < (i = (size_t)BN_num_bytes(b)))
+ buf_len = i;
+ if (buf_len < (i = (size_t)BN_num_bytes(gen)))
+ buf_len = i;
+ if (buf_len < (i = (size_t)BN_num_bytes(order)))
+ buf_len = i;
+ if (buf_len < (i = (size_t)BN_num_bytes(cofactor)))
+ buf_len = i;
+
+ if ((seed = EC_GROUP_get0_seed(x)) != NULL)
+ seed_len = EC_GROUP_get_seed_len(x);
+
+ buf_len += 10;
+ if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
+ {
+ reason = ERR_R_MALLOC_FAILURE;
+ goto err;
+ }
+
+ if (!BIO_indent(bp, off, 128))
+ goto err;
+
+ /* print the 'short name' of the field type */
+ if (BIO_printf(bp, "Field Type: %s\n",
OBJ_nid2sn(tmp_nid))
+ <= 0)
+ goto err;
+
+ if (is_char_two)
+ {
+ /* print the 'short name' of the base type OID */
+ int basis_type = EC_GROUP_get_basis_type(x);
+ if (basis_type == 0)
+ goto err;
+
+ if (!BIO_indent(bp, off, 128))
+ goto err;
+
+ if (BIO_printf(bp, "Basis Type: %s\n",
+ OBJ_nid2sn(basis_type)) <= 0)
+ goto err;
+
+ /* print the polynomial */
+ if ((p != NULL) && !ASN1_bn_print(bp,
"Polynomial:", p, buffer,
+ off))
+ goto err;
+ }
+ else
+ {
+ if ((p != NULL) && !ASN1_bn_print(bp,
"Prime:", p, buffer,off))
+ goto err;
+ }
+ if ((a != NULL) && !ASN1_bn_print(bp, "A:
", a, buffer, off))
+ goto err;
+ if ((b != NULL) && !ASN1_bn_print(bp, "B:
", b, buffer, off))
+ goto err;
+ if (form == POINT_CONVERSION_COMPRESSED)
+ {
+ if ((gen != NULL) && !ASN1_bn_print(bp,
gen_compressed, gen,
+ buffer, off))
+ goto err;
+ }
+ else if (form == POINT_CONVERSION_UNCOMPRESSED)
+ {
+ if ((gen != NULL) && !ASN1_bn_print(bp,
gen_uncompressed, gen,
+ buffer, off))
+ goto err;
+ }
+ else /* form == POINT_CONVERSION_HYBRID */
+ {
+ if ((gen != NULL) && !ASN1_bn_print(bp,
gen_hybrid, gen,
+ buffer, off))
+ goto err;
+ }
+ if ((order != NULL) && !ASN1_bn_print(bp,
"Order: ", order,
+ buffer, off)) goto err;
+ if ((cofactor != NULL) && !ASN1_bn_print(bp,
"Cofactor: ", cofactor,
+ buffer, off)) goto err;
+ if (seed && !print_bin(bp, "Seed:",
seed, seed_len, off))
+ goto err;
+ }
+ ret=1;
+err:
+ if (!ret)
+ ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
+ if (p)
+ BN_free(p);
+ if (a)
+ BN_free(a);
+ if (b)
+ BN_free(b);
+ if (gen)
+ BN_free(gen);
+ if (order)
+ BN_free(order);
+ if (cofactor)
+ BN_free(cofactor);
+ if (ctx)
+ BN_CTX_free(ctx);
+ if (buffer != NULL)
+ OPENSSL_free(buffer);
+ return(ret);
+ }
+
+static int print_bin(BIO *fp, const char *name, const
unsigned char *buf,
+ size_t len, int off)
+ {
+ size_t i;
+ char str[128];
+
+ if (buf == NULL)
+ return 1;
+ if (off)
+ {
+ if (off > 128)
+ off=128;
+ memset(str,' ',off);
+ if (BIO_write(fp, str, off) <= 0)
+ return 0;
+ }
+
+ if (BIO_printf(fp,"%s", name) <= 0)
+ return 0;
+
+ for (i=0; i<len; i++)
+ {
+ if ((i%15) == 0)
+ {
+ str[0]='\n';
+ memset(&(str[1]),' ',off+4);
+ if (BIO_write(fp, str, off+1+4) <= 0)
+ return 0;
+ }
+ if (BIO_printf(fp,"%02x%s",buf[i],((i+1) ==
len)?"":":") <= 0)
+ return 0;
+ }
+ if (BIO_write(fp,"\n",1) <= 0)
+ return 0;
+
+ return 1;
+ }
 .
patch -p0 <<' .'
Index: openssl/crypto/evp/evp.h
============================================================
================
$ cvs diff -u -r1.116 -r1.117 evp.h
--- openssl/crypto/evp/evp.h 20 Mar 2006 17:56:05
-0000 1.116
+++ openssl/crypto/evp/evp.h 22 Mar 2006 13:09:34
-0000 1.117
 -819,6 +819,13 
int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
+int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
+ int indent, ASN1_PCTX *pctx);
+int EVP_PKEY_print_private(BIO *out, const EVP_PKEY
*pkey,
+ int indent, ASN1_PCTX *pctx);
+int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
+ int indent, ASN1_PCTX *pctx);
+
int EVP_CIPHER_type(const EVP_CIPHER *ctx);
/* calls methods */
 .
patch -p0 <<' .'
Index: openssl/crypto/evp/evp_pkey.c
============================================================
================
$ cvs diff -u -r1.41 -r1.42 evp_pkey.c
--- openssl/crypto/evp/evp_pkey.c 22 Mar 2006 11:26:48
-0000 1.41
+++ openssl/crypto/evp/evp_pkey.c 22 Mar 2006 13:09:34
-0000 1.42
 -69,12 +69,6 
#endif
#include <openssl/bn.h>
-#ifdef FLAT_INC
-#include "asn1_locl.h"
-#else
-#include "../asn1/asn1_locl.h"
-#endif
-
/* Extract a private key from a PKCS8 structure */
EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
 .
patch -p0 <<' .'
Index: openssl/crypto/evp/p_lib.c
============================================================
================
$ cvs diff -u -r1.34 -r1.35 p_lib.c
--- openssl/crypto/evp/p_lib.c 20 Mar 2006 17:56:05
-0000 1.34
+++ openssl/crypto/evp/p_lib.c 22 Mar 2006 13:09:34
-0000 1.35
 -320,3 +320,37 
x->ameth->pkey_free(x);
}
+static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int
indent,
+ const char *kstr)
+ {
+ BIO_indent(out, indent, 128);
+ BIO_printf(out, "%s %s, algorithm,
unsupported\n",
+ OBJ_nid2ln(pkey->type), kstr);
+ return 1;
+ }
+
+int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
+ int indent, ASN1_PCTX *pctx)
+ {
+ if (pkey->ameth &&
pkey->ameth->pub_print)
+ return pkey->ameth->pub_print(out, pkey, indent,
pctx);
+
+ return unsup_alg(out, pkey, indent, "Public
Key");
+ }
+
+int EVP_PKEY_print_private(BIO *out, const EVP_PKEY
*pkey,
+ int indent, ASN1_PCTX *pctx)
+ {
+ if (pkey->ameth &&
pkey->ameth->priv_print)
+ return pkey->ameth->priv_print(out, pkey, indent,
pctx);
+
+ return unsup_alg(out, pkey, indent, "Private
Key");
+ }
+
+int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
+ int indent, ASN1_PCTX *pctx)
+ {
+ if (pkey->ameth &&
pkey->ameth->param_print)
+ return pkey->ameth->param_print(out, pkey,
indent, pctx);
+ return unsup_alg(out, pkey, indent,
"Parameters");
+ }
 .
patch -p0 <<' .'
Index: openssl/crypto/rsa/rsa_ameth.c
============================================================
================
$ cvs diff -u -r1.2 -r1.3 rsa_ameth.c
--- openssl/crypto/rsa/rsa_ameth.c 20 Mar 2006 17:56:05
-0000 1.2
+++ openssl/crypto/rsa/rsa_ameth.c 22 Mar 2006 13:09:35
-0000 1.3
 -153,6 +153,101 
RSA_free(pkey->pkey.rsa);
}
+
+static void update_buflen(const BIGNUM *b, size_t
*pbuflen)
+ {
+ int i;
+ if (!b)
+ return;
+ if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
+ *pbuflen = i;
+ }
+
+static int do_rsa_print(BIO *bp, const RSA *x, int off,
int priv)
+ {
+ char *str;
+ const char *s;
+ unsigned char *m=NULL;
+ int ret=0, mod_len = 0;
+ size_t buf_len=0;
+
+ update_buflen(x->n, &buf_len);
+ update_buflen(x->e, &buf_len);
+
+ if (priv)
+ {
+ update_buflen(x->d, &buf_len);
+ update_buflen(x->p, &buf_len);
+ update_buflen(x->q, &buf_len);
+ update_buflen(x->dmp1, &buf_len);
+ update_buflen(x->dmq1, &buf_len);
+ update_buflen(x->iqmp, &buf_len);
+ }
+
+ m=(unsigned char *)OPENSSL_malloc(buf_len+10);
+ if (m == NULL)
+ {
+ RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ if (x->n != NULL)
+ mod_len = BN_num_bits(x->n);
+
+ if(!BIO_indent(bp,off,128))
+ goto err;
+
+ if (priv && x->d)
+ {
+ if (BIO_printf(bp,"Private-Key: (%d
bit)\n", mod_len)
+ <= 0) goto err;
+ str = "modulus:";
+ s = "publicExponent:";
+ }
+ else
+ {
+ if (BIO_printf(bp,"Public-Key: (%d
bit)\n", mod_len)
+ <= 0) goto err;
+ str = "Modulus:";
+ s= "Exponent:";
+ }
+ if (!ASN1_bn_print(bp,str,x->n,m,off)) goto err;
+ if (!ASN1_bn_print(bp,s,x->e,m,off))
+ goto err;
+ if (priv)
+ {
+ if
(!ASN1_bn_print(bp,"privateExponent:",x->d,m,
off))
+ goto err;
+ if
(!ASN1_bn_print(bp,"prime1:",x->p,m,off))
+ goto err;
+ if
(!ASN1_bn_print(bp,"prime2:",x->q,m,off))
+ goto err;
+ if
(!ASN1_bn_print(bp,"exponent1:",x->dmp1,m,off
))
+ goto err;
+ if
(!ASN1_bn_print(bp,"exponent2:",x->dmq1,m,off
))
+ goto err;
+ if
(!ASN1_bn_print(bp,"coefficient:",x->iqmp,m,o
ff))
+ goto err;
+ }
+ ret=1;
+err:
+ if (m != NULL) OPENSSL_free(m);
+ return(ret);
+ }
+
+static int rsa_pub_print(BIO *bp, const EVP_PKEY *pkey,
int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_rsa_print(bp, pkey->pkey.rsa, indent, 0);
+ }
+
+
+static int rsa_priv_print(BIO *bp, const EVP_PKEY *pkey,
int indent,
+ ASN1_PCTX *ctx)
+ {
+ return do_rsa_print(bp, pkey->pkey.rsa, indent, 1);
+ }
+
const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] =
{
{
 -163,11 +258,11 
rsa_pub_decode,
rsa_pub_encode,
rsa_pub_cmp,
- 0,
+ rsa_pub_print,
rsa_priv_decode,
rsa_priv_encode,
- 0,
+ rsa_priv_print,
int_rsa_size,
rsa_bits,
 .
____________________________________________________________
__________
OpenSSL Project http://www.openssl.org
CVS Repository Commit List
openssl-cvs openssl.org
Automated List Manager
majordomo openssl.org
|