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

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

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

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

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

示例1: pkey_dsa_paramgen

static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey){    DSA *dsa = NULL;    DSA_PKEY_CTX *dctx = ctx->data;    BN_GENCB *pcb;    int ret;    if (ctx->pkey_gencb) {        pcb = BN_GENCB_new();        if (pcb == NULL)            return 0;        evp_pkey_set_cb_translate(pcb, ctx);    } else        pcb = NULL;    dsa = DSA_new();    if (dsa == NULL) {        BN_GENCB_free(pcb);        return 0;    }    ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd,                               NULL, 0, NULL, NULL, NULL, pcb);    BN_GENCB_free(pcb);    if (ret)        EVP_PKEY_assign_DSA(pkey, dsa);    else        DSA_free(dsa);    return ret;}
开发者ID:AlexanderPankiv,项目名称:node,代码行数:27,


示例2: EVP_PKEY_set1_DSA

int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) {  if (EVP_PKEY_assign_DSA(pkey, key)) {    DSA_up_ref(key);    return 1;  }  return 0;}
开发者ID:Cyril2004,项目名称:proto-quic,代码行数:7,


示例3: NativeCrypto_EVP_PKEY_new_DSA

/** * private static native int EVP_PKEY_new_DSA(byte[] p, byte[] q, byte[] g, byte[] pub_key, byte[] priv_key); */static EVP_PKEY* NativeCrypto_EVP_PKEY_new_DSA(JNIEnv* env, jclass clazz, jbyteArray p, jbyteArray q, jbyteArray g, jbyteArray pub_key, jbyteArray priv_key) {    // LOGD("Entering EVP_PKEY_new_DSA()");    DSA* dsa = DSA_new();    dsa->p = arrayToBignum(env, p);    dsa->q = arrayToBignum(env, q);    dsa->g = arrayToBignum(env, g);    dsa->pub_key = arrayToBignum(env, pub_key);    if (priv_key != NULL) {        dsa->priv_key = arrayToBignum(env, priv_key);    }    if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL || dsa->pub_key == NULL) {        DSA_free(dsa);        throwRuntimeException(env, "Unable to convert BigInteger to BIGNUM");        return NULL;    }    EVP_PKEY* pkey = EVP_PKEY_new();    EVP_PKEY_assign_DSA(pkey, dsa);    return pkey;}
开发者ID:llnull,项目名称:platform_dalvik,代码行数:28,


示例4: generate_dsa_key

static EP_STATgenerate_dsa_key(EP_CRYPTO_KEY *key, int keylen){	DSA *dsakey;	// generate new parameter block	dsakey = DSA_new();	if (DSA_generate_parameters_ex(dsakey, keylen,			NULL, 0, NULL, NULL, NULL) != 1)	{		_ep_crypto_error("cannot initialize DSA parameters");		goto fail0;	}	if (DSA_generate_key(dsakey) != 1)	{		_ep_crypto_error("cannot generate DSA key");		goto fail0;	}	if (EVP_PKEY_assign_DSA(key, dsakey) != 1)	{		_ep_crypto_error("cannot save DSA key");		goto fail0;	}	return EP_STAT_OK;fail0:	return EP_STAT_CRYPTO_KEYCREATE;}
开发者ID:jugador87,项目名称:gdp,代码行数:30,


示例5: EVP_PKEY_set1_DSA

int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key){	int ret = EVP_PKEY_assign_DSA(pkey, key);	if(ret)		DSA_up_ref(key);	return ret;}
开发者ID:1310701102,项目名称:sl4a,代码行数:7,


示例6: old_dsa_priv_decode

static intold_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen){	DSA *dsa;	BN_CTX *ctx = NULL;	BIGNUM *j, *p1, *newp1;	if (!(dsa = d2i_DSAPrivateKey(NULL, pder, derlen))) {		DSAerror(ERR_R_DSA_LIB);		return 0;	}	ctx = BN_CTX_new();	if (ctx == NULL)		goto err;	/*	 * Check that p and q are consistent with each other.	 */	j = BN_CTX_get(ctx);	p1 = BN_CTX_get(ctx);	newp1 = BN_CTX_get(ctx);	if (j == NULL || p1 == NULL || newp1 == NULL)		goto err;	/* p1 = p - 1 */	if (BN_sub(p1, dsa->p, BN_value_one()) == 0)		goto err;	/* j = (p - 1) / q */	if (BN_div_ct(j, NULL, p1, dsa->q, ctx) == 0)		goto err;	/* q * j should == p - 1 */	if (BN_mul(newp1, dsa->q, j, ctx) == 0)		goto err;	if (BN_cmp(newp1, p1) != 0) {		DSAerror(DSA_R_BAD_Q_VALUE);		goto err;	}	/*	 * Check that q is not a composite number.	 */	if (BN_is_prime_ex(dsa->q, BN_prime_checks, ctx, NULL) <= 0) {		DSAerror(DSA_R_BAD_Q_VALUE);		goto err;	}	BN_CTX_free(ctx);	EVP_PKEY_assign_DSA(pkey, dsa);	return 1; err:	BN_CTX_free(ctx);	DSA_free(dsa);	return 0;}
开发者ID:libressl-portable,项目名称:openbsd,代码行数:58,


示例7: dsa_pub_decode

