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


C++ ASN1_INTEGER_new函数代码示例

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


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

示例1: RSA_PSS_PARAMS_new

RSA_PSS_PARAMS *rsa_pss_params_create(const EVP_MD *sigmd,
                                      const EVP_MD *mgf1md, int saltlen)
{
    RSA_PSS_PARAMS *pss = RSA_PSS_PARAMS_new();

    if (pss == NULL)
        goto err;
    if (saltlen != 20) {
        pss->saltLength = ASN1_INTEGER_new();
        if (pss->saltLength == NULL)
            goto err;
        if (!ASN1_INTEGER_set(pss->saltLength, saltlen))
            goto err;
    }
    if (!rsa_md_to_algor(&pss->hashAlgorithm, sigmd))
        goto err;
    if (mgf1md == NULL)
        mgf1md = sigmd;
    if (!rsa_md_to_mgf1(&pss->maskGenAlgorithm, mgf1md))
        goto err;
    if (!rsa_md_to_algor(&pss->maskHash, mgf1md))
        goto err;
    return pss;
 err:
    RSA_PSS_PARAMS_free(pss);
    return NULL;
}
开发者ID:Bilibili,项目名称:openssl,代码行数:27,代码来源:rsa_ameth.c

示例2: create_nonce

static ASN1_INTEGER *
create_nonce(int bits)
{
	unsigned char buf[20];
	ASN1_INTEGER *nonce = NULL;
	int len = (bits - 1) / 8 + 1;
	int i;

	/* Generating random byte sequence. */
	if (len > (int) sizeof(buf))
		goto err;
	arc4random_buf(buf, len);

	/* Find the first non-zero byte and creating ASN1_INTEGER object. */
	for (i = 0; i < len && !buf[i]; ++i)
		;
	if (!(nonce = ASN1_INTEGER_new()))
		goto err;
	free(nonce->data);
	/* Allocate at least one byte. */
	nonce->length = len - i;
	if (!(nonce->data = malloc(nonce->length + 1)))
		goto err;
	memcpy(nonce->data, buf + i, nonce->length);

	return nonce;

err:
	BIO_printf(bio_err, "could not create nonce\n");
	ASN1_INTEGER_free(nonce);
	return NULL;
}
开发者ID:Heratom,项目名称:Firefly-project,代码行数:32,代码来源:ts.c

示例3: EVP_PKEY_CTX_get0_pkey

/* rsa_ctx_to_pss converts EVP_PKEY_CTX in PSS mode into corresponding
 * algorithm parameter, suitable for setting as an AlgorithmIdentifier. */
static ASN1_STRING *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx) {
  const EVP_MD *sigmd, *mgf1md;
  RSA_PSS_PARAMS *pss = NULL;
  ASN1_STRING *os = NULL;
  EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(pkctx);
  int saltlen, rv = 0;

  if (!EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) ||
      !EVP_PKEY_CTX_get_rsa_mgf1_md(pkctx, &mgf1md) ||
      !EVP_PKEY_CTX_get_rsa_pss_saltlen(pkctx, &saltlen)) {
    goto err;
  }

  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) - 1) & 0x7) == 0) {
      saltlen--;
    }
  } else {
    goto err;
  }

  pss = RSA_PSS_PARAMS_new();
  if (!pss) {
    goto err;
  }

  if (saltlen != 20) {
    pss->saltLength = ASN1_INTEGER_new();
    if (!pss->saltLength ||
        !ASN1_INTEGER_set(pss->saltLength, saltlen)) {
      goto err;
    }
  }

  if (!rsa_md_to_algor(&pss->hashAlgorithm, sigmd) ||
      !rsa_md_to_mgf1(&pss->maskGenAlgorithm, mgf1md)) {
    goto err;
  }

  /* Finally create string with pss parameter encoding. */
  if (!ASN1_item_pack(pss, ASN1_ITEM_rptr(RSA_PSS_PARAMS), &os)) {
    goto err;
  }
  rv = 1;

err:
  if (pss) {
    RSA_PSS_PARAMS_free(pss);
  }
  if (rv) {
    return os;
  }
  if (os) {
    ASN1_STRING_free(os);
  }
  return NULL;
}
开发者ID:krunalsoni01,项目名称:src,代码行数:62,代码来源:p_rsa_asn1.c

示例4: memcpy

