您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ASN1_bn_print函数代码示例

51自学网 2021-06-01 19:37:10
  C++
这篇教程C++ ASN1_bn_print函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中ASN1_bn_print函数的典型用法代码示例。如果您正苦于以下问题:C++ ASN1_bn_print函数的具体用法?C++ ASN1_bn_print怎么用?C++ ASN1_bn_print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ASN1_bn_print函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: do_dsa_print

static 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";	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_DO_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);	}
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:59,


示例2: do_dsa_print

static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) {  uint8_t *m = NULL;  int ret = 0;  size_t buf_len = 0;  const char *ktype = NULL;  const BIGNUM *priv_key, *pub_key;  priv_key = NULL;  if (ptype == 2) {    priv_key = x->priv_key;  }  pub_key = NULL;  if (ptype > 0) {    pub_key = x->pub_key;  }  ktype = "DSA-Parameters";  if (ptype == 2) {    ktype = "Private-Key";  } else if (ptype == 1) {    ktype = "Public-Key";  }  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 = (uint8_t *)OPENSSL_malloc(buf_len + 10);  if (m == NULL) {    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);    goto err;  }  if (priv_key) {    if (!BIO_indent(bp, off, 128) ||        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) ||      !ASN1_bn_print(bp, "pub: ", pub_key, m, off) ||      !ASN1_bn_print(bp, "P:   ", x->p, m, off) ||      !ASN1_bn_print(bp, "Q:   ", x->q, m, off) ||      !ASN1_bn_print(bp, "G:   ", x->g, m, off)) {    goto err;  }  ret = 1;err:  OPENSSL_free(m);  return ret;}
开发者ID:bheesham,项目名称:boringssl,代码行数:57,


示例3: dsa_sig_print

static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,                         const ASN1_STRING *sig,                         int indent, ASN1_PCTX *pctx){    DSA_SIG *dsa_sig;    const unsigned char *p;    if (!sig)    {        if (BIO_puts(bp, "/n") <= 0)            return 0;        else            return 1;    }    p = sig->data;    dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);    if (dsa_sig)    {        int rv = 0;        size_t buf_len = 0;        unsigned char *m=NULL;        update_buflen(dsa_sig->r, &buf_len);        update_buflen(dsa_sig->s, &buf_len);        m = OPENSSL_malloc(buf_len+10);        if (m == NULL)        {            DSAerr(DSA_F_DSA_SIG_PRINT,ERR_R_MALLOC_FAILURE);            goto err;        }        if (BIO_write(bp, "/n", 1) != 1)            goto err;        if (!ASN1_bn_print(bp,"r:   ",dsa_sig->r,m,indent))            goto err;        if (!ASN1_bn_print(bp,"s:   ",dsa_sig->s,m,indent))            goto err;        rv = 1;err:        if (m)            OPENSSL_free(m);        DSA_SIG_free(dsa_sig);        return rv;    }    return X509_signature_dump(bp, sig, indent);}
开发者ID:Ashod,项目名称:openssl,代码行数:45,


示例4: do_dsa_print

static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype){    int ret = 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 (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, NULL, off))        goto err;    if (!ASN1_bn_print(bp, "pub: ", pub_key, NULL, off))        goto err;    if (!ASN1_bn_print(bp, "P:   ", x->p, NULL, off))        goto err;    if (!ASN1_bn_print(bp, "Q:   ", x->q, NULL, off))        goto err;    if (!ASN1_bn_print(bp, "G:   ", x->g, NULL, off))        goto err;    ret = 1; err:    return ret;}
开发者ID:akamai,项目名称:openssl,代码行数:45,


示例5: dsa_sig_print