static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) {  const uint8_t *p, *pm;  int pklen, pmlen;  int ptype;  void *pval;  ASN1_STRING *pstr;  X509_ALGOR *palg;  ASN1_INTEGER *public_key = NULL;  DSA *dsa = NULL;  if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey)) {    return 0;  }  X509_ALGOR_get0(NULL, &ptype, &pval, palg);  if (ptype == V_ASN1_SEQUENCE) {    pstr = pval;    pm = pstr->data;    pmlen = pstr->length;    dsa = d2i_DSAparams(NULL, &pm, pmlen);    if (dsa == NULL) {      OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);      goto err;    }  } else if (ptype == V_ASN1_NULL || ptype == V_ASN1_UNDEF) {    dsa = DSA_new();    if (dsa == NULL) {      OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);      goto err;    }  } else {    OPENSSL_PUT_ERROR(EVP, EVP_R_PARAMETER_ENCODING_ERROR);    goto err;  }  public_key = d2i_ASN1_INTEGER(NULL, &p, pklen);  if (public_key == NULL) {    OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);    goto err;  }  dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL);  if (dsa->pub_key == NULL) {    OPENSSL_PUT_ERROR(EVP, EVP_R_BN_DECODE_ERROR);    goto err;  }  ASN1_INTEGER_free(public_key);  EVP_PKEY_assign_DSA(pkey, dsa);  return 1;err:  ASN1_INTEGER_free(public_key);  DSA_free(dsa);  return 0;}
开发者ID:bheesham,项目名称:boringssl,代码行数:58,


示例8: dsa_pub_decode

static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey){    const unsigned char *p, *pm;    int pklen, pmlen;    int ptype;    void *pval;    ASN1_STRING *pstr;    X509_ALGOR *palg;    ASN1_INTEGER *public_key = NULL;    DSA *dsa = NULL;    if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))        return 0;    X509_ALGOR_get0(NULL, &ptype, &pval, palg);    if (ptype == V_ASN1_SEQUENCE) {        pstr = pval;        pm = pstr->data;        pmlen = pstr->length;        if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) {            DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);            goto err;        }    } else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF)) {        if (!(dsa = DSA_new())) {            DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE);            goto err;        }    } else {        DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR);        goto err;    }    if (!(public_key = d2i_ASN1_INTEGER(NULL, &p, pklen))) {        DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);        goto err;    }    if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) {        DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR);        goto err;    }    ASN1_INTEGER_free(public_key);    EVP_PKEY_assign_DSA(pkey, dsa);    return 1; err:    if (public_key)        ASN1_INTEGER_free(public_key);    if (dsa)        DSA_free(dsa);    return 0;}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:58,


示例9: dsa_param_decode

static int dsa_param_decode(EVP_PKEY *pkey, const uint8_t **pder, int derlen) {  DSA *dsa;  dsa = d2i_DSAparams(NULL, pder, derlen);  if (dsa == NULL) {    OPENSSL_PUT_ERROR(EVP, ERR_R_DSA_LIB);    return 0;  }  EVP_PKEY_assign_DSA(pkey, dsa);  return 1;}
开发者ID:bheesham,项目名称:boringssl,代码行数:10,


示例10: old_dsa_priv_decode

static int old_dsa_priv_decode(EVP_PKEY *pkey, const uint8_t **pder,                               int derlen) {  DSA *dsa;  dsa = d2i_DSAPrivateKey(NULL, pder, derlen);  if (dsa == NULL) {    OPENSSL_PUT_ERROR(EVP, old_dsa_priv_decode, ERR_R_DSA_LIB);    return 0;  }  EVP_PKEY_assign_DSA(pkey, dsa);  return 1;}
开发者ID:krunalsoni01,项目名称:src,代码行数:11,


示例11: old_dsa_priv_decode

static int old_dsa_priv_decode(EVP_PKEY *pkey,                               const unsigned char **pder, int derlen){    DSA *dsa;    if (!(dsa = d2i_DSAPrivateKey(NULL, pder, derlen))) {        DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB);        return 0;    }    EVP_PKEY_assign_DSA(pkey, dsa);    return 1;}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:11,


示例12: dsa_param_decode

static int dsa_param_decode(EVP_PKEY *pkey,                            const unsigned char **pder, int derlen){    DSA *dsa;    if (!(dsa = d2i_DSAparams(NULL, pder, derlen))) {        DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB);        return 0;    }    EVP_PKEY_assign_DSA(pkey, dsa);    return 1;}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:11,


示例13: switch

void pki_evp::generate(int bits, int type, QProgressBar *progress, int curve_nid){	RSA *rsakey;	DSA *dsakey;	EC_KEY *eckey;	progress->setMinimum(0);	progress->setMaximum(100);	progress->setValue(50);	switch (type) {	case EVP_PKEY_RSA:		rsakey = RSA_generate_key(bits, 0x10001, inc_progress_bar,			progress);		if (rsakey)			EVP_PKEY_assign_RSA(key, rsakey);		break;	case EVP_PKEY_DSA:		progress->setMaximum(500);		dsakey = DSA_generate_parameters(bits, NULL, 0, NULL, NULL,				inc_progress_bar, progress);		DSA_generate_key(dsakey);		if (dsakey)			EVP_PKEY_assign_DSA(key, dsakey);		break;	case EVP_PKEY_EC:		EC_GROUP *group = EC_GROUP_new_by_curve_name(curve_nid);		if (!group)			break;		eckey = EC_KEY_new();		if (eckey == NULL) {			EC_GROUP_free(group);			break;		}		EC_GROUP_set_asn1_flag(group, 1);		if (EC_KEY_set_group(eckey, group)) {			if (EC_KEY_generate_key(eckey)) {				EVP_PKEY_assign_EC_KEY(key, eckey);				EC_GROUP_free(group);				break;			}		}		EC_KEY_free(eckey);		EC_GROUP_free(group);		break;	}	pki_openssl_error();	encryptKey();}
开发者ID:J-Javan,项目名称:xca,代码行数:49,