static ASN1_INTEGER *create_nonce(int bits)
{
    unsigned char buf[20];
    ASN1_INTEGER *nonce = NULL;
    int len = (bits - 1) / 8 + 1;
    int i;

    if (len > (int)sizeof(buf))
        goto err;
    if (RAND_bytes(buf, len) <= 0)
        goto err;

    /* Find the first non-zero byte and creating ASN1_INTEGER object. */
    for (i = 0; i < len && !buf[i]; ++i)
        continue;
    if ((nonce = ASN1_INTEGER_new()) == NULL)
        goto err;
    OPENSSL_free(nonce->data);
    nonce->length = len - i;
    nonce->data = app_malloc(nonce->length + 1, "nonce buffer");
    memcpy(nonce->data, buf + i, nonce->length);
    return nonce;

 err:
    BIO_printf(bio_err, "could not create nonce\n");
    ASN1_INTEGER_free(nonce);
    return NULL;
}
开发者ID:Beatzevo,项目名称:openssl,代码行数:28,代码来源:ts.c

示例5: AUTHORITY_KEYID_new

X509_EXTENSION* AuthorityKeyIdentifierExtension::getX509Extension()
{
    X509_EXTENSION *ret;
    AUTHORITY_KEYID *authKeyId;
    ByteArray temp;
    authKeyId = AUTHORITY_KEYID_new();
    if (this->keyIdentifier.size() > 0)
    {
        authKeyId->keyid = ASN1_OCTET_STRING_new();
        temp = this->keyIdentifier;
        ASN1_OCTET_STRING_set(authKeyId->keyid, temp.getDataPointer(), temp.size());
    }
    if (this->authorityCertIssuer.getNumberOfEntries() > 0)
    {
        authKeyId->issuer = this->authorityCertIssuer.getInternalGeneralNames();
    }
    if (this->serialNumber >= 0)
    {
        authKeyId->serial = ASN1_INTEGER_new();
        ASN1_INTEGER_set(authKeyId->serial, this->serialNumber);
    }
    ret = X509V3_EXT_i2d(NID_authority_key_identifier, this->critical?1:0, (void *)authKeyId);
    AUTHORITY_KEYID_free(authKeyId);
    return ret;
}
开发者ID:GNakayama,项目名称:libcryptosec,代码行数:25,代码来源:AuthorityKeyIdentifierExtension.cpp

示例6: VMCAGetNextCrlNumber

