當前位置: 首頁>>代碼示例>>C++>>正文


C++ BN_hex2bn函數代碼示例

本文整理匯總了C++中BN_hex2bn函數的典型用法代碼示例。如果您正苦於以下問題:C++ BN_hex2bn函數的具體用法?C++ BN_hex2bn怎麽用?C++ BN_hex2bn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BN_hex2bn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: _BN_rand

int _BN_rand(BIGNUM *rnd, int bits, int top,int bottom)
{
    static int i32 = 0;
    static int i256 = 0;
    int rsts = 0;

    switch(bits)
    {
      case 32:
        rsts = BN_hex2bn(&rnd, hex_bn32_rand[i32++]);
        if (i32 >= sizeof(hex_bn32_rand)/sizeof(char *))
        {
            i32 = 0;
        }

      break;

      case 256:
        rsts = BN_hex2bn(&rnd, hex_bn256_rand[i256++]);
        if (i256 >= sizeof(hex_bn256_rand)/sizeof(char *))
        {
            i256 = 0;
        }
      break;

      default:
      break;
    }

    return rsts;
}
開發者ID:Dan-McGee,項目名稱:lightwave,代碼行數:31,代碼來源:srp.c

示例2: dh_new_group_asc

DH *
dh_new_group_asc(const char *gen, const char *modulus)
{
	DH *dh = NULL;
	BIGNUM *p=NULL, *g=NULL;

	if ((dh = DH_new()) == NULL ||
	    (p = BN_new()) == NULL ||
	    (g = BN_new()) == NULL)
		goto null;
	if (BN_hex2bn(&p, modulus) == 0 ||
	    BN_hex2bn(&g, gen) == 0) {
		goto null;
	}
	if (DH_set0_pqg(dh, p, NULL, g) == 0) {
		goto null;
	}
	p = g = NULL;
	return (dh);
null:
	BN_free(p);
	BN_free(g);
	DH_free(dh);
	return NULL;
}
開發者ID:ozaki-r,項目名稱:netbsd-src,代碼行數:25,代碼來源:dh.c

示例3: init_checksum

/*
 * Initialize everything necessary to check the signature of the given image.
 * Returns non-zero if successful, 0 otherwise.
 */
int
init_checksum(char *keyfile)
{
	char str[1024];
	FILE *file;

	if (keyfile == NULL || (file = fopen(keyfile, "r")) == NULL) {
		fprintf(stderr, "%s: cannot open keyfile\n", keyfile);
		return 0;
	}
	if ((signature_key = RSA_new()) == NULL) {
		fprintf(stderr, "%s: cannot allocate RSA struct\n", keyfile);
		return 0;
	}

	fscanf(file, "%1024s", str);
	BN_hex2bn(&signature_key->n, str);
	fscanf(file, "%1024s", str);
	BN_hex2bn(&signature_key->e, str);
	fscanf(file, "%1024s", str);
	BN_hex2bn(&signature_key->dmp1, str);
	fscanf(file, "%1024s", str);
	BN_hex2bn(&signature_key->dmq1, str);
	fscanf(file, "%1024s", str);
	BN_hex2bn(&signature_key->iqmp, str);
	fclose(file);

	return 1; 
}
開發者ID:senseisimple,項目名稱:emulab-stable,代碼行數:33,代碼來源:checksum.c

示例4: BN_CTX_new

polypseud_ctx *polypseud_ctx_new() {
    polypseud_ctx *ctx = (polypseud_ctx*)malloc(sizeof(polypseud_ctx));
    ctx->bn_ctx = BN_CTX_new();
    ctx->p = BN_new();
    ctx->a = BN_new();
    ctx->b = BN_new();
    BN_hex2bn(&ctx->p, "D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27");
    BN_hex2bn(&ctx->a, "3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F492F375A97D860EB4");
    BN_hex2bn(&ctx->b, "520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD884539816F5EB4AC8FB1F1A6");
    ctx->ec_group = EC_GROUP_new_curve_GFp(ctx->p, ctx->a, ctx->b, ctx->bn_ctx);
    if(ctx->ec_group == NULL) {
        BN_free(ctx->p);
        BN_free(ctx->a);
        BN_free(ctx->b);
        BN_CTX_free(ctx->bn_ctx);
        return NULL;
    }
    ctx->q = BN_new();
    BN_hex2bn(&ctx->q, "D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D482EC7EE8658E98691555B44C59311");
    ctx->g = EC_POINT_new(ctx->ec_group);
    EC_POINT_hex2point(ctx->ec_group,
            "0443BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599C710AF8D0D39E2061114FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6AC7D35245D1692E8EE1",
            ctx->g, ctx->bn_ctx);
    EC_GROUP_set_generator(ctx->ec_group, ctx->g, ctx->q, BN_value_one());
    return ctx;
}
開發者ID:polymorphic-pseudonyms,項目名稱:libpolypseud,代碼行數:26,代碼來源:polypseud.c

