• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ BN_dec2bn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: fill_GOST94_params

/*
 * Fill GOST 94 params, searching them in R3410_paramset array
 * by nid of paramset
 *
 */
int fill_GOST94_params (DSA * dsa, int nid)
{
    R3410_params *params = R3410_paramset;

    while (params->nid != NID_undef && params->nid != nid)
        params++;
    if (params->nid == NID_undef)
    {
        GOSTerr (GOST_F_FILL_GOST94_PARAMS, GOST_R_UNSUPPORTED_PARAMETER_SET);
        return 0;
    }
#define dump_signature(a,b,c)
    if (dsa->p)
    {
        BN_free (dsa->p);
    }
    dsa->p = NULL;
    BN_dec2bn (&(dsa->p), params->p);
    if (dsa->q)
    {
        BN_free (dsa->q);
    }
    dsa->q = NULL;
    BN_dec2bn (&(dsa->q), params->q);
    if (dsa->g)
    {
        BN_free (dsa->g);
    }
    dsa->g = NULL;
    BN_dec2bn (&(dsa->g), params->a);
    return 1;
}
开发者ID:274914765,项目名称:C,代码行数:37,代码来源:gost_sign.c


示例2: compute_mod

/*--------------------------------------------------*/
void compute_mod(Task * task)
{
	BN_CTX *context;
       	BIGNUM *r,*a,*p,*m;
        if(task->p==NULL){
	fprintf(stderr,"Wrong Exponent\n");
	exit(0);
        }
	/*Just printing out the client send numbers*/
 	printf("Printing the Exponent\n");	
        print_bignumber(task->p);
 	printf("Printing the Prime\n");	
	print_bignumber(task->m);
		
 	context = BN_CTX_new();
        r = BN_new();
	a = BN_new();
	p = BN_new();
	m = BN_new();

	BN_dec2bn(&a,"2");
	BN_dec2bn(&p,task->p);
	BN_dec2bn(&m,task->m);
	BN_mod_exp(r,a,p,m,context);

 	printf("Response ----\n");
	strcpy(task->response,BN_bn2dec(r));
	print_bignumber(task->response);
	
	return;
}
开发者ID:roguehit,项目名称:aos2,代码行数:32,代码来源:server.c


示例3: serverAct1

int serverAct1(Server * server) {
    int bytes;
    char buf[1024];
    char * bufptr = buf;
    char * tmpstr;

    printf("\n==== Этап 1 ====\n\n");
    
    server->k = BN_new();
    server->m = BN_new();

    bytes = BIO_read(server->conn, buf, 1024);
    buf[bytes] = 0;
    BN_dec2bn(&server->k, buf);
    tmpstr = BN_bn2dec(server->k);
    printf("k = %s\n", tmpstr);
    OPENSSL_free(tmpstr);

    BIO_puts(server->conn, "OK");

    bytes = BIO_read(server->conn, buf, 1024);
    buf[bytes] = 0;
    BN_dec2bn(&server->m, buf);
    tmpstr = BN_bn2dec(server->m);
    printf("m = %s\n", tmpstr);
    OPENSSL_free(tmpstr);

    BIO_puts(server->conn, "OK");

    return 0;
}
开发者ID:ei-grad,项目名称:rsazkp,代码行数:31,代码来源:server.c


示例4: main

