本文整理汇总了C++中BN_hex2bn函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_hex2bn函数的具体用法?C++ BN_hex2bn怎么用?C++ BN_hex2bn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BN_hex2bn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例5: 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
示例6: 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
示例7: 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
示例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
示例16: 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
示例17: next_pkey
int next_pkey(RSA *pub, FILE *fp)
{
static char nbuf[2048];
static char ebuf[10];
if (fscanf(fp, "%s\t%s", nbuf, ebuf) != 2)
return 0;
BN_hex2bn(&pub->n, nbuf);
BN_hex2bn(&pub->e, ebuf);
return 1;
}
开发者ID:fxfactorial,项目名称:bachelor,代码行数:11,代码来源:despicable.c
示例18: openssl_bioBN_math
void openssl_bioBN_math()
{
BIO *outs;
BN_CTX *ctx;
char num1[8], num2[8];
BIGNUM *bg1, *bg2, *tmp, *stp;
bg1 = BN_new();
bg2 = BN_new();
tmp = BN_new();
ctx = BN_CTX_new();
strcpy(num1, "84");
strcpy(num2, "3");
BN_hex2bn(&bg1, num1);
BN_hex2bn(&bg2, num2);
outs = BIO_new(BIO_s_file());
BIO_set_fp(outs, stdout, BIO_NOCLOSE);
printf("\nBIO_MATH as follow:\n");
BN_add(tmp, bg1, bg2);
BIO_puts(outs, "\tbn(0x84 + 0x3) = 0x");
BN_print(outs, tmp);
BIO_puts(outs, "\n");
BN_sub(tmp, bg1, bg2);
BIO_puts(outs, "\tbn(0x84 - 0x3) = 0x");
BN_print(outs, tmp);
BIO_puts(outs, "\n");
BN_mul(tmp, bg1, bg2, ctx);
BIO_puts(outs, "\tbn(0x84 * 0x3) = 0x");
BN_print(outs, tmp);
BIO_puts(outs, "\n");
BN_sqr(tmp, bg1, ctx);
BIO_puts(outs, "\tbn(sqr(0x84)) = 0x");
BN_print(outs, tmp);
BIO_puts(outs, "\n");
BN_div(tmp, stp, bg1, bg2, ctx);
BIO_puts(outs, "\tbn(0x84 / 0x3) = 0x");
BN_print(outs, tmp);
BIO_puts(outs, "\n");
BN_exp(tmp, bg1, bg2, ctx);
BIO_puts(outs, "\tbn(0x84 e 0x03)= 0x");
BN_print(outs, tmp);
BIO_puts(outs, "\n");
BN_free(bg1);
BN_free(bg2);
BN_free(tmp);
BIO_free(outs);
}
开发者ID:beike2020,项目名称:source,代码行数:54,代码来源:openssl_base.c
示例19: OPENSSL_assert
rsa_prvkey_t *rsa_prvkey_new_from_str(const char *str)
{
RSA *rsa = NULL;
char n_buf[1024];
char e_buf[1024];
char d_buf[1024];
OPENSSL_assert(str);
if (strlen(str) > sizeof(n_buf)) {
fprintf(stderr, "invalid data\n");
return NULL;
}
if (sscanf(str, "%s %s %s", n_buf, e_buf, d_buf) != 3) {
fprintf(stderr, "invalid data\n");
return NULL;
}
if (!(rsa = RSA_new())) {
ERR_print_errors_fp(stderr);
return NULL;
}
if (!BN_hex2bn(&rsa->n, n_buf)) {
ERR_print_errors_fp(stderr);
RSA_free(rsa);
return NULL;
}
if (!BN_hex2bn(&rsa->e, e_buf)) {
ERR_print_errors_fp(stderr);
RSA_free(rsa);
return NULL;
}
if (!BN_hex2bn(&rsa->d, d_buf)) {
ERR_print_errors_fp(stderr);
RSA_free(rsa);
return NULL;
}
if (!RSA_check_key(rsa)) {
ERR_print_errors_fp(stderr);
RSA_free(rsa);
return NULL;
}
return rsa;
}
开发者ID:sara62,项目名称:hcrypt,代码行数:50,代码来源:hcrypt_rsa_lib.c
示例20: dh_new_group_asc
DH *
dh_new_group_asc(const char *gen, const char *modulus)
{
DH *dh;
if ((dh = DH_new()) == NULL)
return NULL;
if (BN_hex2bn(&dh->p, modulus) == 0 ||
BN_hex2bn(&dh->g, gen) == 0) {
DH_free(dh);
return NULL;
}
return (dh);
}
开发者ID:AaronDP,项目名称:openssh4android,代码行数:14,代码来源:dh.c
注:本文中的BN_hex2bn函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论