示例5: memcpy

/**
* @brief Deserialize the supplied buffer into an RSA public key.
*
* Allocate a new RSA keypair and fill in the modulus and the exponent from
*	the public key stored in buf.
*
* @param buf Buffer containing the key to deserialize.
* @param len Length of the buffer.
*
* @return RSA *keypair on success, NULL on failure
*/
RSA *deserialize_rsa_pub_key(char *buf, size_t len) {
	(void)len; // TODO: use len to make sure we don't try to read past end of buffer

	/* get modulus */
	uint32_t hexformodsize = *(uint32_t*)buf;
	char *hexformod = (char*)malloc(hexformodsize + 1);
	memcpy(hexformod, &buf[sizeof(uint32_t)], hexformodsize);
	hexformod[hexformodsize] = '\0';
	DBGF("hexformod: %s", hexformod);

	/* get exponent */
	uint32_t hexforexpsize = *(uint32_t*)&buf[sizeof(uint32_t) + hexformodsize];
	char *hexforexp = (char*)malloc(hexforexpsize + 1);
	memcpy(hexforexp, &buf[2*sizeof(uint32_t) + hexformodsize], hexforexpsize);
	hexforexp[hexforexpsize] = '\0';
	DBGF("hexforexp: %s", hexforexp);

	/* make the keypair */
    RSA *keypair = RSA_new();
    BN_hex2bn(&keypair->n, hexformod); // TODO: need BN_new() first?
    BN_hex2bn(&keypair->e, hexforexp);
    keypair->d = NULL;
    keypair->p = NULL;
    keypair->q = NULL;
    keypair->dmp1 = NULL;
    keypair->dmq1 = NULL;
    keypair->iqmp = NULL;

	free(hexformod);
	free(hexforexp);

	return keypair;
}
開發者ID:BigQNo2,項目名稱:xia-core,代碼行數:44,代碼來源:XSSL_util.c

示例6: fprintf

static EVP_PKEY *create_pkey(neverbleed_t *nb, size_t key_index, const char *ebuf, const char *nbuf)
{
    struct st_neverbleed_rsa_exdata_t *exdata;
    RSA *rsa;
    EVP_PKEY *pkey;

    if ((exdata = malloc(sizeof(*exdata))) == NULL) {
        fprintf(stderr, "no memory\n");
        abort();
    }
    exdata->nb = nb;
    exdata->key_index = key_index;

    rsa = RSA_new_method(nb->engine);
    RSA_set_ex_data(rsa, 0, exdata);
    if (BN_hex2bn(&rsa->e, ebuf) == 0) {
        fprintf(stderr, "failed to parse e:%s\n", ebuf);
        abort();
    }
    if (BN_hex2bn(&rsa->n, nbuf) == 0) {
        fprintf(stderr, "failed to parse n:%s\n", nbuf);
        abort();
    }
    rsa->flags |= RSA_FLAG_EXT_PKEY;

    pkey = EVP_PKEY_new();
    EVP_PKEY_set1_RSA(pkey, rsa);
    RSA_free(rsa);

    return pkey;
}
開發者ID:johnjohnsp1,項目名稱:neverbleed,代碼行數:31,代碼來源:neverbleed.c

示例7: 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

示例8: test_Div_open_ssl

void test_Div_open_ssl()
{
    myInt64 cycles;
    myInt64 start;
    int num_runs = NUM_RUNS;
    
    BN_CTX *ctx;
    ctx = BN_CTX_new();
    BIGNUM *a = BN_new();
	BIGNUM *b = BN_new();
	BIGNUM *result = BN_new();
	BIGNUM *rem = BN_new();

    BN_hex2bn(&a, "7cd73b6fc007dfee34a23caf363ae67e8bb8782600000000032accceb");
    BN_hex2bn(&b, "c69d8b898f0e43b4643a018e7b0569de6f8cf328e0bf6d59ace4e3bc2ca28d10");


    start = start_tsc();
    for(int i = 0; i < num_runs; i++)
    {
		BN_div(result, rem, b, a, ctx);
	}
    cycles = stop_tsc(start);

    double r;  
    r = cycles / num_runs;
    printf("RDTSC instruction:\n %lf cycles measured => %lf seconds, assuming frequency is %lf MHz. (change in source file if different)\n", r, r/(FREQUENCY), (FREQUENCY)/1e6);
	
    BN_CTX_free(ctx);
    BN_free(a);
	BN_free(b);
    BN_free(result);
	BN_free(rem);
}
開發者ID:tyrann,項目名稱:fastcode16,代碼行數:34,代碼來源:openssl_benchmark_div.c