int
main(int argc, char *argv[])
{
    BIGNUM *val;
    int ch;
    char *p, buf[LINE_MAX];		/* > max number of digits. */

    ctx = BN_CTX_new();
    val = BN_new();
    if (val == NULL)
        errx(1, "can't initialise bignum");

    while ((ch = getopt(argc, argv, "h")) != -1)
        switch (ch) {
        case 'h':
            hflag++;
            break;
        case '?':
        default:
            usage();
        }
    argc -= optind;
    argv += optind;

    /* No args supplied, read numbers from stdin. */
    if (argc == 0)
        for (;;) {
            if (fgets(buf, sizeof(buf), stdin) == NULL) {
                if (ferror(stdin))
                    err(1, "stdin");
                exit (0);
            }
            for (p = buf; isblank(*p); ++p);
            if (*p == '\n' || *p == '\0')
                continue;
            if (*p == '-')
                errx(1, "negative numbers aren't permitted.");
            if (BN_dec2bn(&val, buf) == 0 &&
                    BN_hex2bn(&val, buf) == 0)
                errx(1, "%s: illegal numeric format.", buf);
            pr_fact(val);
        }
    /* Factor the arguments. */
    else
        for (; *argv != NULL; ++argv) {
            if (argv[0][0] == '-')
                errx(1, "negative numbers aren't permitted.");
            if (BN_dec2bn(&val, argv[0]) == 0 &&
                    BN_hex2bn(&val, argv[0]) == 0)
                errx(1, "%s: illegal numeric format.", argv[0]);
            pr_fact(val);
        }
    exit(0);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:54,代码来源:factor.c


示例5: priv_to_pub

int priv_to_pub (unsigned char * const result, const size_t m, const unsigned char * const priv, const size_t n) {

  int ret = 0;
  int i = 0;

  BIGNUM * privbn = 0;
  BN_dec2bn(&privbn,"0");
  BIGNUM * pow256 = 0;
  BN_dec2bn(&pow256,"1");
  BIGNUM * one256 = 0;
  BN_dec2bn(&one256,"256");

  const unsigned char * input_it = priv + n - 1;
  for (i=0; i<n; i++) {
    BIGNUM * input_bn = 0;
    char * input_str = malloc(4);
    sprintf(input_str,"%d",*input_it);
    BN_dec2bn(&input_bn,input_str);
    BN_CTX * ctx = BN_CTX_new();
    BN_mul(input_bn, pow256, input_bn, ctx);
    BN_add(privbn,privbn,input_bn);
    BN_mul(pow256, pow256, one256, ctx);
    BN_free(input_bn);
    if (input_str != 0) {
      free(input_str);
    }
    BN_CTX_free(ctx);
    input_it--;
  }

  EC_GROUP * group = EC_GROUP_new_by_curve_name(NID_secp256k1);
  EC_POINT * pub_key = EC_POINT_new(group);
  BN_CTX * ctx = BN_CTX_new();
  EC_POINT_mul(group, pub_key, privbn, 0, 0, ctx);
  if (m == 65) {
    EC_POINT_point2oct(group,pub_key,POINT_CONVERSION_UNCOMPRESSED,result,m,ctx);
  }
  else {
    EC_POINT_point2oct(group,pub_key,POINT_CONVERSION_COMPRESSED,result,m,ctx);
  }

  EC_GROUP_free(group);
  EC_POINT_free(pub_key);
  BN_CTX_free(ctx);
  BN_free(privbn);
  BN_free(pow256);
  BN_free(one256);

  return(0);
}
开发者ID:piratelinux,项目名称:cwallet,代码行数:50,代码来源:cwallet.c


示例6: serverAct2

int serverAct2(Server * server) {

    int bytes;
    char buf[1024];
    
    printf("\n==== Этап 2 ====\n\n");

    bytes = BIO_read(server->conn, buf, 1024);
    buf[bytes] = 0;

    printf("Получен шифртекст: %s\n", buf);

    server->C = BN_new();

    if (!BN_dec2bn(&server->C, buf)) {
        fprintf(stderr, "Ошибка при получении шифртекста!");
        BIO_puts(server->conn, "ERR");
        return 1;
    }
    
    BIO_puts(server->conn, "OK");
    printf("Шифртест принят.\n");
    
    return 0;
}
开发者ID:ei-grad,项目名称:rsazkp,代码行数:25,代码来源:server.c


示例7: dec2bin

static int
dec2bin(uint8_t *out, const char *in)
{
	int ret, l;
	char *tmp = NULL;
	BIGNUM *B;

	if ((NULL == (B = BN_new())) ||
	    (0 == BN_dec2bn(&B, in)) ||
	    (NULL == (tmp = BN_bn2hex(B)))) {
		ret = RFC6287_ERR_OPENSSL;
		goto err;
	}
	if (256 < (l = strlen(tmp))) {
		ret = RFC6287_INVALID_CHALLENGE;
		goto err;
	}
	if (1 < l && '0' == tmp[0])
		ret = hex2bin(out, tmp + 1);
	else
		ret = hex2bin(out, tmp);
err:
	if (NULL != tmp)
		OPENSSL_free(tmp);
	if (NULL != B)
		BN_free(B);
	return ret;
}
开发者ID:sg2342,项目名称:pam_ocra,代码行数:28,代码来源:rfc6287.c


示例8: main

int main(int argc, char *argv[])
{
   BIGNUM *fat; // declaração de uma variável Big
   BN_ULONG a, f; // apenas um long int normal
   char *resp;
   int i;

   /* Primeiro tem que alocar as variáveis BIGNUM */
   fat = BN_new();

   for (i = 1; i < argc; i++) {
      printf("Calculando fatorial de %s\n", argv[i]); 

      /* convertendo string em long int */
      f = atoll(argv[i]); 

      /* forma de atribuir 1 a uma variável BIGNUM */
      BN_dec2bn(&fat, "1"); 

      for (a = 2; a <= f; a++) {
         BN_mul_word(fat, a);
      } 

      /* gerando uma string imprimível do resultado */
      resp = BN_bn2dec(fat); 

      /* impressão do resultado (agora é uma string) */
      printf("Fatorial de %s = %s\n", argv[i], resp);
   }
}
开发者ID:weltonvaz,项目名称:Primos,代码行数:30,代码来源:fatorialBig.c


示例9: ribs_ssl_set_options

int ribs_ssl_set_options(SSL_CTX *ssl_ctx, char *cipher_list) {
    /* bugs */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); /* almost all bugs */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2); /* disable SSLv2 per RFC 6176 */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv3); /* disable SSLv3. goodbye IE6 */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_COMPRESSION);
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);

    /* ciphers */
    if (!cipher_list)
        cipher_list = _HTTP_SERVER_SSL_CIPHERS;
    SSL_CTX_set_options(ssl_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
    if (0 == SSL_CTX_set_cipher_list(ssl_ctx, cipher_list))
        return LOGGER_ERROR("failed to initialize SSL:cipher_list"), -1;

    /* DH 2048 bits */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_DH_USE);
    DH *dh = DH_new();
    dh->p = get_rfc3526_prime_2048(NULL);
    BN_dec2bn(&dh->g, "2");
    if (0 == SSL_CTX_set_tmp_dh(ssl_ctx, dh))
        return LOGGER_ERROR("failed to initialize SSL:dh"), -1;
    DH_free(dh);

    /* Ecliptic Curve DH */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_ECDH_USE);
    EC_KEY *ecdh = EC_KEY_new_by_curve_name(OBJ_sn2nid("prime256v1"));
    if (ecdh == NULL)
        return LOGGER_ERROR("failed to initialize SSL:edch"), -1;
    SSL_CTX_set_tmp_ecdh(ssl_ctx, ecdh);
    EC_KEY_free(ecdh);

    return 0;
}
开发者ID:TrueSkills,项目名称:ribs2,代码行数:34,代码来源:ribs_ssl.c