DWORD
VMCAGetNextCrlNumber(
    X509_CRL *pCrl,
    DWORD *pNextNum
)
{
    DWORD dwError = 0;
    ASN1_INTEGER *pCrlNumber = NULL;
    long nCrlNum = 0;

    if(pCrl == NULL) {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_ERROR(dwError);
    }

    pCrlNumber = ASN1_INTEGER_new();
    if(pCrlNumber == NULL) {
        dwError = VMCA_OUT_MEMORY_ERR;
        BAIL_ON_ERROR(dwError);
    }

    pCrlNumber = X509_CRL_get_ext_d2i(pCrl, NID_crl_number, 0,0);
    nCrlNum = ASN1_INTEGER_get(pCrlNumber);
    nCrlNum++;
    *pNextNum = nCrlNum;
cleanup:
    if(pCrlNumber) {
        ASN1_INTEGER_free(pCrlNumber);
    }
    return dwError;
error :
    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:33,代码来源:pkcs_crl.c

示例7: main

int main(int argc, char const *argv[])
{
	/* code */
	long value;
	int ret, len, i;
	unsigned char *buf = NULL;
	unsigned char *p;
	ASN1_INTEGER *a = ASN1_INTEGER_new();
	ret = ASN1_INTEGER_set(a, 100);

	len = i2d_ASN1_INTEGER(a, NULL);
	p = buf = malloc(sizeof(unsigned char) * len);

	len = i2d_ASN1_INTEGER(a, &buf);
	for( i = 0; i < len; i++)
	{
		//printf("%0x\t", p[i]);
		printf("%0x\t", buf[i]);
	}
	printf("\n");

	a= d2i_ASN1_INTEGER(&a, &p, len);
	value = ASN1_INTEGER_get(a);
	printf("value = %d\n", value);
	ASN1_INTEGER_free(a);
	return 0;
}
开发者ID:gwg-bhb,项目名称:exercise-win,代码行数:27,代码来源:asn1_1.c

示例8: d2i_ASN1_UINTEGER

ASN1_INTEGER *
d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
{
	ASN1_INTEGER *ret = NULL;
	const unsigned char *p;
	unsigned char *s;
	long len;
	int inf, tag, xclass;
	int i;

	if ((a == NULL) || ((*a) == NULL)) {
		if ((ret = ASN1_INTEGER_new()) == NULL)
			return (NULL);
	} else
		ret = (*a);

	p = *pp;
	inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
	if (inf & 0x80) {
		i = ASN1_R_BAD_OBJECT_HEADER;
		goto err;
	}

	if (tag != V_ASN1_INTEGER) {
		i = ASN1_R_EXPECTING_AN_INTEGER;
		goto err;
	}

	/* We must malloc stuff, even for 0 bytes otherwise it
	 * signifies a missing NULL parameter. */
	s = malloc(len + 1);
	if (s == NULL) {
		i = ERR_R_MALLOC_FAILURE;
		goto err;
	}
	ret->type = V_ASN1_INTEGER;
	if (len) {
		if ((*p == 0) && (len != 1)) {
			p++;
			len--;
		}
		memcpy(s, p, len);
		p += len;
	}

	free(ret->data);
	ret->data = s;
	ret->length = (int)len;
	if (a != NULL)
		(*a) = ret;
	*pp = p;
	return (ret);

err:
	ASN1error(i);
	if (a == NULL || *a != ret)
		ASN1_INTEGER_free(ret);
	return (NULL);
}
开发者ID:MiKTeX,项目名称:miktex,代码行数:59,代码来源:a_int.c

示例9: X509_CRL_set_version

int X509_CRL_set_version(X509_CRL *x, long version)
{
    if (x == NULL)
        return (0);
    if (x->crl.version == NULL) {
        if ((x->crl.version = ASN1_INTEGER_new()) == NULL)
            return (0);
    }
    return (ASN1_INTEGER_set(x->crl.version, version));
}
开发者ID:Beatzevo,项目名称:openssl,代码行数:10,代码来源:x509cset.c

示例10: x509_rsa_ctx_to_pss

int x509_rsa_ctx_to_pss(EVP_MD_CTX *ctx, X509_ALGOR *algor) {
  const EVP_MD *sigmd, *mgf1md;
  int saltlen;
  if (!EVP_PKEY_CTX_get_signature_md(ctx->pctx, &sigmd) ||
      !EVP_PKEY_CTX_get_rsa_mgf1_md(ctx->pctx, &mgf1md) ||
      !EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx->pctx, &saltlen)) {
    return 0;
  }

  EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(ctx->pctx);
  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) - 1) & 0x7) == 0) {
      saltlen--;
    }
  } else {
    return 0;
  }

  int ret = 0;
  ASN1_STRING *os = NULL;
  RSA_PSS_PARAMS *pss = RSA_PSS_PARAMS_new();
  if (!pss) {
    goto err;
  }

  if (saltlen != 20) {
    pss->saltLength = ASN1_INTEGER_new();
    if (!pss->saltLength ||
        !ASN1_INTEGER_set(pss->saltLength, saltlen)) {
      goto err;
    }
  }

  if (!rsa_md_to_algor(&pss->hashAlgorithm, sigmd) ||
      !rsa_md_to_mgf1(&pss->maskGenAlgorithm, mgf1md)) {
    goto err;
  }

  /* Finally create string with pss parameter encoding. */
  if (!ASN1_item_pack(pss, ASN1_ITEM_rptr(RSA_PSS_PARAMS), &os)) {
    goto err;
  }

  X509_ALGOR_set0(algor, OBJ_nid2obj(NID_rsassaPss), V_ASN1_SEQUENCE, os);
  os = NULL;
  ret = 1;

err:
  RSA_PSS_PARAMS_free(pss);
  ASN1_STRING_free(os);
  return ret;
}
开发者ID:MateusDeSousa,项目名称:FiqueRico,代码行数:55,代码来源:rsa_pss.c

示例11: X509_set_version

int
X509_set_version(X509 *x, long version)
{
	if (x == NULL)
		return (0);
	if (x->cert_info->version == NULL) {
		if ((x->cert_info->version = ASN1_INTEGER_new()) == NULL)
			return (0);
	}
	return (ASN1_INTEGER_set(x->cert_info->version, version));
}
开发者ID:2trill2spill,项目名称:nextgen,代码行数:11,代码来源:x509_set.c

示例12: VMCAGetCRLInfoPrivate