示例14: generate_dsa_keypair

static int generate_dsa_keypair(EVP_PKEY* pkey, const keymaster_dsa_keygen_params_t* dsa_params) {    if (dsa_params->key_size < 512) {        ALOGI("Requested DSA key size is too small (<512)");        return -1;    }    Unique_DSA dsa(DSA_new());    if (dsa_params->generator_len == 0 || dsa_params->prime_p_len == 0 ||        dsa_params->prime_q_len == 0 || dsa_params->generator == NULL ||        dsa_params->prime_p == NULL || dsa_params->prime_q == NULL) {        if (DSA_generate_parameters_ex(dsa.get(), dsa_params->key_size, NULL, 0, NULL, NULL,                                       NULL) != 1) {            logOpenSSLError("generate_dsa_keypair");            return -1;        }    } else {        dsa->g = BN_bin2bn(dsa_params->generator, dsa_params->generator_len, NULL);        if (dsa->g == NULL) {            logOpenSSLError("generate_dsa_keypair");            return -1;        }        dsa->p = BN_bin2bn(dsa_params->prime_p, dsa_params->prime_p_len, NULL);        if (dsa->p == NULL) {            logOpenSSLError("generate_dsa_keypair");            return -1;        }        dsa->q = BN_bin2bn(dsa_params->prime_q, dsa_params->prime_q_len, NULL);        if (dsa->q == NULL) {            logOpenSSLError("generate_dsa_keypair");            return -1;        }    }    if (DSA_generate_key(dsa.get()) != 1) {        logOpenSSLError("generate_dsa_keypair");        return -1;    }    if (EVP_PKEY_assign_DSA(pkey, dsa.get()) == 0) {        logOpenSSLError("generate_dsa_keypair");        return -1;    }    release_because_ownership_transferred(dsa);    return 0;}
开发者ID:LordNerevar,项目名称:system_security,代码行数:49,


示例15: pkey_dsa_keygen

static int pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey){    DSA *dsa = NULL;    if (ctx->pkey == NULL) {        DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET);        return 0;    }    dsa = DSA_new();    if (dsa == NULL)        return 0;    EVP_PKEY_assign_DSA(pkey, dsa);    /* Note: if error return, pkey is freed by parent routine */    if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey))        return 0;    return DSA_generate_key(pkey->pkey.dsa);}
开发者ID:AlexanderPankiv,项目名称:node,代码行数:16,


示例16: isns_dsa_decode_public

EVP_PKEY *isns_dsa_decode_public(const void *ptr, size_t len){	const unsigned char *der = ptr;	EVP_PKEY *evp;	DSA	*dsa;	/* Assigning ptr to a temporary variable avoids a silly	 * compiled warning about type-punning. */	dsa = d2i_DSA_PUBKEY(NULL, &der, len);	if (dsa == NULL)		return NULL;	evp = EVP_PKEY_new();	EVP_PKEY_assign_DSA(evp, dsa);	return evp;}
开发者ID:open-iscsi,项目名称:open-isns,代码行数:17,


示例17: dsa_create_pkey

/*! * /brief Create DSA private key from key parameters. * /see rsa_create_pkey */static int dsa_create_pkey(const knot_key_params_t *params, EVP_PKEY *key){	assert(key);	DSA *dsa = DSA_new();	if (dsa == NULL)		return KNOT_ENOMEM;	dsa->p        = knot_b64_to_bignum(params->prime);	dsa->q        = knot_b64_to_bignum(params->subprime);	dsa->g        = knot_b64_to_bignum(params->base);	dsa->priv_key = knot_b64_to_bignum(params->private_value);	dsa->pub_key  = knot_b64_to_bignum(params->public_value);	if (!EVP_PKEY_assign_DSA(key, dsa)) {		DSA_free(dsa);		return KNOT_DNSSEC_EASSIGN_KEY;	}	return KNOT_EOK;}
开发者ID:stribika,项目名称:curveprotect,代码行数:25,


示例18: EVP_PKEY_new

static EVP_PKEY *old_priv_decode(CBS *cbs, int type) {  EVP_PKEY *ret = EVP_PKEY_new();  if (ret == NULL) {    return NULL;  }  switch (type) {    case EVP_PKEY_EC: {      EC_KEY *ec_key = EC_KEY_parse_private_key(cbs, NULL);      if (ec_key == NULL || !EVP_PKEY_assign_EC_KEY(ret, ec_key)) {        EC_KEY_free(ec_key);        goto err;      }      return ret;    }    case EVP_PKEY_DSA: {      DSA *dsa = DSA_parse_private_key(cbs);      if (dsa == NULL || !EVP_PKEY_assign_DSA(ret, dsa)) {        DSA_free(dsa);        goto err;      }      return ret;    }    case EVP_PKEY_RSA: {      RSA *rsa = RSA_parse_private_key(cbs);      if (rsa == NULL || !EVP_PKEY_assign_RSA(ret, rsa)) {        RSA_free(rsa);        goto err;      }      return ret;    }    default:      OPENSSL_PUT_ERROR(EVP, EVP_R_UNKNOWN_PUBLIC_KEY_TYPE);      goto err;  }err:  EVP_PKEY_free(ret);  return NULL;}
开发者ID:AadityaDev,项目名称:AadityaDev.github.io,代码行数:40,


示例19: FIPS_selftest_dsa

