}
if (x->d == NULL)
- sprintf(str,"Modulus (%d bit):",BN_num_bits(x->n));
+ BIO_snprintf(str,sizeof str,"Modulus (%d bit):",BN_num_bits(x->n));
else
- strcpy(str,"modulus:");
+ BUF_strlcpy(str,"modulus:",sizeof str);
if (!print(bp,str,x->n,m,off)) goto err;
s=(x->d == NULL)?"Exponent:":"publicExponent:";
if (!print(bp,s,x->e,m,off)) goto err;
int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
{
- char str[128];
unsigned char *buffer=NULL;
size_t buf_len=0, i;
int ret=0, reason=ERR_R_BIO_LIB;
/* the curve parameter are given by an asn1 OID */
int nid;
- if (off)
- {
- if (off > 128)
- off=128;
- memset(str, ' ', off);
- if (BIO_write(bp, str, off) <= 0)
- goto err;
- }
+ if (!BIO_indent(bp, off, 128))
+ goto err;
nid = EC_GROUP_get_nid(x);
if (nid == 0)
reason = ERR_R_MALLOC_FAILURE;
goto err;
}
- if (off)
- {
- if (off > 128) off=128;
- memset(str,' ',off);
- if (BIO_write(bp, str, off) <= 0)
- 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)
if (basis_type == 0)
goto err;
- if (off)
- {
- if (off > 128) off=128;
- memset(str,' ',off);
- if (BIO_write(bp, str, off) <= 0)
- goto err;
- }
+ if (!BIO_indent(bp, off, 128))
+ goto err;
if (BIO_printf(bp, "Basis Type: %s\n",
OBJ_nid2sn(basis_type)) <= 0)
int EC_KEY_print(BIO *bp, const EC_KEY *x, int off)
{
- char str[128];
unsigned char *buffer=NULL;
size_t buf_len=0, i;
int ret=0, reason=ERR_R_BIO_LIB;
- BIGNUM *pub_key=NULL;
+ BIGNUM *pub_key=NULL, *order=NULL;
BN_CTX *ctx=NULL;
if (!x || !x->group)
reason = ERR_R_MALLOC_FAILURE;
goto err;
}
- if (off)
- {
- if (off > 128) off=128;
- memset(str,' ',off);
- }
+
if (x->priv_key != NULL)
{
- if (off && (BIO_write(bp, str, off) <= 0)) goto err;
+ if (!BIO_indent(bp, off, 128))
+ goto err;
+ if ((order = BN_new()) == NULL)
+ goto err;
+ if (!EC_GROUP_get_order(x->group, order, NULL))
+ goto err;
if (BIO_printf(bp, "Private-Key: (%d bit)\n",
- BN_num_bits(x->priv_key)) <= 0) goto err;
+ BN_num_bits(order)) <= 0) goto err;
}
if ((x->priv_key != NULL) && !print(bp, "priv:", x->priv_key,
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)