示例9: printf

static DH *dh_new_group_asc(const char *gen, const char *modulus)
{
	DH *dh = NULL;

	if ((dh = DH_new()) == NULL) {
		printf("dh_new_group_asc: DH_new");
		goto error;
	}

	// PとGは公開してもよい素數の組み合わせ
	if (BN_hex2bn(&dh->p, modulus) == 0) {
		printf("BN_hex2bn p");
		goto error;
	}

	if (BN_hex2bn(&dh->g, gen) == 0) {
		printf("BN_hex2bn g");
		goto error;
	}

	return (dh);

error:
	DH_free(dh);
	return (NULL);
}
開發者ID:lifangbo,項目名稱:teraterm,代碼行數:26,代碼來源:kex.c

示例10: main

int main(int argc,char **argv)
    {
    ops_create_info_t *info;
    const unsigned char *id;
    const char *nstr;
    const char *estr;
    BIGNUM *n=NULL;
    BIGNUM *e=NULL;

    if(argc != 4)
	{
	fprintf(stderr,"%s <n> <e> <user id>\n",argv[0]);
	exit(1);
	}
    
    nstr=argv[1];
    estr=argv[2];
    id=(unsigned char *)argv[3];

    BN_hex2bn(&n,nstr);
    BN_hex2bn(&e,estr);

    info=ops_create_info_new();
    ops_writer_set_fd(info,1);

    ops_write_rsa_public_key(time(NULL),n,e,info);
    ops_write_user_id(id,info);

    ops_create_info_delete(info);

    return 0;
    }
開發者ID:agl,項目名稱:OpenPGP-SDK,代碼行數:32,代碼來源:create-key.c

示例11: Encode_RSA

void Encode_RSA(unsigned char *in,int fd)
{
	RSA *r;
	BIGNUM *bne,*bnn,*bnd;
	int bits = 1024, ret, len, flen, padding, i;
	unsigned char *key, *p;
	BIO *b;
	unsigned  char *encData,*decData,*tmpData;//加密後的數據/解密後的數據/臨時指針
       /* Key data */
	unsigned long e = 75011;  

	/* 構建RSA數據結構   */
	bne = BN_new();  
	bnd = BN_new();  
	bnn = BN_new();  
	ret = BN_set_word(bne, e);  
	BN_hex2bn(&bnd, PRIVATE);  
	BN_hex2bn(&bnn, MODULUS);  

	r = RSA_new();  
	r->e=bne;  
	r->d=bnd;  
	r->n=bnn;
	/* Debug output key */
	/*RSA_print_fp(stdout, r, 5);*/

	/*準備輸出的加密數據結構   */
	flen =  RSA_size(r);// - 11;   
	encData =  (unsigned char *)malloc(flen);  
	bzero(encData, flen);//memset(encData, 0, flen);   

	ret =  RSA_private_encrypt(flen, in, encData, r,  RSA_NO_PADDING);  
	if(ret < 0){
		JCG("Encrypt failed!\n");  
		return;  
	}  

	write(fd,encData,flen);

	tmpData=encData;  
#if 0
	for  (i=0; i<ret; i++)
	{
		JDG("0x%02x, ", *tmpData);
		if(i%16 == 7)
			JDG("\t");
		else if(i%16 == 15)
			JDG("\n");
		tmpData++;  
	}
	JDG("\n");

	JCG("end private encrypt ");
#endif

	free(encData);  
	RSA_free(r);  
}
開發者ID:princeofdream,項目名稱:debug_src_full,代碼行數:58,代碼來源:sn_writer.cpp

示例12: read_rsa_private_key