static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,                         const ASN1_STRING *sig, int indent, ASN1_PCTX *pctx) {  DSA_SIG *dsa_sig;  const uint8_t *p;  if (!sig) {    return BIO_puts(bp, "/n") > 0;  }  p = sig->data;  dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);  if (dsa_sig == NULL) {    return X509_signature_dump(bp, sig, indent);  }  int rv = 0;  size_t buf_len = 0;  uint8_t *m = NULL;  update_buflen(dsa_sig->r, &buf_len);  update_buflen(dsa_sig->s, &buf_len);  m = OPENSSL_malloc(buf_len + 10);  if (m == NULL) {    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);    goto err;  }  if (BIO_write(bp, "/n", 1) != 1 ||      !ASN1_bn_print(bp, "r:   ", dsa_sig->r, m, indent) ||      !ASN1_bn_print(bp, "s:   ", dsa_sig->s, m, indent)) {    goto err;  }  rv = 1;err:  OPENSSL_free(m);  DSA_SIG_free(dsa_sig);  return rv;}
开发者ID:bheesham,项目名称:boringssl,代码行数:39,


示例6: dsa_sig_print

static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,                         const ASN1_STRING *sig, int indent, ASN1_PCTX *pctx){    DSA_SIG *dsa_sig;    const unsigned char *p;    if (!sig) {        if (BIO_puts(bp, "/n") <= 0)            return 0;        else            return 1;    }    p = sig->data;    dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);    if (dsa_sig) {        int rv = 0;        const BIGNUM *r, *s;        DSA_SIG_get0(dsa_sig, &r, &s);        if (BIO_write(bp, "/n", 1) != 1)            goto err;        if (!ASN1_bn_print(bp, "r:   ", r, NULL, indent))            goto err;        if (!ASN1_bn_print(bp, "s:   ", s, NULL, indent))            goto err;        rv = 1; err:        DSA_SIG_free(dsa_sig);        return rv;    }    if (BIO_puts(bp, "/n") <= 0)        return 0;    return X509_signature_dump(bp, sig, indent);}
开发者ID:akamai,项目名称:openssl,代码行数:36,


示例7: do_rsa_print

static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv){    char *str;    const char *s;    int ret = 0, mod_len = 0;    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, NULL, off))        goto err;    if (!ASN1_bn_print(bp, s, x->e, NULL, off))        goto err;    if (priv) {        if (!ASN1_bn_print(bp, "privateExponent:", x->d, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "prime1:", x->p, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "prime2:", x->q, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "exponent1:", x->dmp1, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "exponent2:", x->dmq1, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, NULL, off))            goto err;    }    ret = 1; err:    return (ret);}
开发者ID:Astel,项目名称:openssl,代码行数:45,


示例8: do_dh_print

static int do_dh_print(BIO *bp, const DH *x, int indent,                       ASN1_PCTX *ctx, int ptype){    unsigned char *m = NULL;    int reason = ERR_R_BUF_LIB, ret = 0;    size_t buf_len = 0;    const char *ktype = NULL;    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;    update_buflen(x->p, &buf_len);    if (buf_len == 0) {        reason = ERR_R_PASSED_NULL_PARAMETER;        goto err;    }    update_buflen(x->g, &buf_len);    update_buflen(x->q, &buf_len);    update_buflen(x->j, &buf_len);    update_buflen(x->counter, &buf_len);    update_buflen(pub_key, &buf_len);    update_buflen(priv_key, &buf_len);    if (ptype == 2)        ktype = "DH Private-Key";    else if (ptype == 1)        ktype = "DH Public-Key";    else        ktype = "DH Parameters";    m = OPENSSL_malloc(buf_len + 10);    if (m == NULL) {        reason = ERR_R_MALLOC_FAILURE;        goto err;    }    BIO_indent(bp, indent, 128);    if (BIO_printf(bp, "%s: (%d bit)/n", ktype, BN_num_bits(x->p)) <= 0)        goto err;    indent += 4;    if (!ASN1_bn_print(bp, "private-key:", priv_key, m, indent))        goto err;    if (!ASN1_bn_print(bp, "public-key:", pub_key, m, indent))        goto err;    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->q && !ASN1_bn_print(bp, "subgroup order:", x->q, m, indent))        goto err;    if (x->j && !ASN1_bn_print(bp, "subgroup factor:", x->j, m, indent))        goto err;    if (x->seed) {        int i;        BIO_indent(bp, indent, 128);        BIO_puts(bp, "seed:");        for (i = 0; i < x->seedlen; i++) {            if ((i % 15) == 0) {                if (BIO_puts(bp, "/n") <= 0                    || !BIO_indent(bp, indent + 4, 128))                    goto err;            }            if (BIO_printf(bp, "%02x%s", x->seed[i],                           ((i + 1) == x->seedlen) ? "" : ":") <= 0)                goto err;        }        if (BIO_write(bp, "/n", 1) <= 0)            return (0);    }    if (x->counter && !ASN1_bn_print(bp, "counter:", x->counter, 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_DO_DH_PRINT, reason);    }    if (m != NULL)        OPENSSL_free(m);    return (ret);//.........这里部分代码省略.........
开发者ID:Orav,项目名称:kbengine,代码行数:101,