int FIPS_selftest_dsa(){    DSA *dsa = NULL;    EVP_PKEY *pk = NULL;    int ret = 0;    dsa = DSA_new();    if (dsa == NULL)        goto err;    fips_load_key_component(dsa, p, dsa_test_2048);    fips_load_key_component(dsa, q, dsa_test_2048);    fips_load_key_component(dsa, g, dsa_test_2048);    fips_load_key_component(dsa, pub_key, dsa_test_2048);    fips_load_key_component(dsa, priv_key, dsa_test_2048);    if (corrupt_dsa)        BN_set_bit(dsa->pub_key, 2047);    if ((pk = EVP_PKEY_new()) == NULL)        goto err;    EVP_PKEY_assign_DSA(pk, dsa);    if (!fips_pkey_signature_test(pk, NULL, 0,                                  NULL, 0, EVP_sha256(), 0, "DSA SHA256"))        goto err;    ret = 1; err:    if (pk)        EVP_PKEY_free(pk);    else if (dsa)        DSA_free(dsa);    return ret;}
开发者ID:davidlt,项目名称:openssl-fedora,代码行数:37,


示例20: isns_dsa_generate_key

/* * DSA key generation */EVP_PKEY *isns_dsa_generate_key(void){	EVP_PKEY *pkey;	DSA	*dsa = NULL;	if (!(dsa = isns_dsa_load_params(isns_config.ic_dsa.param_file)))		goto failed;	if (!DSA_generate_key(dsa)) {		isns_dsasig_report_errors("Failed to generate DSA key",				isns_error);		goto failed;	}	pkey = EVP_PKEY_new();	EVP_PKEY_assign_DSA(pkey, dsa);	return pkey;failed:	if (dsa)		DSA_free(dsa);	return NULL;}
开发者ID:open-iscsi,项目名称:open-isns,代码行数:27,


示例21: CAPIerr

//.........这里部分代码省略.........		rkey = RSA_new_method(eng);		if (!rkey)			goto memerr;		rkey->e = BN_new();		rkey->n = BN_new();		if (!rkey->e || !rkey->n)			goto memerr;		if (!BN_set_word(rkey->e, rp->pubexp))			goto memerr;		rsa_modlen = rp->bitlen / 8;		if (!lend_tobn(rkey->n, rsa_modulus, rsa_modlen))			goto memerr;		RSA_set_ex_data(rkey, rsa_capi_idx, key);		if (!(ret = EVP_PKEY_new()))			goto memerr;		EVP_PKEY_assign_RSA(ret, rkey);		rkey = NULL;		}	else if (bh->aiKeyAlg == CALG_DSS_SIGN)		{		DSSPUBKEY *dp;		DWORD dsa_plen;		unsigned char *btmp;		dp = (DSSPUBKEY *)(bh + 1);		if (dp->magic != 0x31535344)			{			char magstr[10];			BIO_snprintf(magstr, 10, "%lx", dp->magic);			CAPIerr(CAPI_F_CAPI_GET_PKEY, CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER);			ERR_add_error_data(2, "magic=0x", magstr);			goto err;			}		dsa_plen = dp->bitlen / 8;		btmp = (unsigned char *)(dp + 1);		dkey = DSA_new_method(eng);		if (!dkey)			goto memerr;		dkey->p = BN_new();		dkey->q = BN_new();		dkey->g = BN_new();		dkey->pub_key = BN_new();		if (!dkey->p || !dkey->q || !dkey->g || !dkey->pub_key)			goto memerr;		if (!lend_tobn(dkey->p, btmp, dsa_plen))			goto memerr;		btmp += dsa_plen;		if (!lend_tobn(dkey->q, btmp, 20))			goto memerr;		btmp += 20;		if (!lend_tobn(dkey->g, btmp, dsa_plen))			goto memerr;		btmp += dsa_plen;		if (!lend_tobn(dkey->pub_key, btmp, dsa_plen))			goto memerr;		btmp += dsa_plen;		DSA_set_ex_data(dkey, dsa_capi_idx, key);		if (!(ret = EVP_PKEY_new()))			goto memerr;		EVP_PKEY_assign_DSA(ret, dkey);		dkey = NULL;		}	else		{		char algstr[10];		BIO_snprintf(algstr, 10, "%lx", bh->aiKeyAlg);		CAPIerr(CAPI_F_CAPI_GET_PKEY, CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM);		ERR_add_error_data(2, "aiKeyAlg=0x", algstr);		goto err;		}	err:	if (pubkey)		OPENSSL_free(pubkey);	if (!ret)		{		if (rkey)			RSA_free(rkey);		if (dkey)			DSA_free(dkey);		}	return ret;memerr:	CAPIerr(CAPI_F_CAPI_GET_PKEY, ERR_R_MALLOC_FAILURE);	goto err;	}
开发者ID:Groestlcoin,项目名称:foreign,代码行数:101,


示例22: setup_key_digest