示例10: serverAct3

int serverAct3(Server * server) {

    int bytes;
    char buf[1024];
    
    printf("\n==== Этап 3 ====\n\n");

    bytes = BIO_read(server->conn, buf, 1024);
    buf[bytes] = 0;

    printf("Получен X: %s\n", buf);

    server->X = BN_new();

    if (!BN_dec2bn(&server->X, buf)) {
        fprintf(stderr, "Ошибка при получении X!");
        BIO_puts(server->conn, "ERR");
        return 1;
    }
    
    BIO_puts(server->conn, "OK");
    printf("X принят.\n");
    
    return 0;
}
开发者ID:ei-grad,项目名称:rsazkp,代码行数:25,代码来源:server.c


示例11: BN_new

BIGNUM *BN_get(lua_State *L, int i)
{
  BIGNUM *x = BN_new();
  switch (lua_type(L, i))
  {
  case LUA_TNUMBER:
    BN_set_word(x, lua_tointeger(L, i));
    break;
  case LUA_TSTRING:
  {
    const char *s = lua_tostring(L, i);
    if (s[0] == 'X' || s[0] == 'x') BN_hex2bn(&x, s + 1);
    else BN_dec2bn(&x, s);
    break;
  }
  case LUA_TUSERDATA:
    BN_copy(x, CHECK_OBJECT(i, BIGNUM, "openssl.bn"));
    break;
  case LUA_TNIL:
    BN_free(x);
    x = NULL;
    break;
  }
  return x;
}
开发者ID:fiendish,项目名称:lua-openssl,代码行数:25,代码来源:misc.c