示例9: do_rsa_print

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_DO_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, off))            goto err;    }    ret = 1; err:    if (m != NULL)        OPENSSL_free(m);    return (ret);}
开发者ID:03050903,项目名称:godot,代码行数:69,


示例10: do_dh_print

static int do_dh_print(BIO *bp, const DH *x, int indent,						ASN1_PCTX *ctx, int ptype)	{	unsigned char *m=NULL;	int reason=ERR_R_BUF_LIB,ret=0;	size_t buf_len=0;	const char *ktype = NULL;	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;	update_buflen(x->p, &buf_len);	if (buf_len == 0)		{		reason = ERR_R_PASSED_NULL_PARAMETER;		goto err;		}	update_buflen(x->g, &buf_len);	update_buflen(pub_key, &buf_len);	update_buflen(priv_key, &buf_len);	if (ptype == 2)		ktype = "PKCS#3 DH Private-Key";	else if (ptype == 1)		ktype = "PKCS#3 DH Public-Key";	else		ktype = "PKCS#3 DH Parameters";	m= OPENSSL_malloc(buf_len+10);	if (m == NULL)		{		reason=ERR_R_MALLOC_FAILURE;		goto err;		}	BIO_indent(bp, indent, 128);	if (BIO_printf(bp,"%s: (%d bit)/n", ktype, BN_num_bits(x->p)) <= 0)		goto err;	indent += 4;	if (!ASN1_bn_print(bp,"private-key:",priv_key,m,indent)) goto err;	if (!ASN1_bn_print(bp,"public-key:",pub_key,m,indent)) goto err;	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_DO_DH_PRINT,reason);		}	if (m != NULL) OPENSSL_free(m);	return(ret);	}
开发者ID:002301,项目名称:node,代码行数:74,


示例11: do_EC_KEY_print

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 (public_key != NULL)			{			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);			}		}	if (ktype == 2)		{		priv_key = EC_KEY_get0_private_key(x);		if (priv_key && (i = (size_t)BN_num_bytes(priv_key)) > buf_len)			buf_len = i;		}	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_DO_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);	}
开发者ID:RyunosukeOno,项目名称:rayjack,代码行数:96,


示例12: ECPKParameters_print

//.........这里部分代码省略.........		    !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 = 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)		ECerror(reason);	BN_free(p);	BN_free(a);	BN_free(b);	BN_free(gen);	BN_free(order);	BN_free(cofactor);	BN_CTX_free(ctx);	free(buffer);	return (ret);}
开发者ID:2trill2spill,项目名称:nextgen,代码行数:101,


示例13: do_rsa_print