/** * Setup key and digest for verification. Adjust sig if necessary. * * @param algo: key algorithm * @param evp_key: EVP PKEY public key to create. * @param digest_type: digest type to use * @param key: key to setup for. * @param keylen: length of key. * @return false on failure. */static intsetup_key_digest(int algo, EVP_PKEY** evp_key, const EVP_MD** digest_type, 	unsigned char* key, size_t keylen){#if defined(USE_DSA) && defined(USE_SHA1)	DSA* dsa;#endif	RSA* rsa;	switch(algo) {#if defined(USE_DSA) && defined(USE_SHA1)		case LDNS_DSA:		case LDNS_DSA_NSEC3:			*evp_key = EVP_PKEY_new();			if(!*evp_key) {				log_err("verify: malloc failure in crypto");				return 0;			}			dsa = sldns_key_buf2dsa_raw(key, keylen);			if(!dsa) {				verbose(VERB_QUERY, "verify: "					"sldns_key_buf2dsa_raw failed");				return 0;			}			if(EVP_PKEY_assign_DSA(*evp_key, dsa) == 0) {				verbose(VERB_QUERY, "verify: "					"EVP_PKEY_assign_DSA failed");				return 0;			}#ifdef HAVE_EVP_DSS1			*digest_type = EVP_dss1();#else			*digest_type = EVP_sha1();#endif			break;#endif /* USE_DSA && USE_SHA1 */#if defined(USE_SHA1) || (defined(HAVE_EVP_SHA256) && defined(USE_SHA2)) || (defined(HAVE_EVP_SHA512) && defined(USE_SHA2))#ifdef USE_SHA1		case LDNS_RSASHA1:		case LDNS_RSASHA1_NSEC3:#endif#if defined(HAVE_EVP_SHA256) && defined(USE_SHA2)		case LDNS_RSASHA256:#endif#if defined(HAVE_EVP_SHA512) && defined(USE_SHA2)		case LDNS_RSASHA512:#endif			*evp_key = EVP_PKEY_new();			if(!*evp_key) {				log_err("verify: malloc failure in crypto");				return 0;			}			rsa = sldns_key_buf2rsa_raw(key, keylen);			if(!rsa) {				verbose(VERB_QUERY, "verify: "					"sldns_key_buf2rsa_raw SHA failed");				return 0;			}			if(EVP_PKEY_assign_RSA(*evp_key, rsa) == 0) {				verbose(VERB_QUERY, "verify: "					"EVP_PKEY_assign_RSA SHA failed");				return 0;			}			/* select SHA version */#if defined(HAVE_EVP_SHA256) && defined(USE_SHA2)			if(algo == LDNS_RSASHA256)				*digest_type = EVP_sha256();			else#endif#if defined(HAVE_EVP_SHA512) && defined(USE_SHA2)				if(algo == LDNS_RSASHA512)				*digest_type = EVP_sha512();			else#endif#ifdef USE_SHA1				*digest_type = EVP_sha1();#else				{ verbose(VERB_QUERY, "no digest available"); return 0; }#endif			break;#endif /* defined(USE_SHA1) || (defined(HAVE_EVP_SHA256) && defined(USE_SHA2)) || (defined(HAVE_EVP_SHA512) && defined(USE_SHA2)) */		case LDNS_RSAMD5:			*evp_key = EVP_PKEY_new();			if(!*evp_key) {				log_err("verify: malloc failure in crypto");				return 0;//.........这里部分代码省略.........
开发者ID:k0nsl,项目名称:unbound,代码行数:101,


示例23: STACK_OF

//.........这里部分代码省略.........    }    if (!param || (param->type != V_ASN1_SEQUENCE)) {      EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);      goto dsaerr;    }    cp = p = param->value.sequence->data;    plen = param->value.sequence->length;    if (!(dsa = d2i_DSAparams (NULL, &cp, plen))) {      EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);      goto dsaerr;    }    /* We have parameters now set private key */    if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {      EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);      goto dsaerr;    }    /* Calculate public key (ouch!) */    if (!(dsa->pub_key = BN_new())) {      EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);      goto dsaerr;    }    if (!(ctx = BN_CTX_new())) {      EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);      goto dsaerr;    }          if (!BN_mod_exp(dsa->pub_key, dsa->g,             dsa->priv_key, dsa->p, ctx)) {            EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);      goto dsaerr;    }    EVP_PKEY_assign_DSA(pkey, dsa);    BN_CTX_free (ctx);    if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);    else ASN1_INTEGER_free(privkey);    break;    dsaerr:    BN_CTX_free (ctx);    sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);    DSA_free(dsa);    EVP_PKEY_free(pkey);    return NULL;    break;#endif#ifndef OPENSSL_NO_EC    case NID_X9_62_id_ecPublicKey:    p_tmp = p;    /* extract the ec parameters */    param = p8->pkeyalg->parameter;    if (!param || ((param->type != V_ASN1_SEQUENCE) &&        (param->type != V_ASN1_OBJECT)))    {      EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);      goto ecerr;    }    if (param->type == V_ASN1_SEQUENCE)    {      cp = p = param->value.sequence->data;      plen = param->value.sequence->length;      if (!(eckey = d2i_ECParameters(NULL, &cp, plen)))      {
开发者ID:yyyyyao,项目名称:Slicer3-lib-mirrors,代码行数:67,


示例24: dsa_priv_decode

static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8){    const unsigned char *p, *pm;    int pklen, pmlen;    int ptype;    void *pval;    ASN1_STRING *pstr;    X509_ALGOR *palg;    ASN1_INTEGER *privkey = NULL;    BN_CTX *ctx = NULL;    STACK_OF(ASN1_TYPE) *ndsa = NULL;    DSA *dsa = NULL;    if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))        return 0;    X509_ALGOR_get0(NULL, &ptype, &pval, palg);    /* Check for broken DSA PKCS#8, UGH! */    if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))    {        ASN1_TYPE *t1, *t2;        if(!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen)))            goto decerr;        if (sk_ASN1_TYPE_num(ndsa) != 2)            goto decerr;        /* Handle Two broken types:        	 * SEQUENCE {parameters, priv_key}         * SEQUENCE {pub_key, priv_key}         */        t1 = sk_ASN1_TYPE_value(ndsa, 0);        t2 = sk_ASN1_TYPE_value(ndsa, 1);        if (t1->type == V_ASN1_SEQUENCE)        {            p8->broken = PKCS8_EMBEDDED_PARAM;            pval = t1->value.ptr;        }        else if (ptype == V_ASN1_SEQUENCE)            p8->broken = PKCS8_NS_DB;        else            goto decerr;        if (t2->type != V_ASN1_INTEGER)            goto decerr;        privkey = t2->value.integer;    }    else    {        const unsigned char *q = p;        if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen)))            goto decerr;        if (privkey->type == V_ASN1_NEG_INTEGER)        {            p8->broken = PKCS8_NEG_PRIVKEY;            ASN1_INTEGER_free(privkey);            if (!(privkey=d2i_ASN1_UINTEGER(NULL, &q, pklen)))                goto decerr;        }        if (ptype != V_ASN1_SEQUENCE)            goto decerr;    }    pstr = pval;    pm = pstr->data;    pmlen = pstr->length;    if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen)))        goto decerr;    /* We have parameters now set private key */    if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)))    {        DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);        goto dsaerr;    }    /* Calculate public key */    if (!(dsa->pub_key = BN_new()))    {        DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);        goto dsaerr;    }    if (!(ctx = BN_CTX_new()))    {        DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);        goto dsaerr;    }    if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx))    {        DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);        goto dsaerr;    }    EVP_PKEY_assign_DSA(pkey, dsa);    BN_CTX_free (ctx);    if(ndsa)        sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);    else        ASN1_INTEGER_free(privkey);//.........这里部分代码省略.........
开发者ID:Ashod,项目名称:openssl,代码行数:101,


