本文整理匯總了C++中BN_print_fp函數的典型用法代碼示例。如果您正苦於以下問題:C++ BN_print_fp函數的具體用法?C++ BN_print_fp怎麽用?C++ BN_print_fp使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BN_print_fp函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: test
/**
* \brief Test for a pair of moduluses having a prime factor in common.
*
*/
int test(BIGNUM *n, BIGNUM *m)
{
BIGNUM *g;
BN_CTX *ctx;
int ret = 0;
if (!BN_cmp(n, m)) return 1;
g = BN_new();
ctx = BN_CTX_new();
BN_gcd(g, n, m, ctx);
if (!BN_is_one(g)) {
fprintf(stdout, "%-8s: ", PRIME);
BN_print_fp(stdout, n);
fprintf(stdout, " ");
BN_print_fp(stdout, m);
fprintf(stdout, "\n");
ret = 1;
}
BN_CTX_free(ctx);
BN_free(g);
return ret;
}
示例2: dump_dsa_sig
void dump_dsa_sig(const char *message, DSA_SIG *sig)
{
fprintf(stderr,"%s\nR=",message);
BN_print_fp(stderr,sig->r);
fprintf(stderr,"\nS=");
BN_print_fp(stderr,sig->s);
fprintf(stderr,"\n");
}
示例3: dump_dsa_sig
void dump_dsa_sig(const char *message, DSA_SIG *sig)
{
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"%s\nR=",message);
BN_print_fp(OPENSSL_TYPE__FILE_STDERR,sig->r);
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"\nS=");
BN_print_fp(OPENSSL_TYPE__FILE_STDERR,sig->s);
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"\n");
}
示例4: test_lshift
int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
{
BIGNUM *a,*b,*c,*d;
int i;
b=BN_new();
c=BN_new();
d=BN_new();
BN_one(c);
if(a_)
a=a_;
else
{
a=BN_new();
BN_bntest_rand(a,200,0,0); /**/
a->neg=rand_neg();
}
for (i=0; i<num0; i++)
{
BN_lshift(b,a,i+1);
BN_add(c,c,c);
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp," * ");
BN_print(bp,c);
BIO_puts(bp," - ");
}
BN_print(bp,b);
BIO_puts(bp,"\n");
}
BN_mul(d,a,c,ctx);
BN_sub(d,d,b);
if(!BN_is_zero(d))
{
fprintf(stderr,"Left shift test failed!\n");
fprintf(stderr,"a=");
BN_print_fp(stderr,a);
fprintf(stderr,"\nb=");
BN_print_fp(stderr,b);
fprintf(stderr,"\nc=");
BN_print_fp(stderr,c);
fprintf(stderr,"\nd=");
BN_print_fp(stderr,d);
fprintf(stderr,"\n");
return 0;
}
}
BN_free(a);
BN_free(b);
BN_free(c);
BN_free(d);
return(1);
}
示例5: bn8_cmp_bn
void bn8_cmp_bn(bn8 a, uint8_t size, BIGNUM *b, int i)
{
BIGNUM *aBN = BN_new();
BN_bin2bn(a, size, aBN);
if(BN_cmp(aBN, b) != 0) {
printf("cmp fail %d\n", i);
BN_print_fp(stdout, aBN); printf("\n");
BN_print_fp(stdout, b); printf("\n");
}
}
示例6: a_is_zero_mod_one
/*
* Test that r == 0 in test_exp_mod_zero(). Returns one on success,
* returns zero and prints debug output otherwise.
*/
static int a_is_zero_mod_one(const char *method, const BIGNUM *r,
const BIGNUM *a) {
if (!BN_is_zero(r)) {
fprintf(stderr, "%s failed:\n", method);
fprintf(stderr, "a ** 0 mod 1 = r (should be 0)\n");
fprintf(stderr, "a = ");
BN_print_fp(stderr, a);
fprintf(stderr, "\nr = ");
BN_print_fp(stderr, r);
fprintf(stderr, "\n");
return 0;
}
return 1;
}
示例7: main
int main(int argc, char **argv)
{
FILE *fp;
RSA *rsa;
int proc, procs;
int i;
QA_library_init();
MPI_Comm_rank(MPI_COMM_WORLD, &proc);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
if (argc < 1) return EXIT_FAILURE;
if (!(fp = fopen(argv[argc-1], "r"))) return EXIT_FAILURE;
rsa = RSA_new();
rsa->n = BN_new();
rsa->e = BN_new();
for (i=0; next_pkey(rsa, fp); i = (i+1) % procs) {
if (i != proc) continue;
if (run_question(question, NULL, rsa) == 1) {
BN_print_fp(stdout, rsa->n);
fprintf(stdout, "\t broken\n");
}
}
MPI_Finalize();
return EXIT_SUCCESS;
}
示例8: pr_fact
/*
* pr_fact - print the factors of a number
*
* Print the factors of the number, from the lowest to the highest.
* A factor will be printed multiple times if it divides the value
* multiple times.
*
* Factors are printed with leading tabs.
*/
static void
pr_fact(BIGNUM *val)
{
const ubig *fact; /* The factor found. */
/* Firewall - catch 0 and 1. */
if (BN_is_zero(val)) /* Historical practice; 0 just exits. */
exit(0);
if (BN_is_one(val)) {
printf("1: 1\n");
return;
}
/* Factor value. */
if (hflag) {
fputs("0x", stdout);
BN_print_fp(stdout, val);
} else
BN_print_dec_fp(stdout, val);
putchar(':');
for (fact = &prime[0]; !BN_is_one(val); ++fact) {
/* Look for the smallest factor. */
do {
if (BN_mod_word(val, (BN_ULONG)*fact) == 0)
break;
} while (++fact <= pr_limit);
/* Watch for primes larger than the table. */
if (fact > pr_limit) {
#ifdef HAVE_OPENSSL
BIGNUM *bnfact;
bnfact = BN_new();
BN_set_word(bnfact, *(fact - 1));
if (!BN_sqr(bnfact, bnfact, ctx))
errx(1, "error in BN_sqr()");
if (BN_cmp(bnfact, val) > 0 ||
BN_is_prime(val, PRIME_CHECKS,
NULL, NULL, NULL) == 1)
pr_print(val);
else
pollard_pminus1(val);
#else
pr_print(val);
#endif
break;
}
/* Divide factor out until none are left. */
do {
printf(hflag ? " 0x%lx" : " %lu", *fact);
BN_div_word(val, (BN_ULONG)*fact);
} while (BN_mod_word(val, (BN_ULONG)*fact) == 0);
/* Let the user know we're doing something. */
fflush(stdout);
}
putchar('\n');
}
示例9: main
int main(int argc, char* argv[]){
int res;
int toGet;
std::vector<RSA*> allPrivateKeys;
uint32_t allPublicKeys[100][32];
if(argc != 3){
puts("wrong number of args. takes db to open, num to get");
return 0;
}
puts("Starting key printer...");
toGet = atoi(argv[2]);
//run through the DB passed in and get all they keys from it
res = getAllKeys(argv[1], toGet, &allPrivateKeys, allPublicKeys);
printf("Asked for %d keys, got %d\n", toGet, res);
printf("after, vector of private keys was %d\n", (int)allPrivateKeys.size());
printf("after, vector of public keys was %d\n", res);
//RSA_print_fp(stdout, allPrivateKeys.at(0), 0);
//0 is MSB for our 1024
BIGNUM *n = allPrivateKeys.at(0)->n;
BN_print_fp(stdout, n);
printf("\ntop = %d and 0th is\t%02x\n", n->dmax, (uint32_t)n->d[0]);
printf("bottom = \t\t%02x\n", allPublicKeys[0][31]);
return 0;
}
示例10: showbn
static void showbn(const char *name, const BIGNUM *bn)
{
fputs(name, stdout);
fputs(" = ", stdout);
BN_print_fp(stdout, bn);
putc('\n', stdout);
}
示例11: test_exp_mod_zero
/*
* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success.
*/
static int test_exp_mod_zero()
{
BIGNUM a, p, m;
BIGNUM r;
BN_CTX *ctx = BN_CTX_new();
int ret = 1;
BN_init(&m);
BN_one(&m);
BN_init(&a);
BN_one(&a);
BN_init(&p);
BN_zero(&p);
BN_init(&r);
BN_mod_exp(&r, &a, &p, &m, ctx);
BN_CTX_free(ctx);
if (BN_is_zero(&r))
ret = 0;
else {
printf("1**0 mod 1 = ");
BN_print_fp(stdout, &r);
printf(", should be 0\n");
}
BN_free(&r);
BN_free(&a);
BN_free(&p);
BN_free(&m);
return ret;
}
示例12: pkey_gost01_cp_verify
static int pkey_gost01_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
size_t siglen, const unsigned char *tbs, size_t tbs_len)
{
int ok = 0;
EVP_PKEY* pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
DSA_SIG *s=unpack_cp_signature(sig,siglen);
if (!s) return 0;
#ifdef DEBUG_SIGN
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"R=");
BN_print_fp(OPENSSL_TYPE__FILE_STDERR,s->r);
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"\nS=");
BN_print_fp(OPENSSL_TYPE__FILE_STDERR,s->s);
TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"\n");
#endif
if (pub_key) ok = gost2001_do_verify(tbs,tbs_len,s,(EC_KEY*)EVP_PKEY_get0(pub_key));
DSA_SIG_free(s);
return ok;
}
示例13: pkey_gost01_cp_verify
static int pkey_gost01_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
size_t siglen, const unsigned char *tbs, size_t tbs_len)
{
int ok = 0;
EVP_PKEY* pub_key = EVP_PKEY_CTX_get0_pkey(ctx);
DSA_SIG *s=unpack_cp_signature(sig,siglen);
if (!s) return 0;
#ifdef DEBUG_SIGN
fprintf(stderr,"R=");
BN_print_fp(stderr,s->r);
fprintf(stderr,"\nS=");
BN_print_fp(stderr,s->s);
fprintf(stderr,"\n");
#endif
if (pub_key) ok = gost2001_do_verify(tbs,tbs_len,s,EVP_PKEY_get0(pub_key));
DSA_SIG_free(s);
return ok;
}
示例14: pr_print
static void
pr_print(BIGNUM *val)
{
if (hflag) {
fputs(" 0x", stdout);
BN_print_fp(stdout, val);
} else {
putchar(' ');
BN_print_dec_fp(stdout, val);
}
}
示例15: fill_GOST2001_params
/*
* Fills EC_KEY structure hidden in the app_data field of DSA structure
* with parameter information, extracted from parameter array in
* params.c file.
*
* Also fils DSA->q field with copy of EC_GROUP order field to make
* DSA_size function work
*/
int fill_GOST2001_params(EC_KEY *eckey, int nid)
{
R3410_2001_params *params = R3410_2001_paramset;
EC_GROUP *grp = NULL;
BIGNUM *p = NULL, *q = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL;
EC_POINT *P = NULL;
BN_CTX *ctx = BN_CTX_new();
int ok = 0;
BN_CTX_start(ctx);
p = BN_CTX_get(ctx);
a = BN_CTX_get(ctx);
b = BN_CTX_get(ctx);
x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
q = BN_CTX_get(ctx);
while (params->nid != NID_undef && params->nid != nid)
params++;
if (params->nid == NID_undef) {
GOSTerr(GOST_F_FILL_GOST2001_PARAMS,
GOST_R_UNSUPPORTED_PARAMETER_SET);
goto err;
}
BN_hex2bn(&p, params->p);
BN_hex2bn(&a, params->a);
BN_hex2bn(&b, params->b);
grp = EC_GROUP_new_curve_GFp(p, a, b, ctx);
P = EC_POINT_new(grp);
BN_hex2bn(&x, params->x);
BN_hex2bn(&y, params->y);
EC_POINT_set_affine_coordinates_GFp(grp, P, x, y, ctx);
BN_hex2bn(&q, params->q);
#ifdef DEBUG_KEYS
fprintf(stderr, "Set params index %d oid %s\nq=",
(params - R3410_2001_paramset), OBJ_nid2sn(params->nid));
BN_print_fp(stderr, q);
fprintf(stderr, "\n");
#endif
EC_GROUP_set_generator(grp, P, q, NULL);
EC_GROUP_set_curve_name(grp, params->nid);
EC_KEY_set_group(eckey, grp);
ok = 1;
err:
EC_POINT_free(P);
EC_GROUP_free(grp);
BN_CTX_end(ctx);
BN_CTX_free(ctx);
return ok;
}