这篇教程C++ BN_hex2bn函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中BN_hex2bn函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_hex2bn函数的具体用法?C++ BN_hex2bn怎么用?C++ BN_hex2bn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了BN_hex2bn函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: _BN_randint _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,
示例2: dh_new_group_ascDH *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,
示例3: init_checksum/* * Initialize everything necessary to check the signature of the given image. * Returns non-zero if successful, 0 otherwise. */intinit_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,
示例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,
示例5: fprintfstatic 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,
示例6: APSetKeyBoolean 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,
示例7: BN_CTX_newpolypseud_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,
示例8: test_Div_open_sslvoid 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,
示例9: printfstatic 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は公 C++ BN_init函数代码示例 C++ BN_get_word函数代码示例
|