当前位置: 首页>>代码示例>>C++>>正文


C++ DSA_SIG_new函数代码示例

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


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

示例1: DSA_verify

/*
 * data has already been hashed (probably with SHA or SHA-1).
 * returns
 *      1: correct signature
 *      0: incorrect signature
 *     -1: error
 */
int
DSA_verify(int type, const unsigned char *dgst, int dgst_len,
    const unsigned char *sigbuf, int siglen, DSA *dsa)
{
	DSA_SIG *s;
	unsigned char *der = NULL;
	const unsigned char *p = sigbuf;
	int derlen = -1;
	int ret = -1;

	s = DSA_SIG_new();
	if (s == NULL)
		return ret;
	if (d2i_DSA_SIG(&s, &p, siglen) == NULL)
		goto err;
	/* Ensure signature uses DER and doesn't have trailing garbage */
	derlen = i2d_DSA_SIG(s, &der);
	if (derlen != siglen || memcmp(sigbuf, der, derlen))
		goto err;
	ret = DSA_do_verify(dgst, dgst_len, s, dsa);
err:
	freezero(der, derlen);
	DSA_SIG_free(s);
	return ret;
}
开发者ID:mr-moai-2016,项目名称:znk_project,代码行数:32,代码来源:dsa_asn1.c

示例2: DSA_check_signature

int DSA_check_signature(int *out_valid, const uint8_t *digest,
                        size_t digest_len, const uint8_t *sig, size_t sig_len,
                        const DSA *dsa) {
    DSA_SIG *s = NULL;
    int ret = 0;
    uint8_t *der = NULL;

    s = DSA_SIG_new();
    if (s == NULL) {
        goto err;
    }

    const uint8_t *sigp = sig;
    if (d2i_DSA_SIG(&s, &sigp, sig_len) == NULL || sigp != sig + sig_len) {
        goto err;
    }

    /* Ensure that the signature uses DER and doesn't have trailing garbage. */
    int der_len = i2d_DSA_SIG(s, &der);
    if (der_len < 0 || (size_t)der_len != sig_len || memcmp(sig, der, sig_len)) {
        goto err;
    }

    ret = DSA_do_check_signature(out_valid, digest, digest_len, s, dsa);

err:
    OPENSSL_free(der);
    DSA_SIG_free(s);
    return ret;
}
开发者ID:gotomypc,项目名称:tiny-webrtc-gw,代码行数:30,代码来源:dsa.c

示例3: constructDSASignature

static int constructDSASignature(struct pgpDigSigDSA_s *sig)
{
    int rc;

    if (sig->dsa_sig) {
        /* We've already constructed it, so just reuse it */
        return 1;
    }

    /* Create the DSA signature */
    DSA_SIG *dsa_sig = DSA_SIG_new();
    if (!dsa_sig) return 0;

    if (!DSA_SIG_set0(dsa_sig, sig->r, sig->s)) {
        rc = 0;
        goto done;
    }

    sig->dsa_sig = dsa_sig;

    rc = 1;
done:
    if (rc == 0) {
        DSA_SIG_free(sig->dsa_sig);
    }
    return rc;
}
开发者ID:maxamillion,项目名称:rpm,代码行数:27,代码来源:digest_openssl.c

示例4: openssldsa_verify

static isc_result_t
openssldsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
	isc_sha1_t *sha1ctx = dctx->opaque;
	dst_key_t *key = dctx->key;
	DSA *dsa = key->opaque;
	DSA_SIG *dsasig;
	int status = 0;
	unsigned char digest[ISC_SHA1_DIGESTLENGTH];
	unsigned char *cp = sig->base;

	isc_sha1_final(sha1ctx, digest);

	if (sig->length < 2 * ISC_SHA1_DIGESTLENGTH + 1)
		return (DST_R_VERIFYFAILURE);

	cp++;	/*%< Skip T */
	dsasig = DSA_SIG_new();
	dsasig->r = BN_bin2bn(cp, ISC_SHA1_DIGESTLENGTH, NULL);
	cp += ISC_SHA1_DIGESTLENGTH;
	dsasig->s = BN_bin2bn(cp, ISC_SHA1_DIGESTLENGTH, NULL);
	cp += ISC_SHA1_DIGESTLENGTH;

	status = DSA_do_verify(digest, ISC_SHA1_DIGESTLENGTH, dsasig, dsa);
	DSA_SIG_free(dsasig);
	if (status <= 0)
		return (dst__openssl_toresult(DST_R_VERIFYFAILURE));

	return (ISC_R_SUCCESS);
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:29,代码来源:openssldsa_link.c