示例25: sureware_load_public

static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype){    EVP_PKEY *res = NULL;#ifndef OPENSSL_NO_RSA    RSA *rsatmp = NULL;#endif#ifndef OPENSSL_NO_DSA    DSA *dsatmp=NULL;#endif    char msg[64]="sureware_load_public";    int ret=0;    if(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey)    {        SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_NOT_INITIALISED);        goto err;    }    switch (keytype)    {#ifndef OPENSSL_NO_RSA    case 1: /*RSA*/        /* set private external reference */        rsatmp = RSA_new_method(e);        RSA_set_ex_data(rsatmp,rsaHndidx,hptr);        rsatmp->flags |= RSA_FLAG_EXT_PKEY;        /* set public big nums*/        rsatmp->e = BN_new();        rsatmp->n = BN_new();        bn_expand2(rsatmp->e, el/sizeof(BN_ULONG));        bn_expand2(rsatmp->n, el/sizeof(BN_ULONG));        if (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))||                !rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG)))            goto err;        ret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el,                                         (unsigned long *)rsatmp->n->d,                                         (unsigned long *)rsatmp->e->d);        surewarehk_error_handling(msg,SUREWARE_F_SUREWARE_LOAD_PUBLIC,ret);        if (ret!=1)        {            SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);            goto err;        }        /* normalise pub e and pub n */        rsatmp->e->top=el/sizeof(BN_ULONG);        bn_fix_top(rsatmp->e);        rsatmp->n->top=el/sizeof(BN_ULONG);        bn_fix_top(rsatmp->n);        /* create an EVP object: engine + rsa key */        res = EVP_PKEY_new();        EVP_PKEY_assign_RSA(res, rsatmp);        break;#endif#ifndef OPENSSL_NO_DSA    case 2:/*DSA*/        /* set private/public external reference */        dsatmp = DSA_new_method(e);        DSA_set_ex_data(dsatmp,dsaHndidx,hptr);        /*dsatmp->flags |= DSA_FLAG_EXT_PKEY;*/        /* set public key*/        dsatmp->pub_key = BN_new();        dsatmp->p = BN_new();        dsatmp->q = BN_new();        dsatmp->g = BN_new();        bn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG));        bn_expand2(dsatmp->p, el/sizeof(BN_ULONG));        bn_expand2(dsatmp->q, 20/sizeof(BN_ULONG));        bn_expand2(dsatmp->g, el/sizeof(BN_ULONG));        if (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))||                !dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) ||                !dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) ||                !dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG)))            goto err;        ret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el,                                         (unsigned long *)dsatmp->pub_key->d,                                         (unsigned long *)dsatmp->p->d,                                         (unsigned long *)dsatmp->q->d,                                         (unsigned long *)dsatmp->g->d);        surewarehk_error_handling(msg,SUREWARE_F_SUREWARE_LOAD_PUBLIC,ret);        if (ret!=1)        {            SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);            goto err;        }        /* set parameters */        /* normalise pubkey and parameters in case of */        dsatmp->pub_key->top=el/sizeof(BN_ULONG);        bn_fix_top(dsatmp->pub_key);        dsatmp->p->top=el/sizeof(BN_ULONG);        bn_fix_top(dsatmp->p);        dsatmp->q->top=20/sizeof(BN_ULONG);        bn_fix_top(dsatmp->q);        dsatmp->g->top=el/sizeof(BN_ULONG);        bn_fix_top(dsatmp->g);        /* create an EVP object: engine + rsa key */        res = EVP_PKEY_new();        EVP_PKEY_assign_DSA(res, dsatmp);//.........这里部分代码省略.........
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,


示例26: ERR_clear_error

//.........这里部分代码省略.........			RSA_free(rsa_key);			goto end;		}		EVP_PKEY_assign_RSA(key_ptr, rsa_key);	}	else	{		// DSA key		DSA* dsa_key;		dsa_key = DSA_generate_parameters(signatureKeyLengthM, NULL, 0, NULL, NULL, NULL, 0);		if (dsa_key == NULL)		{			openSsl_ptr->printError(logger_ptr, LOG_ERROR, "generating DSA parameters");			goto end;		}		if (DSA_generate_key(dsa_key) == 0)		{			openSsl_ptr->printError(logger_ptr, LOG_ERROR, "generating DSA key");			DSA_free(dsa_key);			goto end;		}		key_ptr = EVP_PKEY_new();		if (key_ptr == NULL)		{			openSsl_ptr->printError(logger_ptr, LOG_ERROR, "creating DSA key");			DSA_free(dsa_key);			goto end;		}		EVP_PKEY_assign_DSA(key_ptr, dsa_key);	}	// create the certificate	cert_ptr = X509_new();	if (cert_ptr == NULL)	{		openSsl_ptr->printError(logger_ptr, LOG_ERROR, "creating certificate object");		goto end;	}	// version	if (X509_set_version(cert_ptr, (versionM - 1)) != 1)	{		openSsl_ptr->printError(logger_ptr, LOG_ERROR, "setting certificate version");		goto end;	}	// subject	name_ptr = openSsl_ptr->onelineName2Name(subjectM.c_str());	if (name_ptr == NULL)	{		openSsl_ptr->printError(logger_ptr, LOG_ERROR, "parsing owner name");		goto end;	}	if (X509_set_subject_name(cert_ptr, name_ptr) != 1)	{		openSsl_ptr->printError(logger_ptr, LOG_ERROR, "setting owner name in certificate");		goto end;	}	// issuer
开发者ID:151706061,项目名称:DVTK-1,代码行数:67,


示例27: STACK_OF

//.........这里部分代码省略.........		 * be recalculated.		 */			/* Check for broken DSA PKCS#8, UGH! */		if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {		    if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen, 							  d2i_ASN1_TYPE,							  ASN1_TYPE_free))) {			EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);			goto dsaerr;		    }		    if(sk_ASN1_TYPE_num(ndsa) != 2 ) {			EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);			goto dsaerr;		    }		    /* Handle Two broken types:		     * SEQUENCE {parameters, priv_key}		     * SEQUENCE {pub_key, priv_key}		     */		    t1 = sk_ASN1_TYPE_value(ndsa, 0);		    t2 = sk_ASN1_TYPE_value(ndsa, 1);		    if(t1->type == V_ASN1_SEQUENCE) {			p8->broken = PKCS8_EMBEDDED_PARAM;			param = t1;		    } else if(a->parameter->type == V_ASN1_SEQUENCE) {			p8->broken = PKCS8_NS_DB;			param = a->parameter;		    } else {			EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);			goto dsaerr;		    }		    if(t2->type != V_ASN1_INTEGER) {			EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);			goto dsaerr;		    }		    privkey = t2->value.integer;		} else {			if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {				EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);				goto dsaerr;			}			param = p8->pkeyalg->parameter;		}		if (!param || (param->type != V_ASN1_SEQUENCE)) {			EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);			goto dsaerr;		}		p = param->value.sequence->data;		plen = param->value.sequence->length;		if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {			EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);			goto dsaerr;		}		/* We have parameters now set private key */		if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {			EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);			goto dsaerr;		}		/* Calculate public key (ouch!) */		if (!(dsa->pub_key = BN_new())) {			EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);			goto dsaerr;		}		if (!(ctx = BN_CTX_new())) {			EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);			goto dsaerr;		}					if (!BN_mod_exp(dsa->pub_key, dsa->g,						 dsa->priv_key, dsa->p, ctx)) {						EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);			goto dsaerr;		}		EVP_PKEY_assign_DSA(pkey, dsa);		BN_CTX_free (ctx);		if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);		else ASN1_INTEGER_free(privkey);		break;		dsaerr:		BN_CTX_free (ctx);		sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);		DSA_free(dsa);		EVP_PKEY_free(pkey);		return NULL;		break;#endif		default:		EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);		if (!a->algorithm) strcpy (obj_tmp, "NULL");		else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);		ERR_add_error_data(2, "TYPE=", obj_tmp);		EVP_PKEY_free (pkey);		return NULL;	}	return pkey;}
开发者ID:jhbsz,项目名称:actiontec_opensource_mi424wr-rev-acd-56-0-10-14-4,代码行数:101,


示例28: dsa_priv_decode

//.........这里部分代码省略.........  }  X509_ALGOR_get0(NULL, &ptype, &pval, palg);  /* Check for broken DSA PKCS#8, UGH! */  if (*p == (V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED)) {    ASN1_TYPE *t1, *t2;    ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen);    if (ndsa == NULL) {      goto decerr;    }    if (sk_ASN1_TYPE_num(ndsa) != 2) {      goto decerr;    }    /* Handle Two broken types:     * SEQUENCE {parameters, priv_key}     * SEQUENCE {pub_key, priv_key}. */    t1 = sk_ASN1_TYPE_value(ndsa, 0);    t2 = sk_ASN1_TYPE_value(ndsa, 1);    if (t1->type == V_ASN1_SEQUENCE) {      p8->broken = PKCS8_EMBEDDED_PARAM;      pval = t1->value.ptr;    } else if (ptype == V_ASN1_SEQUENCE) {      p8->broken = PKCS8_NS_DB;    } else {      goto decerr;    }    if (t2->type != V_ASN1_INTEGER) {      goto decerr;    }    privkey = t2->value.integer;  } else {    const uint8_t *q = p;    privkey = d2i_ASN1_INTEGER(NULL, &p, pklen);    if (privkey == NULL) {      goto decerr;    }    if (privkey->type == V_ASN1_NEG_INTEGER) {      p8->broken = PKCS8_NEG_PRIVKEY;      ASN1_INTEGER_free(privkey);      privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen);      if (privkey == NULL) {        goto decerr;      }    }    if (ptype != V_ASN1_SEQUENCE) {      goto decerr;    }  }  pstr = pval;  pm = pstr->data;  pmlen = pstr->length;  dsa = d2i_DSAparams(NULL, &pm, pmlen);  if (dsa == NULL) {    goto decerr;  }  /* We have parameters. Now set private key */  dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL);  if (dsa->priv_key == NULL) {    OPENSSL_PUT_ERROR(EVP, ERR_LIB_BN);    goto dsaerr;  }  /* Calculate public key. */  dsa->pub_key = BN_new();  if (dsa->pub_key == NULL) {    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);    goto dsaerr;  }  ctx = BN_CTX_new();  if (ctx == NULL) {    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);    goto dsaerr;  }  if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {    OPENSSL_PUT_ERROR(EVP, ERR_LIB_BN);    goto dsaerr;  }  EVP_PKEY_assign_DSA(pkey, dsa);  BN_CTX_free(ctx);  sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);  ASN1_INTEGER_free(privkey);  return 1;decerr:  OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);dsaerr:  BN_CTX_free(ctx);  ASN1_INTEGER_free(privkey);  sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);  DSA_free(dsa);  return 0;}
开发者ID:bheesham,项目名称:boringssl,代码行数:101,


示例29: dsa_priv_decode

static int dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8){    const unsigned char *p, *pm;    int pklen, pmlen;    int ptype;    const void *pval;    const ASN1_STRING *pstr;    const X509_ALGOR *palg;    ASN1_INTEGER *privkey = NULL;    BN_CTX *ctx = NULL;    DSA *dsa = NULL;    int ret = 0;    if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))        return 0;    X509_ALGOR_get0(NULL, &ptype, &pval, palg);    if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL)        goto decerr;    if (privkey->type == V_ASN1_NEG_INTEGER || ptype != V_ASN1_SEQUENCE)        goto decerr;    pstr = pval;    pm = pstr->data;    pmlen = pstr->length;    if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL)        goto decerr;    /* We have parameters now set private key */    if ((dsa->priv_key = BN_secure_new()) == NULL        || !ASN1_INTEGER_to_BN(privkey, dsa->priv_key)) {        DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);        goto dsaerr;    }    /* Calculate public key */    if ((dsa->pub_key = BN_new()) == NULL) {        DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);        goto dsaerr;    }    if ((ctx = BN_CTX_new()) == NULL) {        DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);        goto dsaerr;    }    BN_set_flags(dsa->priv_key, BN_FLG_CONSTTIME);    if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {        DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);        goto dsaerr;    }    EVP_PKEY_assign_DSA(pkey, dsa);    ret = 1;    goto done; decerr:    DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR); dsaerr:    DSA_free(dsa); done:    BN_CTX_free(ctx);    ASN1_STRING_clear_free(privkey);    return ret;}
开发者ID:akamai,项目名称:openssl,代码行数:65,