static int do_rsa_print(BIO *out, const RSA *rsa, int off,                        int include_private) {  char *str;  const char *s;  uint8_t *m = NULL;  int ret = 0, mod_len = 0;  size_t buf_len = 0;  update_buflen(rsa->n, &buf_len);  update_buflen(rsa->e, &buf_len);  if (include_private) {    update_buflen(rsa->d, &buf_len);    update_buflen(rsa->p, &buf_len);    update_buflen(rsa->q, &buf_len);    update_buflen(rsa->dmp1, &buf_len);    update_buflen(rsa->dmq1, &buf_len);    update_buflen(rsa->iqmp, &buf_len);    if (rsa->additional_primes != NULL) {      size_t i;      for (i = 0; i < sk_RSA_additional_prime_num(rsa->additional_primes);           i++) {        const RSA_additional_prime *ap =            sk_RSA_additional_prime_value(rsa->additional_primes, i);        update_buflen(ap->prime, &buf_len);        update_buflen(ap->exp, &buf_len);        update_buflen(ap->coeff, &buf_len);      }    }  }  m = (uint8_t *)OPENSSL_malloc(buf_len + 10);  if (m == NULL) {    OPENSSL_PUT_ERROR(EVP, do_rsa_print, ERR_R_MALLOC_FAILURE);    goto err;  }  if (rsa->n != NULL) {    mod_len = BN_num_bits(rsa->n);  }  if (!BIO_indent(out, off, 128)) {    goto err;  }  if (include_private && rsa->d) {    if (BIO_printf(out, "Private-Key: (%d bit)/nversion: %ld/n", mod_len,                   rsa->version) <= 0) {      goto err;    }    str = "modulus:";    s = "publicExponent:";  } else {    if (BIO_printf(out, "Public-Key: (%d bit)/n", mod_len) <= 0) {      goto err;    }    str = "Modulus:";    s = "Exponent:";  }  if (!ASN1_bn_print(out, str, rsa->n, m, off) ||      !ASN1_bn_print(out, s, rsa->e, m, off)) {    goto err;  }  if (include_private) {    if (!ASN1_bn_print(out, "privateExponent:", rsa->d, m, off) ||        !ASN1_bn_print(out, "prime1:", rsa->p, m, off) ||        !ASN1_bn_print(out, "prime2:", rsa->q, m, off) ||        !ASN1_bn_print(out, "exponent1:", rsa->dmp1, m, off) ||        !ASN1_bn_print(out, "exponent2:", rsa->dmq1, m, off) ||        !ASN1_bn_print(out, "coefficient:", rsa->iqmp, m, off)) {      goto err;    }    if (rsa->additional_primes != NULL &&        sk_RSA_additional_prime_num(rsa->additional_primes) > 0) {      size_t i;      if (BIO_printf(out, "otherPrimeInfos:/n") <= 0) {        goto err;      }      for (i = 0; i < sk_RSA_additional_prime_num(rsa->additional_primes);           i++) {        const RSA_additional_prime *ap =            sk_RSA_additional_prime_value(rsa->additional_primes, i);        if (BIO_printf(out, "otherPrimeInfo (prime %u):/n",                       (unsigned)(i + 3)) <= 0 ||            !ASN1_bn_print(out, "prime:", ap->prime, m, off) ||            !ASN1_bn_print(out, "exponent:", ap->exp, m, off) ||            !ASN1_bn_print(out, "coeff:", ap->coeff, m, off)) {          goto err;        }      }    }  }  ret = 1;//.........这里部分代码省略.........
开发者ID:krunalsoni01,项目名称:src,代码行数:101,


示例14: do_EC_KEY_print

static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) {  uint8_t *buffer = NULL;  const char *ecstr;  size_t buf_len = 0, i;  int ret = 0, reason = ERR_R_BIO_LIB;  BN_CTX *ctx = NULL;  const EC_GROUP *group;  const EC_POINT *public_key;  const BIGNUM *priv_key;  uint8_t *pub_key_bytes = NULL;  size_t pub_key_bytes_len = 0;  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 (public_key != NULL) {      pub_key_bytes_len = EC_POINT_point2oct(          group, public_key, EC_KEY_get_conv_form(x), NULL, 0, ctx);      if (pub_key_bytes_len == 0) {        reason = ERR_R_MALLOC_FAILURE;        goto err;      }      pub_key_bytes = OPENSSL_malloc(pub_key_bytes_len);      if (pub_key_bytes == NULL) {        reason = ERR_R_MALLOC_FAILURE;        goto err;      }      pub_key_bytes_len =          EC_POINT_point2oct(group, public_key, EC_KEY_get_conv_form(x),                             pub_key_bytes, pub_key_bytes_len, ctx);      if (pub_key_bytes_len == 0) {        reason = ERR_R_MALLOC_FAILURE;        goto err;      }      buf_len = pub_key_bytes_len;    }  }  if (ktype == 2) {    priv_key = EC_KEY_get0_private_key(x);    if (priv_key && (i = (size_t)BN_num_bytes(priv_key)) > buf_len) {      buf_len = i;    }  } 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;  }  const BIGNUM *order = EC_GROUP_get0_order(group);  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_bytes != NULL) {    BIO_hexdump(bp, pub_key_bytes, pub_key_bytes_len, off);  }  /* TODO(fork): implement */  /*  if (!ECPKParameters_print(bp, group, off))    goto err; */  ret = 1;err:  if (!ret) {    OPENSSL_PUT_ERROR(EVP, reason);  }  OPENSSL_free(pub_key_bytes);  BN_CTX_free(ctx);  OPENSSL_free(buffer);//.........这里部分代码省略.........
开发者ID:bheesham,项目名称:boringssl,代码行数:101,