示例5: _libssh2_dsa_sha1_verify

int
_libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
                         const unsigned char *sig,
                         const unsigned char *m, unsigned long m_len)
{
    unsigned char hash[SHA_DIGEST_LENGTH];
    DSA_SIG * dsasig;
    BIGNUM * r;
    BIGNUM * s;
    int ret = -1;

    r = BN_new();
    BN_bin2bn(sig, 20, r);
    s = BN_new();
    BN_bin2bn(sig + 20, 20, s);

    dsasig = DSA_SIG_new();
#ifdef HAVE_OPAQUE_STRUCTS
    DSA_SIG_set0(dsasig, r, s);
#else
    dsasig->r = r;
    dsasig->s = s;
#endif
    if(!_libssh2_sha1(m, m_len, hash))
        /* _libssh2_sha1() succeeded */
        ret = DSA_do_verify(hash, SHA_DIGEST_LENGTH, dsasig, dsactx);

    DSA_SIG_free(dsasig);

    return (ret == 1) ? 0 : -1;
}
开发者ID:stinb,项目名称:libssh2,代码行数:31,代码来源:openssl.c

示例6: DSA_verify

int DSA_verify(int type, const uint8_t *digest, size_t digest_len,
               const uint8_t *sig, size_t sig_len, const DSA *dsa) {
  DSA_SIG *s = NULL;
  int ret = -1, valid;

  s = DSA_SIG_new();
  if (s == NULL) {
    goto err;
  }

  if (d2i_DSA_SIG(&s, &sig, sig_len) == NULL) {
    goto err;
  }

  if (!DSA_do_check_signature(&valid, digest, digest_len, s, dsa)) {
    goto err;
  }

  ret = valid;

err:
  if (s) {
    DSA_SIG_free(s);
  }
  return ret;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:26,代码来源:dsa.c

示例7: sigver

void sigver()
    {
    DSA *dsa=NULL;
    char buf[1024];
    int nmod=0;
    unsigned char hash[20];
    DSA_SIG *sig=DSA_SIG_new();

    while(fgets(buf,sizeof buf,stdin) != NULL)
	{
	if(!strncmp(buf,"[mod = ",7))
	    {
	    nmod=atoi(buf+7);
	    if(dsa)
		DSA_free(dsa);
	    dsa=DSA_new();
	    }
	else if(!strncmp(buf,"P = ",4))
	    dsa->p=hex2bn(buf+4);
	else if(!strncmp(buf,"Q = ",4))
	    dsa->q=hex2bn(buf+4);
	else if(!strncmp(buf,"G = ",4))
	    {
	    dsa->g=hex2bn(buf+4);

	    printf("[mod = %d]\n\n",nmod);
	    pbn("P",dsa->p);
	    pbn("Q",dsa->q);
	    pbn("G",dsa->g);
	    putc('\n',stdout);
	    }
	else if(!strncmp(buf,"Msg = ",6))
	    {
	    unsigned char msg[1024];
	    int n;

	    n=hex2bin(buf+6,msg);
	    pv("Msg",msg,n);
	    SHA1(msg,n,hash);
	    }
	else if(!strncmp(buf,"Y = ",4))
	    dsa->pub_key=hex2bn(buf+4);
	else if(!strncmp(buf,"R = ",4))
	    sig->r=hex2bn(buf+4);
	else if(!strncmp(buf,"S = ",4))
	    {
	    sig->s=hex2bn(buf+4);
	
	    pbn("Y",dsa->pub_key);
	    pbn("R",sig->r);
	    pbn("S",sig->s);
	    printf("Result = %c\n",DSA_do_verify(hash,sizeof hash,sig,dsa)
		   ? 'P' : 'F');
	    putc('\n',stdout);
	    }
	}
    }
开发者ID:FelipeFernandes1988,项目名称:Alice-1121-Modem,代码行数:57,代码来源:fips_dssvs.c

示例8: DSA_verify

/* returns
 *      1: correct signature
 *      0: incorrect signature
 *     -1: error
 */
int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
	     const unsigned char *sigbuf, int siglen, DSA *dsa)
	{
	DSA_SIG *s;
	/*
	  rdar://problem/20168109 and others
	  a binary compat issue with OpenSSL zd from zc
	  this change seems to be the problem, and is not critical
	  (for now).
	*/
#if 0
	const unsigned char *p = sigbuf;
	unsigned char *der = NULL;
	int derlen = -1;
#endif
	int ret=-1;
#ifdef OPENSSL_FIPS
	if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
		{
		DSAerr(DSA_F_DSA_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
		return 0;
		}
#endif

	s = DSA_SIG_new();
	if (s == NULL) return(ret);
	/*
	  rdar://problem/20168109 and others
	  a binary compat issue with OpenSSL zd from zc
	  this change seems to be the problem, and is not critical
	  (for now).
	*/
#if 0
	if (d2i_DSA_SIG(&s,&p,siglen) == NULL) goto err;
	/* Ensure signature uses DER and doesn't have trailing garbage */
	derlen = i2d_DSA_SIG(s, &der);
	if (derlen != siglen || memcmp(sigbuf, der, derlen))
		goto err;
#else
	if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
#endif
	ret=DSA_do_verify(dgst,dgst_len,s,dsa);
err:
	/*
	  more from rdar://problem/20168109 and others
	*/
#if 0
	if (derlen > 0)
		{
		OPENSSL_cleanse(der, derlen);
		OPENSSL_free(der);
		}
#endif
	DSA_SIG_free(s);
	return(ret);
	}
开发者ID:darlinghq,项目名称:darling-openssl,代码行数:61,代码来源:dsa_asn1.c

示例9: dsa_sign_write

/*!
 * \brief Finish the signing and write out the DSA signature.
 * \see any_sign_write
 */
static int dsa_sign_write(const knot_dnssec_sign_context_t *context,
                          uint8_t *signature, size_t signature_size)
{
	assert(context);
	assert(signature);

	size_t output_size = dsa_sign_size(context->key);
	if (output_size != signature_size) {
		return KNOT_DNSSEC_EUNEXPECTED_SIGNATURE_SIZE;
	}

	// create raw signature

	uint8_t *raw_signature = NULL;
	size_t raw_size = 0;
	int result = sign_alloc_and_write(context, &raw_signature, &raw_size);
	if (result != KNOT_EOK) {
		return result;
	}

	// decode signature, X.509 Dss-Sig-Value (RFC2459)

	DSA_SIG *decoded = DSA_SIG_new();
	if (!decoded) {
		free(raw_signature);
		return KNOT_ENOMEM;
	}

	const uint8_t *decode_scan = raw_signature;
	if (!d2i_DSA_SIG(&decoded, &decode_scan, (long)raw_size)) {
		DSA_SIG_free(decoded);
		free(raw_signature);
		return KNOT_DNSSEC_EDECODE_RAW_SIGNATURE;
	}

	free(raw_signature);

	// convert to format defined by RFC 2536 (DSA keys and SIGs in DNS)

	// T (1 byte), R (20 bytes), S (20 bytes)
	uint8_t *signature_t = signature;
	uint8_t *signature_r = signature + 21 - BN_num_bytes(decoded->r);
	uint8_t *signature_s = signature + 41 - BN_num_bytes(decoded->s);

	memset(signature, '\0', output_size);
	*signature_t = 0x00; //! \todo Take from public key. Only recommended.
	BN_bn2bin(decoded->r, signature_r);
	BN_bn2bin(decoded->s, signature_s);

	DSA_SIG_free(decoded);

	return KNOT_EOK;
}
开发者ID:dnstap,项目名称:knot,代码行数:57,代码来源:sign.c

示例10: DSA_SIG_new

/*
 * Computes signature and returns it as DSA_SIG structure
 */
DSA_SIG *gost_do_sign (const unsigned char *dgst, int dlen, DSA * dsa)
{
    BIGNUM *k = NULL, *tmp = NULL, *tmp2 = NULL;

    DSA_SIG *newsig = DSA_SIG_new ();

    BIGNUM *md = hashsum2bn (dgst);

    /* check if H(M) mod q is zero */
    BN_CTX *ctx = BN_CTX_new ();

    BN_CTX_start (ctx);
    if (!newsig)
    {
        GOSTerr (GOST_F_GOST_DO_SIGN, GOST_R_NO_MEMORY);
        goto err;
    }
    tmp = BN_CTX_get (ctx);
    k = BN_CTX_get (ctx);
    tmp2 = BN_CTX_get (ctx);
    BN_mod (tmp, md, dsa->q, ctx);
    if (BN_is_zero (tmp))
    {
        BN_one (md);
    }
    do
    {
        do
        {
            /*Generate random number k less than q */
            BN_rand_range (k, dsa->q);
            /* generate r = (a^x mod p) mod q */
            BN_mod_exp (tmp, dsa->g, k, dsa->p, ctx);
            if (!(newsig->r))
                newsig->r = BN_new ();
            BN_mod (newsig->r, tmp, dsa->q, ctx);
        }
        while (BN_is_zero (newsig->r));
        /* generate s = (xr + k(Hm)) mod q */
        BN_mod_mul (tmp, dsa->priv_key, newsig->r, dsa->q, ctx);
        BN_mod_mul (tmp2, k, md, dsa->q, ctx);
        if (!newsig->s)
            newsig->s = BN_new ();
        BN_mod_add (newsig->s, tmp, tmp2, dsa->q, ctx);
    }
    while (BN_is_zero (newsig->s));
  err:
    BN_free (md);
    BN_CTX_end (ctx);
    BN_CTX_free (ctx);
    return newsig;
}
开发者ID:274914765,项目名称:C,代码行数:55,代码来源:gost_sign.c

示例11: ERROR_MSG

// Verification functions
bool OSSLDSA::verify(PublicKey* publicKey, const ByteString& originalData,
		     const ByteString& signature, const AsymMech::Type mechanism,
		     const void* param /* = NULL */, const size_t paramLen /* = 0 */)
{
	if (mechanism == AsymMech::DSA)
	{
		// Separate implementation for DSA verification without hash computation

		// Check if the private key is the right type
		if (!publicKey->isOfType(OSSLDSAPublicKey::type))
		{
			ERROR_MSG("Invalid key type supplied");

			return false;
		}

		// Perform the verify operation
		OSSLDSAPublicKey* pk = (OSSLDSAPublicKey*) publicKey;
		unsigned int sigLen = pk->getOutputLength();
		if (signature.size() != sigLen)
			return false;
		DSA_SIG* sig = DSA_SIG_new();
		if (sig == NULL)
			return false;
		const unsigned char *s = signature.const_byte_str();
		sig->r = BN_bin2bn(s, sigLen / 2, NULL);
		sig->s = BN_bin2bn(s + sigLen / 2, sigLen / 2, NULL);
		if (sig->r == NULL || sig->s == NULL)
		{
			DSA_SIG_free(sig);
			return false;
		}
		int dLen = originalData.size();
		int ret = DSA_do_verify(originalData.const_byte_str(), dLen, sig, pk->getOSSLKey());
		if (ret != 1)
		{
			if (ret < 0)
				ERROR_MSG("DSA verify failed (0x%08X)", ERR_get_error());

			DSA_SIG_free(sig);
			return false;
		}

		DSA_SIG_free(sig);
		return true;
	}
	else
	{
		// Call the generic function
		return AsymmetricAlgorithm::verify(publicKey, originalData, signature, mechanism, param, paramLen);
	}
}
开发者ID:bluelikeme,项目名称:SoftHSMv2,代码行数:53,代码来源:OSSLDSA.cpp

示例12: DSA_SIG_new

/* Unpack signature according to cryptopro rules  */
DSA_SIG *unpack_cp_signature(const unsigned char *sig, size_t siglen)
{
    DSA_SIG *s;

    s = DSA_SIG_new();
    if (s == NULL) {
        GOSTerr(GOST_F_UNPACK_CP_SIGNATURE, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    s->s = BN_bin2bn(sig, siglen / 2, NULL);
    s->r = BN_bin2bn(sig + siglen / 2, siglen / 2, NULL);
    return s;
}
开发者ID:nicholasmsanford,项目名称:openssl,代码行数:14,代码来源:gost_pmeth.c

示例13: DSA_SIG_new

/* Unpack signature according to cryptopro rules  */
DSA_SIG *unpack_cp_signature(const unsigned char *sig,size_t siglen)
	{
	DSA_SIG *s;

	s = DSA_SIG_new();
	if (s == NULL)
		{
		GOSTerr(GOST_F_UNPACK_CP_SIGNATURE,GOST_R_NO_MEMORY);
		return NULL;
		}
	s->s = getbnfrombuf(sig , siglen/2);
	s->r = getbnfrombuf(sig + siglen/2, siglen/2);
	return s;
	}
开发者ID:Wampamba-Nooh,项目名称:MicroFrameworkSDK-Mono,代码行数:15,代码来源:gost_sign.cpp

示例14: DSA_verify

/* returns
 *      1: correct signature
 *      0: incorrect signature
 *     -1: error
 */
int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
               const unsigned char *sigbuf, int siglen, DSA *dsa)
{
    DSA_SIG *s;
    int ret=-1;

    s = DSA_SIG_new();
    if (s == NULL) return(ret);
    if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
    ret=DSA_do_verify(dgst,dgst_len,s,dsa);
err:
    DSA_SIG_free(s);
    return(ret);
}
开发者ID:GeekMeUpScotty,项目名称:openssl,代码行数:19,代码来源:dsa_asn1.c

示例15: surewarehk_dsa_do_sign

/* DSA sign and verify */
static	DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *from, int flen, DSA *dsa)
{
    int ret=0;
    char *hptr=NULL;
    DSA_SIG *psign=NULL;
    char msg[64]="ENGINE_dsa_do_sign";
    if (!p_surewarehk_Dsa_Sign)
    {
        SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ENGINE_R_NOT_INITIALISED);
        goto err;
    }
    /* extract ref to private key */
    else if (!(hptr=(char*)DSA_get_ex_data(dsa, dsaHndidx)))
    {
        SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,SUREWARE_R_MISSING_KEY_COMPONENTS);
        goto err;
    }
    else
    {
        if((psign = DSA_SIG_new()) == NULL)
        {
            SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ERR_R_MALLOC_FAILURE);
            goto err;
        }
        psign->r=BN_new();
        psign->s=BN_new();
        bn_expand2(psign->r, 20/sizeof(BN_ULONG));
        bn_expand2(psign->s, 20/sizeof(BN_ULONG));
        if (!psign->r || psign->r->dmax!=20/sizeof(BN_ULONG) ||
                !psign->s || psign->s->dmax!=20/sizeof(BN_ULONG))
            goto err;
        ret=p_surewarehk_Dsa_Sign(msg,flen,from,
                                  (unsigned long *)psign->r->d,
                                  (unsigned long *)psign->s->d,
                                  hptr);
        surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ret);
    }
    psign->r->top=20/sizeof(BN_ULONG);
    bn_fix_top(psign->r);
    psign->s->top=20/sizeof(BN_ULONG);
    bn_fix_top(psign->s);

err:
    if (psign)
    {
        DSA_SIG_free(psign);
        psign=NULL;
    }
    return psign;
}
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:51,代码来源:e_sureware.cpp


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