示例12: fbytes

static int fbytes(unsigned char *buf, int num)
{
    int ret = 0;
    BIGNUM *tmp = NULL;

    if (use_fake == 0)
        return old_rand->bytes(buf, num);

    use_fake = 0;

    if (fbytes_counter >= 8)
        return 0;
    if (!TEST_ptr(tmp = BN_new()))
        return 0;
    if (!TEST_true(BN_dec2bn(&tmp, numbers[fbytes_counter]))) {
        BN_free(tmp);
        return 0;
    }
    fbytes_counter++;
    if (TEST_int_eq(BN_num_bytes(tmp), num)
            && TEST_true(BN_bn2bin(tmp, buf)))
        ret = 1;
    BN_free(tmp);
    return ret;
}
开发者ID:Vonage,项目名称:openssl,代码行数:25,代码来源:ecdsatest.c


示例13: APSetKey

Boolean APSetKey(CFStringRef key)
{
    hash = CFSTR("");
    blacklist = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
    
    // Create a new key
    rsaKey = RSA_new();
    
    // Public exponent is always 3
    BN_hex2bn(&rsaKey->e, "3");
    
    CFMutableStringRef mutableKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key);
    if (!mutableKey)
        return FALSE;
    
    CFIndex maximumCStringLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(mutableKey), kCFStringEncodingMacRoman) + 1;
    char *keyCStringBuffer = malloc(maximumCStringLength);
    
    // Determine if we have a hex or decimal key
    CFStringLowercase(mutableKey, NULL);
    if (CFStringHasPrefix(mutableKey, CFSTR("0x"))) {
        CFStringTrim(mutableKey, CFSTR("0x"));
        CFStringGetCString(mutableKey, keyCStringBuffer, maximumCStringLength, kCFStringEncodingMacRoman);
        BN_hex2bn(&rsaKey->n, keyCStringBuffer);
    }
    else {
        CFStringGetCString(mutableKey, keyCStringBuffer, maximumCStringLength, kCFStringEncodingMacRoman);
        BN_dec2bn(&rsaKey->n, keyCStringBuffer);
    }
    CFRelease(mutableKey);
    free(keyCStringBuffer);
    
    return TRUE;
}
开发者ID:samdeane,项目名称:AquaticPrime,代码行数:34,代码来源:AquaticPrime.c


示例14: performDH

struct sec performDH(char *pubkeyRec,DH *privkey){
	
	struct sec s;
	int secret_size;
	/* Send the public key to the peer.
	* How this occurs will be specific to your situation (see main text below) */


	/* Receive the public key from the peer. In this example we're just hard coding a value */
	BIGNUM *pubkey = NULL;
	if(0 == (BN_dec2bn(&pubkey, pubkeyRec))) handleErrors();

	/* Compute the shared secret */
	unsigned char *secret;
	if(NULL == (secret = OPENSSL_malloc(sizeof(unsigned char) * (DH_size(privkey))))) handleErrors();