bool read_rsa_private_key(void) {
    FILE *fp;
    char *fname, *key, *pubkey;
    struct stat s;

    if(get_config_string(lookup_config(config_tree, "PrivateKey"), &key)) {
        if(!get_config_string(lookup_config(config_tree, "PublicKey"), &pubkey)) {
            logger(LOG_ERR, "PrivateKey used but no PublicKey found!");
            return false;
        }
        myself->connection->rsa_key = RSA_new();
//		RSA_blinding_on(myself->connection->rsa_key, NULL);
        BN_hex2bn(&myself->connection->rsa_key->d, key);
        BN_hex2bn(&myself->connection->rsa_key->n, pubkey);
        BN_hex2bn(&myself->connection->rsa_key->e, "FFFF");
        free(key);
        free(pubkey);
        return true;
    }

    if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
        xasprintf(&fname, "%s/rsa_key.priv", confbase);

    fp = fopen(fname, "r");

    if(!fp) {
        logger(LOG_ERR, "Error reading RSA private key file `%s': %s",
               fname, strerror(errno));
        free(fname);
        return false;
    }

#if !defined(HAVE_MINGW) && !defined(HAVE_CYGWIN)
    if(fstat(fileno(fp), &s)) {
        logger(LOG_ERR, "Could not stat RSA private key file `%s': %s'",
               fname, strerror(errno));
        free(fname);
        return false;
    }

    if(s.st_mode & ~0100700)
        logger(LOG_WARNING, "Warning: insecure file permissions for RSA private key file `%s'!", fname);
#endif

    myself->connection->rsa_key = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
    fclose(fp);

    if(!myself->connection->rsa_key) {
        logger(LOG_ERR, "Reading RSA private key file `%s' failed: %s",
               fname, strerror(errno));
        free(fname);
        return false;
    }

    free(fname);
    return true;
}
開發者ID:Rumko,項目名稱:tinc,代碼行數:57,代碼來源:net_setup.c

示例13: BN_hex2bn

Person::Person(const char *p_str, const char *g_str) {
  p = NULL;
  g = NULL;
  B = NULL;
  hash = NULL;
  BN_hex2bn(&p, p_str);
  BN_hex2bn(&g, g_str);
  set_keys();
}
開發者ID:imhotepisinvisible,項目名稱:cryptopals,代碼行數:9,代碼來源:person.cpp

示例14: get_own_data

void get_own_data(sqlite3* db, char** nickname, BIGNUM* e, BIGNUM* n, BIGNUM* d) {
	sqlite3_stmt *stmt;
	char* statement = "SELECT * FROM keys WHERE id = 0";
	sqlite3_prepare_v2(db, statement, strlen(statement) + 1 , &stmt, NULL);
	sqlite3_step(stmt);
	*nickname = (char*) sqlite3_column_text(stmt, 1);
	BN_hex2bn(&e, (const char*) sqlite3_column_text(stmt, 2));
	BN_hex2bn(&n, (const char*) sqlite3_column_text(stmt, 3));
	BN_hex2bn(&d, (const char*) sqlite3_column_text(stmt, 4));
}
開發者ID:StevenMohr,項目名稱:CryptoChat,代碼行數:10,代碼來源:sqlite.c

示例15: test_BN_cmp

static int
test_BN_cmp(void)
{
    BIGNUM *a, *b;

    a = BN_new();
    b = BN_new();

    if (!BN_set_word(a, 1))
	return 1;
    if (!BN_set_word(b, 1))
	return 1;

    if (BN_cmp(a, b) != 0)
	return 1;
    if (BN_cmp(b, a) != 0)
	return 1;

    if (!BN_set_word(b, 2))
	return 1;

    if (BN_cmp(a, b) >= 0)
	return 1;
    if (BN_cmp(b, a) <= 0)
	return 1;

    BN_set_negative(b, 1);

    if (BN_cmp(a, b) <= 0)
	return 1;
    if (BN_cmp(b, a) >= 0)
	return 1;

    BN_free(a);
    BN_free(b);

    BN_hex2bn(&a, "50212A3B611D46642C825A16A354CE0FD4D85DD1");
    BN_hex2bn(&b, "50212A3B611D46642C825A16A354CE0FD4D85DD2");

    if (BN_cmp(a, b) >= 0)
	return 1;
    if (BN_cmp(b, a) <= 0)
	return 1;

    BN_set_negative(b, 1);

    if (BN_cmp(a, b) <= 0)
	return 1;
    if (BN_cmp(b, a) >= 0)
	return 1;

    BN_free(a);
    BN_free(b);
    return 0;
}
開發者ID:Henauxg,項目名稱:minix,代碼行數:55,代碼來源:test_bn.c


注:本文中的BN_hex2bn函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。