示例30: LUA_FUNCTION

static LUA_FUNCTION(openssl_pkey_new){  EVP_PKEY *pkey = NULL;  const char* alg = "rsa";  if (lua_isnoneornil(L, 1) || lua_isstring(L, 1))  {    alg = luaL_optstring(L, 1, alg);    if (strcasecmp(alg, "rsa") == 0)    {      int bits = luaL_optint(L, 2, 1024);      int e = luaL_optint(L, 3, 65537);      RSA* rsa = RSA_new();      BIGNUM *E = BN_new();      BN_set_word(E, e);      if (RSA_generate_key_ex(rsa, bits, E, NULL))      {        pkey = EVP_PKEY_new();        EVP_PKEY_assign_RSA(pkey, rsa);      }      else        RSA_free(rsa);      BN_free(E);    }    else if (strcasecmp(alg, "dsa") == 0)    {      int bits = luaL_optint(L, 2, 1024);      size_t seed_len = 0;      const char* seed = luaL_optlstring(L, 3, NULL, &seed_len);      DSA *dsa = DSA_new();      if (DSA_generate_parameters_ex(dsa, bits, (byte*)seed, seed_len, NULL, NULL, NULL)          && DSA_generate_key(dsa))      {        pkey = EVP_PKEY_new();        EVP_PKEY_assign_DSA(pkey, dsa);      }      else        DSA_free(dsa);    }    else if (strcasecmp(alg, "dh") == 0)    {      int bits = luaL_optint(L, 2, 512);      int generator = luaL_optint(L, 3, 2);      DH* dh = DH_new();      if (DH_generate_parameters_ex(dh, bits, generator, NULL))      {        if (DH_generate_key(dh))        {          pkey = EVP_PKEY_new();          EVP_PKEY_assign_DH(pkey, dh);        }        else          DH_free(dh);      }      else        DH_free(dh);    }#ifndef OPENSSL_NO_EC    else if (strcasecmp(alg, "ec") == 0)    {      EC_KEY *ec = NULL;      EC_GROUP *group = openssl_get_ec_group(L, 2, 3, 4);      if (!group)        luaL_error(L, "failed to get ec_group object");      ec = EC_KEY_new();      if (ec)      {        EC_KEY_set_group(ec, group);        EC_GROUP_free(group);        if (EC_KEY_generate_key(ec))        {          pkey = EVP_PKEY_new();          EVP_PKEY_assign_EC_KEY(pkey, ec);        }        else          EC_KEY_free(ec);      }      else        EC_GROUP_free(group);    }#endif    else    {      luaL_error(L, "not support %s!!!!", alg);    }  }  else if (lua_istable(L, 1))  {    lua_getfield(L, 1, "alg");    alg = luaL_optstring(L, -1, alg);    lua_pop(L, 1);    if (strcasecmp(alg, "rsa") == 0)    {      pkey = EVP_PKEY_new();      if (pkey)//.........这里部分代码省略.........
开发者ID:houzhenggang,项目名称:luajit-android,代码行数:101,



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


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