示例15: pkey_rsa_print

static int pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv){    const RSA *x = pkey->pkey.rsa;    char *str;    const char *s;    int ret = 0, mod_len = 0, ex_primes;    if (x->n != NULL)        mod_len = BN_num_bits(x->n);    ex_primes = sk_RSA_PRIME_INFO_num(x->prime_infos);    if (!BIO_indent(bp, off, 128))        goto err;    if (BIO_printf(bp, "%s ", pkey_is_pss(pkey) ?  "RSA-PSS" : "RSA") <= 0)        goto err;    if (priv && x->d) {        if (BIO_printf(bp, "Private-Key: (%d bit, %d primes)/n",                       mod_len, ex_primes <= 0 ? 2 : ex_primes + 2) <= 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, NULL, off))        goto err;    if (!ASN1_bn_print(bp, s, x->e, NULL, off))        goto err;    if (priv) {        int i;        if (!ASN1_bn_print(bp, "privateExponent:", x->d, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "prime1:", x->p, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "prime2:", x->q, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "exponent1:", x->dmp1, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "exponent2:", x->dmq1, NULL, off))            goto err;        if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, NULL, off))            goto err;        for (i = 0; i < sk_RSA_PRIME_INFO_num(x->prime_infos); i++) {            /* print multi-prime info */            BIGNUM *bn = NULL;            RSA_PRIME_INFO *pinfo;            int j;            pinfo = sk_RSA_PRIME_INFO_value(x->prime_infos, i);            for (j = 0; j < 3; j++) {                if (!BIO_indent(bp, off, 128))                    goto err;                switch (j) {                case 0:                    if (BIO_printf(bp, "prime%d:", i + 3) <= 0)                        goto err;                    bn = pinfo->r;                    break;                case 1:                    if (BIO_printf(bp, "exponent%d:", i + 3) <= 0)                        goto err;                    bn = pinfo->d;                    break;                case 2:                    if (BIO_printf(bp, "coefficient%d:", i + 3) <= 0)                        goto err;                    bn = pinfo->t;                    break;                default:                    break;                }                if (!ASN1_bn_print(bp, "", bn, NULL, off))                    goto err;            }        }    }    if (pkey_is_pss(pkey) && !rsa_pss_param_print(bp, 1, x->pss, off))        goto err;    ret = 1; err:    return ret;}
开发者ID:Bilibili,项目名称:openssl,代码行数:88,



注:本文中的ASN1_bn_print函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ ASN1_d2i_bio_of函数代码示例
C++ ASN1_TYPE_free函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。