	if(0 > (secret_size = DH_compute_key(secret, pubkey, privkey))) handleErrors();

	/* Do something with the shared secret */
	/* Note secret_size may be less than DH_size(privkey) */
	printf("The shared secret is:\n");
	
	strcpy(s.value,secret);
	s.length=secret_size;
	/* Clean up */
	OPENSSL_free(secret);
	BN_free(pubkey);
	DH_free(privkey);

	return s;
}
开发者ID:deepanshululla,项目名称:Network-security,代码行数:31,代码来源:client.c


示例15: fbytes

int fbytes(unsigned char *buf, int num)
{
    int ret;
    BIGNUM *tmp = NULL;

    if (use_fake == 0)
        return old_rand->bytes(buf, num);

    use_fake = 0;

    if (fbytes_counter >= 8)
        return 0;
    tmp = BN_new();
    if (!tmp)
        return 0;
    if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) {
        BN_free(tmp);
        return 0;
    }
    fbytes_counter++;
    if (num != BN_num_bytes(tmp) || !BN_bn2bin(tmp, buf))
        ret = 0;
    else
        ret = 1;
    BN_free(tmp);
    return ret;
}
开发者ID:GH-JY,项目名称:openssl,代码行数:27,代码来源:ecdsatest.c


示例16: from_dec

		bignum bignum::from_dec(const std::string& str)
		{
			BIGNUM* bn = NULL;

			error::throw_error_if_not(BN_dec2bn(&bn, str.c_str()) != 0);

			return take_ownership(bn);
		}
开发者ID:0ver6tm,项目名称:freelan-all,代码行数:8,代码来源:bignum.cpp


示例17: NativeBN_BN_dec2bn

static int NativeBN_BN_dec2bn(JNIEnv* env, jclass, BIGNUM* a, jstring str) {
    if (!oneValidHandle(env, a)) return -1;
    ScopedUtfChars chars(env, str);
    if (chars.c_str() == NULL) {
        return -1;
    }
    return BN_dec2bn(&a, chars.c_str());
}
开发者ID:CarbonArmv6,项目名称:android_libcore,代码行数:8,代码来源:java_math_NativeBN.cpp


示例18: convert_to_bignum

BIGNUM* convert_to_bignum(JNIEnv *env, jstring str) {
    BIGNUM *res;
    const char *nativeStr;
    res = NULL;
    nativeStr = (*env)->GetStringUTFChars(env, str, 0);
    BN_dec2bn(&res, nativeStr);
    (*env)->ReleaseStringUTFChars(env, str, nativeStr);
    return res;
}
开发者ID:Talos-crypto,项目名称:Talos-Android,代码行数:9,代码来源:paillier.c


示例19:

a1int &a1int::setDec(const QString &s)
{
	BIGNUM *bn=0;
	if (!BN_dec2bn(&bn,s.toAscii()))
		openssl_error();
	BN_to_ASN1_INTEGER(bn, in);
	BN_free(bn);
	return *this;
}
开发者ID:LiTianjue,项目名称:xca,代码行数:9,代码来源:asn1int.cpp


示例20: NativeBN_BN_dec2bn

/**
 * public static native int BN_dec2bn(int, java.lang.String)
 */
static int NativeBN_BN_dec2bn(JNIEnv* env, jclass cls, BIGNUM* a, jstring str) {
    if (!oneValidHandle(env, a)) return -1;
    char* tmpStr = (char*)(*env)->GetStringUTFChars(env, str, NULL);
    if (tmpStr != NULL) {
        int len = BN_dec2bn(&a, tmpStr);
        (*env)->ReleaseStringUTFChars(env, str, tmpStr);
        return len; // len == 0: Error
    }
    else return -1; // Error outside BN.
}
开发者ID:Ar3kkusu,项目名称:android_libcore,代码行数:13,代码来源:BNInterface.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ BN_dup函数代码示例发布时间:2022-05-30
下一篇:
C++ BN_copy函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap