本文整理汇总了C++中EVP_PKEY_size函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_PKEY_size函数的具体用法?C++ EVP_PKEY_size怎么用?C++ EVP_PKEY_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVP_PKEY_size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: opensslgost_sign
static isc_result_t
opensslgost_sign(dst_context_t *dctx, isc_buffer_t *sig) {
dst_key_t *key = dctx->key;
isc_region_t r;
unsigned int siglen = 0;
EVP_MD_CTX *evp_md_ctx = dctx->ctxdata.evp_md_ctx;
EVP_PKEY *pkey = key->keydata.pkey;
isc_buffer_availableregion(sig, &r);
if (r.length < (unsigned int) EVP_PKEY_size(pkey))
return (ISC_R_NOSPACE);
if (!EVP_SignFinal(evp_md_ctx, r.base, &siglen, pkey))
return (ISC_R_FAILURE);
isc_buffer_add(sig, siglen);
return (ISC_R_SUCCESS);
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:20,代码来源:opensslgost_link.c
示例2: LUA_FUNCTION
static LUA_FUNCTION(openssl_signFinal)
{
EVP_MD_CTX *ctx = CHECK_OBJECT(1, EVP_MD_CTX, "openssl.evp_digest_ctx");
EVP_PKEY *pkey = lua_gettop(L) > 1 ? CHECK_OBJECT(2, EVP_PKEY, "openssl.evp_pkey") : NULL;
size_t siglen = EVP_PKEY_size(pkey);
unsigned char *sigbuf = malloc(siglen + 1);
int ret = 0;
if (pkey)
ret = EVP_SignFinal(ctx, sigbuf, (unsigned int *)&siglen, pkey);
else
ret = EVP_DigestSignFinal(ctx, sigbuf, &siglen);
if (ret == 1)
{
lua_pushlstring(L, (char *)sigbuf, siglen);
}
free(sigbuf);
EVP_MD_CTX_cleanup(ctx);
if (ret == 1)
return 1;
return openssl_pushresult(L, ret);
}
开发者ID:chk-jxcn,项目名称:lua-openssl,代码行数:21,代码来源:digest.c
示例3: soap_smd_size
/**
@fn size_t soap_smd_size(int alg, const void *key)
@brief Returns the number of octets needed to store the digest or signature returned by soap_smd_end.
@param[in] alg is the digest or signature algorithm to be used
@param[in] key is a pointer to an EVP_PKEY object for RSA/DSA signatures or NULL for digests and HMAC
@return size_t number of octets that is needed to hold digest or signature
@see soap_smd_end
The values returned for digests are SOAP_SMD_MD5_SIZE and SOAP_SMD_SHA1_SIZE.
*/
size_t
soap_smd_size(int alg, const void *key)
{ switch (alg & (SOAP_SMD_PASSTHRU-1))
{ case SOAP_SMD_DGST_MD5:
return SOAP_SMD_MD5_SIZE;
case SOAP_SMD_DGST_SHA1:
case SOAP_SMD_HMAC_SHA1:
return SOAP_SMD_SHA1_SIZE;
case SOAP_SMD_DGST_SHA256:
return SOAP_SMD_SHA256_SIZE;
case SOAP_SMD_SIGN_DSA_SHA1:
case SOAP_SMD_SIGN_RSA_SHA1:
case SOAP_SMD_SIGN_RSA_SHA256:
case SOAP_SMD_VRFY_DSA_SHA1:
case SOAP_SMD_VRFY_RSA_SHA1:
/* OpenSSL EVP_PKEY_size returns size of signatures given a key */
return EVP_PKEY_size((EVP_PKEY*)key);
}
return 0;
}
开发者ID:abidinz,项目名称:Stormee,代码行数:31,代码来源:smdevp.c
示例4: genAlgorithmProperties
void genAlgorithmProperties(X509* cert,
std::string& key,
std::string& sig,
std::string& size) {
int nid = 0;
nid = OBJ_obj2nid(cert->cert_info->key->algor->algorithm);
if (nid != NID_undef) {
key = std::string(OBJ_nid2ln(nid));
// Get EVP public key, to determine public key size.
EVP_PKEY* pkey = nullptr;
pkey = X509_get_pubkey(cert);
if (pkey != nullptr) {
if (nid == NID_rsaEncryption || nid == NID_dsa) {
size_t key_size = 0;
key_size = EVP_PKEY_size(pkey);
size = std::to_string(key_size * 8);
}
// The EVP_size for EC keys returns the maximum buffer for storing the
// key data, it does not indicate the size/strength of the curve.
if (nid == NID_X9_62_id_ecPublicKey) {
const EC_KEY* ec_pkey = pkey->pkey.ec;
const EC_GROUP* ec_pkey_group = nullptr;
ec_pkey_group = EC_KEY_get0_group(ec_pkey);
int curve_nid = 0;
curve_nid = EC_GROUP_get_curve_name(ec_pkey_group);
if (curve_nid != NID_undef) {
size = std::string(OBJ_nid2ln(curve_nid));
}
}
}
EVP_PKEY_free(pkey);
}
nid = OBJ_obj2nid(cert->cert_info->signature->algorithm);
if (nid != NID_undef) {
sig = std::string(OBJ_nid2ln(nid));
}
}
开发者ID:wxsBSD,项目名称:osquery,代码行数:40,代码来源:keychain_utils.cpp
示例5: ERROR_MSG
bool OSSLGOST::signFinal(ByteString& signature)
{
// Save necessary state before calling super class signFinal
OSSLGOSTPrivateKey* pk = (OSSLGOSTPrivateKey*) currentPrivateKey;
if (!AsymmetricAlgorithm::signFinal(signature))
{
return false;
}
// Perform the signature operation
EVP_PKEY* pkey = pk->getOSSLKey();
unsigned int outLen;
if (pkey == NULL)
{
ERROR_MSG("Could not get the OpenSSL private key");
EVP_MD_CTX_cleanup(&curCTX);
return false;
}
signature.resize(EVP_PKEY_size(pkey));
outLen = signature.size();
if (!EVP_SignFinal(&curCTX, &signature[0], &outLen, pkey))
{
ERROR_MSG("EVP_SignFinal failed");
EVP_MD_CTX_cleanup(&curCTX);
return false;
}
signature.resize(outLen);
EVP_MD_CTX_cleanup(&curCTX);
return true;
}
开发者ID:GarysExperiments2014,项目名称:SoftHSMv2,代码行数:40,代码来源:OSSLGOST.cpp
示例6: sign_hello
/* This function signs the buffer passed as argument, returns the length of the signature
* else -1 on error
* It leaves the sign in **sign_buf (which is allocated)
*/
int sign_hello(unsigned char* hello_buf,unsigned int hello_len,unsigned char** sign_buf){
EVP_MD_CTX* ctx = NULL;
unsigned int sign_len;
EVP_PKEY* evp = EVP_PKEY_new();
FILE* fp;
*sign_buf = NULL;
ctx = (EVP_MD_CTX*)calloc(1,sizeof(EVP_MD_CTX));
EVP_MD_CTX_init(ctx);
OpenSSL_add_all_algorithms();
if((fp=fopen(PRIV_KEY,"r"))==NULL){
goto fail;
}
if((evp=PEM_read_PrivateKey(fp,NULL,NULL,NULL))==NULL){
goto fail;
}
*sign_buf = (unsigned char*)calloc(1,EVP_PKEY_size(evp));
if(EVP_SignInit(ctx,EVP_sha512())==0){
goto fail;
}
if(EVP_SignUpdate(ctx,hello_buf,hello_len)==0){
goto fail;
}
if(EVP_SignFinal(ctx,*sign_buf,&sign_len,evp)==0){
goto fail;
}
EVP_MD_CTX_cleanup(ctx);
free(ctx);
EVP_PKEY_free(evp);
return sign_len;
fail:
EVP_MD_CTX_cleanup(ctx);
free(ctx);
if (*sign_buf != NULL) {
free(*sign_buf);
}
return -1;
}
开发者ID:bbeco,项目名称:secretchat,代码行数:43,代码来源:secretchat_support_lib.c
示例7: pkey_rsa_decrypt
static int pkey_rsa_decrypt(EVP_PKEY_CTX *ctx, uint8_t *out,
size_t *outlen, const uint8_t *in,
size_t inlen) {
RSA_PKEY_CTX *rctx = ctx->data;
RSA *rsa = ctx->pkey->pkey.rsa;
const size_t key_len = EVP_PKEY_size(ctx->pkey);
if (!out) {
*outlen = key_len;
return 1;
}
if (*outlen < key_len) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_decrypt, EVP_R_BUFFER_TOO_SMALL);
return 0;
}
if (rctx->pad_mode == RSA_PKCS1_OAEP_PADDING) {
size_t plaintext_len;
int message_len;
if (!setup_tbuf(rctx, ctx) ||
!RSA_decrypt(rsa, &plaintext_len, rctx->tbuf, key_len, in, inlen,
RSA_NO_PADDING)) {
return 0;
}
message_len = RSA_padding_check_PKCS1_OAEP_mgf1(
out, key_len, rctx->tbuf, plaintext_len, rctx->oaep_label,
rctx->oaep_labellen, rctx->md, rctx->mgf1md);
if (message_len < 0) {
return 0;
}
*outlen = message_len;
return 1;
}
return RSA_decrypt(rsa, outlen, out, key_len, in, inlen, rctx->pad_mode);
}
开发者ID:randombit,项目名称:hacrypto,代码行数:39,代码来源:p_rsa.c
示例8: EVP_PKEY_CTX_get0_pkey
static RSA_PSS_PARAMS *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx)
{
const EVP_MD *sigmd, *mgf1md;
EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(pkctx);
int saltlen;
if (EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) <= 0)
return NULL;
if (EVP_PKEY_CTX_get_rsa_mgf1_md(pkctx, &mgf1md) <= 0)
return NULL;
if (!EVP_PKEY_CTX_get_rsa_pss_saltlen(pkctx, &saltlen))
return NULL;
if (saltlen == -1) {
saltlen = EVP_MD_size(sigmd);
} else if (saltlen == -2) {
saltlen = EVP_PKEY_size(pk) - EVP_MD_size(sigmd) - 2;
if ((EVP_PKEY_bits(pk) & 0x7) == 1)
saltlen--;
}
return rsa_pss_params_create(sigmd, mgf1md, saltlen);
}
开发者ID:Bilibili,项目名称:openssl,代码行数:22,代码来源:rsa_ameth.c
示例9: pkey_rsa_verify
static int pkey_rsa_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig,
size_t siglen, const uint8_t *tbs,
size_t tbslen) {
RSA_PKEY_CTX *rctx = ctx->data;
RSA *rsa = ctx->pkey->pkey.rsa;
size_t rslen;
const size_t key_len = EVP_PKEY_size(ctx->pkey);
if (rctx->md) {
switch (rctx->pad_mode) {
case RSA_PKCS1_PADDING:
return RSA_verify(EVP_MD_type(rctx->md), tbs, tbslen, sig, siglen, rsa);
case RSA_PKCS1_PSS_PADDING:
if (!setup_tbuf(rctx, ctx) ||
!RSA_verify_raw(rsa, &rslen, rctx->tbuf, key_len, sig, siglen,
RSA_NO_PADDING) ||
!RSA_verify_PKCS1_PSS_mgf1(rsa, tbs, rctx->md, rctx->mgf1md,
rctx->tbuf, rctx->saltlen)) {
return 0;
}
return 1;
default:
return 0;
}
}
if (!setup_tbuf(rctx, ctx) ||
!RSA_verify_raw(rsa, &rslen, rctx->tbuf, key_len, sig, siglen,
rctx->pad_mode) ||
rslen != tbslen ||
CRYPTO_memcmp(tbs, rctx->tbuf, rslen) != 0) {
return 0;
}
return 1;
}
开发者ID:randombit,项目名称:hacrypto,代码行数:38,代码来源:p_rsa.c
示例10: ossl_pkey_sign
/*
* call-seq:
* pkey.sign(digest, data) -> String
*
* To sign the +String+ +data+, +digest+, an instance of OpenSSL::Digest, must
* be provided. The return value is again a +String+ containing the signature.
* A PKeyError is raised should errors occur.
* Any previous state of the +Digest+ instance is irrelevant to the signature
* outcome, the digest instance is reset to its initial state during the
* operation.
*
* == Example
* data = 'Sign me!'
* digest = OpenSSL::Digest::SHA256.new
* pkey = OpenSSL::PKey::RSA.new(2048)
* signature = pkey.sign(digest, data)
*/
static VALUE
ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
{
EVP_PKEY *pkey;
EVP_MD_CTX ctx;
unsigned int buf_len;
VALUE str;
if (rb_funcallv(self, id_private_q, 0, NULL) != Qtrue) {
ossl_raise(rb_eArgError, "Private key is needed.");
}
GetPKey(self, pkey);
EVP_SignInit(&ctx, GetDigestPtr(digest));
StringValue(data);
EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
str = rb_str_new(0, EVP_PKEY_size(pkey)+16);
if (!EVP_SignFinal(&ctx, (unsigned char *)RSTRING_PTR(str), &buf_len, pkey))
ossl_raise(ePKeyError, NULL);
assert((long)buf_len <= RSTRING_LEN(str));
rb_str_set_len(str, buf_len);
return str;
}
开发者ID:hilben,项目名称:ruby_test,代码行数:40,代码来源:ossl_pkey.c
示例11: EVP_MD_CTX_new
/** Low-level signature operation.
* \param key_count Number of keys in the \a source array.
* \param source Array of keys. The keys must include private key data.
* \param data Data to sign.
* \return Array of signatures, one for each key,
* or NULL if the operation failed.
* \sa gale_crypto_verify_raw(), gale_crypto_sign() */
const struct gale_data *gale_crypto_sign_raw(int key_count,
const struct gale_group *source,
struct gale_data data)
{
int i;
struct gale_data *output;
RSA *rsa;
EVP_MD_CTX *context = EVP_MD_CTX_new();
EVP_SignInit(context,EVP_md5());
EVP_SignUpdate(context,data.p,data.l);
gale_create_array(output,key_count);
for (i = 0; NULL != output && i < key_count; ++i) {
EVP_PKEY *key = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key,RSA_new());
rsa = EVP_PKEY_get0_RSA(key);
crypto_i_rsa(source[i],rsa);
if (!crypto_i_private_valid(rsa)) {
gale_alert(GALE_WARNING,G_("invalid private key"),0);
output = NULL;
goto cleanup;
}
output[i].p = gale_malloc(EVP_PKEY_size(key));
if (!EVP_SignFinal(context,output[i].p,&output[i].l,key)) {
crypto_i_error();
output = NULL;
goto cleanup;
}
cleanup:
EVP_PKEY_free(key);
}
return output;
}
开发者ID:grawity,项目名称:gale,代码行数:43,代码来源:crypto_sign_raw.c
示例12: PEM_SignFinal
int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
EVP_PKEY *pkey)
{
unsigned char *m;
int i,ret=0;
unsigned int m_len;
m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2);
if (m == NULL)
{
PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
goto err;
}
if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err;
i=EVP_EncodeBlock(sigret,m,m_len);
*siglen=i;
ret=1;
err:
/* ctx has been zeroed by EVP_SignFinal() */
if (m != NULL) OPENSSL_free(m);
return(ret);
}
开发者ID:ahenroid,项目名称:ptptl-0.2,代码行数:24,代码来源:pem_sign.c
示例13: pgpVerifySigRSA
static int pgpVerifySigRSA(pgpDigAlg pgpkey, pgpDigAlg pgpsig,
uint8_t *hash, size_t hashlen, int hash_algo)
{
int rc, ret;
EVP_PKEY_CTX *pkey_ctx = NULL;
struct pgpDigSigRSA_s *sig = pgpsig->data;
void *padded_sig = NULL;
struct pgpDigKeyRSA_s *key = pgpkey->data;
if (!constructRSASigningKey(key)) {
rc = 1;
goto done;
}
pkey_ctx = EVP_PKEY_CTX_new(key->evp_pkey, NULL);
if (!pkey_ctx) {
rc = 1;
goto done;
}
ret = EVP_PKEY_verify_init(pkey_ctx);
if (ret < 0) {
rc = 1;
goto done;
}
ret = EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PADDING);
if (ret < 0) {
rc = 1;
goto done;
}
ret = EVP_PKEY_CTX_set_signature_md(pkey_ctx, getEVPMD(hash_algo));
if (ret < 0) {
rc = 1;
goto done;
}
int pkey_len = EVP_PKEY_size(key->evp_pkey);
padded_sig = xcalloc(1, pkey_len);
if (!BN_bn2binpad(sig->bn, padded_sig, pkey_len)) {
rc = 1;
goto done;
}
ret = EVP_PKEY_verify(pkey_ctx, padded_sig, pkey_len, hash, hashlen);
if (ret == 1)
{
/* Success */
rc = 0;
}
else
{
/* Failure */
rc = 1;
}
done:
EVP_PKEY_CTX_free(pkey_ctx);
free(padded_sig);
return rc;
}
开发者ID:maxamillion,项目名称:rpm,代码行数:64,代码来源:digest_openssl.c
示例14: PKCS7_dataFinal
int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
{
int ret=0;
int i,j;
BIO *btmp;
BUF_MEM *buf_mem=NULL;
BUF_MEM *buf=NULL;
PKCS7_SIGNER_INFO *si;
EVP_MD_CTX *mdc,ctx_tmp;
STACK_OF(X509_ATTRIBUTE) *sk;
STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
ASN1_OCTET_STRING *os=NULL;
EVP_MD_CTX_init(&ctx_tmp);
i=OBJ_obj2nid(p7->type);
p7->state=PKCS7_S_HEADER;
switch (i)
{
case NID_pkcs7_signedAndEnveloped:
/* XXXXXXXXXXXXXXXX */
si_sk=p7->d.signed_and_enveloped->signer_info;
if (!(os=M_ASN1_OCTET_STRING_new()))
{
PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
goto err;
}
p7->d.signed_and_enveloped->enc_data->enc_data=os;
break;
case NID_pkcs7_enveloped:
/* XXXXXXXXXXXXXXXX */
if (!(os=M_ASN1_OCTET_STRING_new()))
{
PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
goto err;
}
p7->d.enveloped->enc_data->enc_data=os;
break;
case NID_pkcs7_signed:
si_sk=p7->d.sign->signer_info;
os=PKCS7_get_octet_string(p7->d.sign->contents);
/* If detached data then the content is excluded */
if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
M_ASN1_OCTET_STRING_free(os);
p7->d.sign->contents->d.data = NULL;
}
break;
case NID_pkcs7_digest:
os=PKCS7_get_octet_string(p7->d.digest->contents);
/* If detached data then the content is excluded */
if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached)
{
M_ASN1_OCTET_STRING_free(os);
p7->d.digest->contents->d.data = NULL;
}
break;
}
if (si_sk != NULL)
{
if ((buf=BUF_MEM_new()) == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_BIO_LIB);
goto err;
}
for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
{
si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
if (si->pkey == NULL) continue;
j=OBJ_obj2nid(si->digest_alg->algorithm);
btmp=bio;
btmp = PKCS7_find_digest(&mdc, btmp, j);
if (btmp == NULL)
goto err;
/* We now have the EVP_MD_CTX, lets do the
* signing. */
EVP_MD_CTX_copy_ex(&ctx_tmp,mdc);
if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey)))
{
PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_BIO_LIB);
goto err;
}
sk=si->auth_attr;
/* If there are attributes, we add the digest
* attribute and only sign the attributes */
if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
{
unsigned char md_data[EVP_MAX_MD_SIZE], *abuf=NULL;
unsigned int md_len, alen;
ASN1_OCTET_STRING *digest;
ASN1_UTCTIME *sign_time;
//.........这里部分代码省略.........
开发者ID:jameshilliard,项目名称:actiontec_opensrc_mi424wr-rev-ef_fw-20-20-8,代码行数:101,代码来源:pk7_doit.c
示例15: addIdentity
/* adds a Identity header field to msg
return value: 1: success
0: else
*/
static int addIdentity(char * dateHF, struct sip_msg * msg)
{
#define IDENTITY_HDR_S "Identity: \""
#define IDENTITY_HDR_L (sizeof(IDENTITY_HDR_S)-1)
EVP_MD_CTX ctx;
unsigned int siglen = 0;
int b64len = 0;
unsigned char * sig = NULL;
char digestString[MAX_DIGEST];
str buf;
if(!makeDigestString(digestString, dateHF, msg))
{
LM_ERR("error making digest string\n");
return 0;
}
EVP_SignInit(&ctx, EVP_sha1());
EVP_SignUpdate(&ctx, digestString, strlen(digestString));
sig = pkg_malloc(EVP_PKEY_size(privKey_evp));
if(!sig)
{
EVP_MD_CTX_cleanup(&ctx);
LM_ERR("failed allocating memory\n");
return 0;
}
if(!EVP_SignFinal(&ctx, sig, &siglen, privKey_evp))
{
EVP_MD_CTX_cleanup(&ctx);
pkg_free(sig);
LM_ERR("error calculating signature\n");
return 0;
}
EVP_MD_CTX_cleanup(&ctx);
/* ###Base64-encoding### */
/* annotation: The next few lines are based on example 7-11 of [VIE-02] */
b64len = (((siglen + 2) / 3) * 4) + 1;
buf.len = IDENTITY_HDR_L + b64len + 1 + CRLF_LEN;
buf.s = pkg_malloc(buf.len);
if(!buf.s)
{
pkg_free(sig);
LM_ERR("error allocating memory\n");
return 0;
}
memcpy( buf.s, IDENTITY_HDR_S, IDENTITY_HDR_L);
EVP_EncodeBlock((unsigned char*)(buf.s+IDENTITY_HDR_L), sig, siglen);
memcpy( buf.s+IDENTITY_HDR_L+b64len, "\""CRLF, CRLF_LEN+1);
pkg_free(sig);
if ( id_add_header( msg, buf.s, buf.len )!=0) {
pkg_free(buf.s);
LM_ERR("failed to add Identity header\n");
return 0;
}
return 1;
}
开发者ID:Parantido,项目名称:opensips,代码行数:67,代码来源:identity.c
示例16: STACK_OF
//.........这里部分代码省略.........
int keylen,ivlen;
int max;
X509_OBJECT ret;
#endif
int jj;
if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
goto err;
}
/* It was encrypted, we need to decrypt the secret key
* with the private key */
/* Find the recipientInfo which matches the passed certificate
* (if any)
*/
if (pcert) {
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
if (!pkcs7_cmp_ri(ri, pcert))
break;
ri=NULL;
}
if (ri == NULL) {
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
goto err;
}
}
jj=EVP_PKEY_size(pkey);
tmp=(unsigned char *)OPENSSL_malloc(jj+10);
if (tmp == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
goto err;
}
/* If we haven't got a certificate try each ri in turn */
if (pcert == NULL)
{
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
{
ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
jj=EVP_PKEY_decrypt(tmp,
M_ASN1_STRING_data(ri->enc_key),
M_ASN1_STRING_length(ri->enc_key),
pkey);
if (jj > 0)
break;
ERR_clear_error();
ri = NULL;
}
if (ri == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_NO_RECIPIENT_MATCHES_KEY);
goto err;
}
}
else
{
开发者ID:jameshilliard,项目名称:actiontec_opensrc_mi424wr-rev-ef_fw-20-20-8,代码行数:67,代码来源:pk7_doit.c
示例17: X509_certificate_type
int
X509_certificate_type(X509 *x, EVP_PKEY *pkey)
{
EVP_PKEY *pk;
int ret = 0, i;
if (x == NULL)
return (0);
if (pkey == NULL)
pk = X509_get_pubkey(x);
else
pk = pkey;
if (pk == NULL)
return (0);
switch (pk->type) {
case EVP_PKEY_RSA:
ret = EVP_PK_RSA|EVP_PKT_SIGN;
/* if (!sign only extension) */
ret |= EVP_PKT_ENC;
break;
case EVP_PKEY_DSA:
ret = EVP_PK_DSA|EVP_PKT_SIGN;
break;
case EVP_PKEY_EC:
ret = EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH;
break;
case EVP_PKEY_DH:
ret = EVP_PK_DH|EVP_PKT_EXCH;
break;
case NID_id_GostR3410_94:
case NID_id_GostR3410_2001:
ret = EVP_PKT_EXCH|EVP_PKT_SIGN;
break;
default:
break;
}
i = OBJ_obj2nid(x->sig_alg->algorithm);
if (i && OBJ_find_sigid_algs(i, NULL, &i)) {
switch (i) {
case NID_rsaEncryption:
case NID_rsa:
ret |= EVP_PKS_RSA;
break;
case NID_dsa:
case NID_dsa_2:
ret |= EVP_PKS_DSA;
break;
case NID_X9_62_id_ecPublicKey:
ret |= EVP_PKS_EC;
break;
default:
break;
}
}
if (EVP_PKEY_size(pk) <= 1024/8)/* /8 because it's 1024 bits we look
for, not bytes */
ret |= EVP_PKT_EXP;
if (pkey == NULL)
EVP_PKEY_free(pk);
return (ret);
}
开发者ID:awakecoding,项目名称:libressl,代码行数:66,代码来源:x509type.c
示例18: any_sign_size
/*!
* \brief Get size of the resulting signature.
*
* \param key DNSSEC key.
*
* \return Signature size in bytes.
*/
static size_t any_sign_size(const knot_dnssec_key_t *key)
{
assert(key);
return (size_t)EVP_PKEY_size(key->data->private_key);
}
开发者ID:stribika,项目名称:curveprotect,代码行数:13,代码来源:dnssec.c
示例19: dgst_main
//.........这里部分代码省略.........
goto end;
}
if (sigopts) {
char *sigopt;
for (i = 0; i < sk_OPENSSL_STRING_num(sigopts); i++) {
sigopt = sk_OPENSSL_STRING_value(sigopts, i);
if (pkey_ctrl_string(pctx, sigopt) <= 0) {
BIO_printf(bio_err, "parameter error \"%s\"\n", sigopt);
ERR_print_errors(bio_err);
goto end;
}
}
}
}
/* we use md as a filter, reading from 'in' */
else {
EVP_MD_CTX *mctx = NULL;
if (!BIO_get_md_ctx(bmd, &mctx)) {
BIO_printf(bio_err, "Error getting context\n");
ERR_print_errors(bio_err);
goto end;
}
if (md == NULL)
md = EVP_md5();
if (!EVP_DigestInit_ex(mctx, md, impl)) {
BIO_printf(bio_err, "Error setting digest\n");
ERR_print_errors(bio_err);
goto end;
}
}
if (sigfile && sigkey) {
BIO *sigbio = BIO_new_file(sigfile, "rb");
if (!sigbio) {
BIO_printf(bio_err, "Error opening signature file %s\n", sigfile);
ERR_print_errors(bio_err);
goto end;
}
siglen = EVP_PKEY_size(sigkey);
sigbuf = app_malloc(siglen, "signature buffer");
siglen = BIO_read(sigbio, sigbuf, siglen);
BIO_free(sigbio);
if (siglen <= 0) {
BIO_printf(bio_err, "Error reading signature file %s\n", sigfile);
ERR_print_errors(bio_err);
goto end;
}
}
inp = BIO_push(bmd, in);
if (md == NULL) {
EVP_MD_CTX *tctx;
BIO_get_md_ctx(bmd, &tctx);
md = EVP_MD_CTX_md(tctx);
}
if (argc == 0) {
BIO_set_fp(in, stdin, BIO_NOCLOSE);
ret = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
siglen, NULL, NULL, "stdin", bmd);
} else {
const char *md_name = NULL, *sig_name = NULL;
if (!out_bin) {
if (sigkey) {
const EVP_PKEY_ASN1_METHOD *ameth;
ameth = EVP_PKEY_get0_asn1(sigkey);
if (ameth)
EVP_PKEY_asn1_get0_info(NULL, NULL,
NULL, NULL, &sig_name, ameth);
}
if (md)
md_name = EVP_MD_name(md);
}
ret = 0;
for (i = 0; i < argc; i++) {
int r;
if (BIO_read_filename(in, argv[i]) <= 0) {
perror(argv[i]);
ret++;
continue;
} else
r = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf,
siglen, sig_name, md_name, argv[i], bmd);
if (r)
ret = r;
(void)BIO_reset(bmd);
}
}
end:
OPENSSL_clear_free(buf, BUFSIZE);
BIO_free(in);
OPENSSL_free(passin);
BIO_free_all(out);
EVP_PKEY_free(sigkey);
sk_OPENSSL_STRING_free(sigopts);
sk_OPENSSL_STRING_free(macopts);
OPENSSL_free(sigbuf);
BIO_free(bmd);
return (ret);
}
开发者ID:GH-JY,项目名称:openssl,代码行数:101,代码来源:dgst.c
示例20: PKCS7_dataFinal
//.........这里部分代码省略.........
os = PKCS7_get_octet_string(p7->d.digest->contents);
/* If detached data then the content is excluded */
if (PKCS7_type_is_data(p7->d.digest->contents) && p7->detached) {
M_ASN1_OCTET_STRING_free(os);
os = NULL;
p7->d.digest->contents->d.data = NULL;
}
break;
default:
PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
goto err;
}
if (si_sk != NULL) {
for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(si_sk); i++) {
si = sk_PKCS7_SIGNER_INFO_value(si_sk, i);
if (si->pkey == NULL)
continue;
j = OBJ_obj2nid(si->digest_alg->algorithm);
btmp = bio;
btmp = PKCS7_find_digest(&mdc, btmp, j);
if (btmp == NULL)
goto err;
/*
* We now have the EVP_MD_CTX, lets do the signing.
*/
if (!EVP_MD_CTX_copy_ex(&ctx_tmp, mdc))
goto err;
sk = si->auth_attr;
/*
* If there are attributes, we add the digest attribute and only
* sign the attributes
*/
if (sk_X509_ATTRIBUTE_num(sk) > 0) {
if (!do_pkcs7_signed_attrib(si, &ctx_tmp))
goto err;
} else {
unsigned char *abuf = NULL;
unsigned int abuflen;
abuflen = EVP_PKEY_size(si->pkey);
abuf = OPENSSL_malloc(abuflen);
if (!abuf)
goto err;
if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen, si->pkey)) {
PKCS7err(PKCS7_F_PKCS7_DATAFINAL, ERR_R_EVP_LIB);
goto err;
}
ASN1_STRING_set0(si->enc_digest, abuf, abuflen);
}
}
} else if (i == NID_pkcs7_digest) {
unsigned char md_data[EVP_MAX_MD_SIZE];
unsigned int md_len;
if (!PKCS7_find_digest(&mdc, bio,
OBJ_obj2nid(p7->d.digest->md->algorithm)))
goto err;
if (!EVP_DigestFinal_ex(mdc, md_data, &md_len))
goto err;
M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len);
}
if (!PKCS7_is_detached(p7)) {
/*
* NOTE(emilia): I think we only reach os == NULL here because detached
* digested data support is broken.
*/
if (os == NULL)
goto err;
if (!(os->flags & ASN1_STRING_FLAG_NDEF)) {
char *cont;
long contlen;
btmp = BIO_find_type(bio, BIO_TYPE_MEM);
if (btmp == NULL) {
PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
goto err;
}
contlen = BIO_get_mem_data(btmp, &cont);
/*
* Mark the BIO read only then we can use its copy of the data
* instead of making an extra copy.
*/
BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
BIO_set_mem_eof_return(btmp, 0);
ASN1_STRING_set0(os, (unsigned char *)cont, contlen);
}
}
ret = 1;
err:
EVP_MD_CTX_cleanup(&ctx_tmp);
return (ret);
}
开发者ID:4872866,项目名称:node,代码行数:101,代码来源:pk7_doit.c
注:本文中的EVP_PKEY_size函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论