DWORD
VMCAGetCRLInfoPrivate(
    PSTR pszFileName,
    time_t *ptmLastUpdate,
    time_t *ptmNextUpdate,
    DWORD  *pdwCRLNumber)
{
    DWORD dwError = 0;
    X509_CRL *pCrl = NULL;
    ASN1_TIME *pLastUpdate = NULL;
    ASN1_TIME *pNextUpdate = NULL;
    ASN1_INTEGER *pCrlNumber = NULL;
    long nCrlNum = 0;

    if (   (IsNullOrEmptyString(pszFileName))
        || (ptmNextUpdate == NULL)
        || (ptmLastUpdate == NULL)
        || (pdwCRLNumber == NULL)
        ) {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_ERROR(dwError);
    }

    dwError = VMCAFileToCRL(pszFileName, &pCrl);
    BAIL_ON_ERROR(dwError);

    pLastUpdate = X509_CRL_get_lastUpdate(pCrl);
    pNextUpdate = X509_CRL_get_nextUpdate(pCrl);

    pCrlNumber = ASN1_INTEGER_new();
    if(pCrlNumber == NULL) {
        dwError = VMCA_OUT_MEMORY_ERR;
        BAIL_ON_ERROR(dwError);
    }
    pCrlNumber = X509_CRL_get_ext_d2i(pCrl, NID_crl_number, 0,0);
    nCrlNum = ASN1_INTEGER_get(pCrlNumber);
    *pdwCRLNumber = nCrlNum;

    dwError =  VMCAASN1ToTimeT(pLastUpdate,ptmLastUpdate);
    BAIL_ON_ERROR(dwError);

    dwError =  VMCAASN1ToTimeT(pNextUpdate,ptmNextUpdate);
    BAIL_ON_ERROR(dwError);


cleanup:
    if(pCrlNumber){
        ASN1_INTEGER_free(pCrlNumber);
    }
    VMCACrlFree(pCrl);
    return dwError;
error :
    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:54,代码来源:pkcs_crl.c

示例13: getRandomSN

ASN1_INTEGER* getRandomSN()
{
  ASN1_INTEGER* res = ASN1_INTEGER_new();
  BIGNUM *btmp = BN_new();
  //64 bits of randomness?
  BN_pseudo_rand(btmp, 64, 0, 0);
  BN_to_ASN1_INTEGER(btmp, res);

  BN_free(btmp);
  return res;
}
开发者ID:AlexWei2013,项目名称:Webinos-Platform,代码行数:11,代码来源:openssl_wrapper.cpp

示例14: ASN1_INTEGER_new

static ASN1_INTEGER *def_serial_cb(struct TS_resp_ctx *ctx, void *data)
	{
	ASN1_INTEGER *serial = ASN1_INTEGER_new();
	if (!serial) goto err;
	if (!ASN1_INTEGER_set(serial, 1)) goto err;
	return serial;
 err:
	TSerr(TS_F_DEF_SERIAL_CB, ERR_R_MALLOC_FAILURE);
	TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
				    "Error during serial number generation.");
	return NULL;
	}
开发者ID:RyunosukeOno,项目名称:rayjack,代码行数:12,代码来源:ts_rsp_sign.c

示例15: handle_serial

static char *
handle_serial (char * serial)
{
	int hex = NULL != strchr (serial, ':');

	/* Convert serial to a decimal serial when input is
	   a hexidecimal representation of the serial */
	if (hex)
	{
		unsigned int i,ii;
		char *tmp_serial = (char*) calloc (strlen (serial) + 1,1);

		for (i=0,ii=0; '\0'!=serial[i];i++)
		{
			if (':'!=serial[i])
				tmp_serial[ii++]=serial[i];
		}
		serial=tmp_serial;
	}
	else
	{
		unsigned int i;
		for (i=0; ! hex && '\0' != serial[i]; i++)
			hex = 'a'==serial[i]||'b'==serial[i]||'c'==serial[i]||'d'==serial[i]||'e'==serial[i]||'f'==serial[i];
	}

	if (hex)
	{
		ASN1_INTEGER* ai;
 		BIGNUM *ret;
 		BIO* in = BIO_new_mem_buf(serial, -1);
  		char buf[1025];
  		ai=ASN1_INTEGER_new();
  		if (ai == NULL) return NULL;
   		if (!a2i_ASN1_INTEGER(in,ai,buf,1024))
   		{
			return NULL;
   		}
   		ret=ASN1_INTEGER_to_BN(ai,NULL);
   		if (ret == NULL)
   		{
			return NULL;
   		}
   		else
   		{
    		 serial = BN_bn2dec(ret);
   		}
  	}

	return serial;
} /* handle_serial */
开发者ID:flomar,项目名称:sscep,代码行数:51,代码来源:sscep.c


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