Lines Matching full:bignum
139 /* These preprocessor symbols control various aspects of the bignum headers and
144 * BN_DEBUG - turn on various debugging alterations to the bignum code
146 * mismanagement of bignum internals. You must also define BN_DEBUG.
296 /* get a clone of a BIGNUM with changed flags, for *temporary* use only
309 typedef struct bignum_st BIGNUM;
332 BIGNUM RR; /* used to convert to montgomery form */
333 BIGNUM N; /* The modulus */
334 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
335 * (Ni is only stored for bignum algorithm) */
346 BIGNUM N; /* the divisor */
347 BIGNUM Nr; /* the reciprocal */
415 BIGNUM *_tmp_bn = (a); \
425 const BIGNUM *BN_value_one(void);
433 BIGNUM *BN_CTX_get(BN_CTX *ctx);
435 int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
436 int BN_pseudo_rand(BIGNUM *rnd, int bits, int top,int bottom);
437 int BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
438 int BN_pseudo_rand_range(BIGNUM *rnd, const BIGNUM *range);
439 int BN_num_bits(const BIGNUM *a);
441 BIGNUM *BN_new(void);
442 void BN_init(BIGNUM *);
443 void BN_clear_free(BIGNUM *a);
444 BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
445 void BN_swap(BIGNUM *a, BIGNUM *b);
446 BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
447 int BN_bn2bin(const BIGNUM *a, unsigned char *to);
448 BIGNUM *BN_mpi2bn(const unsigned char *s,int len,BIGNUM *ret);
449 int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
450 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
451 int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
452 int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
453 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
454 int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
455 int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
456 /** BN_set_negative sets sign of a BIGNUM
457 * \param b pointer to the BIGNUM object
458 * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise
460 void BN_set_negative(BIGNUM *b, int n);
461 /** BN_is_negative returns 1 if the BIGNUM is negative
462 * \param a pointer to the BIGNUM object
467 int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
470 int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
471 int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
472 int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
473 int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
474 int BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m);
475 int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
476 const BIGNUM *m, BN_CTX *ctx);
477 int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
478 int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
479 int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m);
480 int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx);
481 int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m);
483 BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
484 BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
485 int BN_mul_word(BIGNUM *a, BN_ULONG w);
486 int BN_add_word(BIGNUM *a, BN_ULONG w);
487 int BN_sub_word(BIGNUM *a, BN_ULONG w);
488 int BN_set_word(BIGNUM *a, BN_ULONG w);
489 BN_ULONG BN_get_word(const BIGNUM *a);
491 int BN_cmp(const BIGNUM *a, const BIGNUM *b);
492 void BN_free(BIGNUM *a);
493 int BN_is_bit_set(const BIGNUM *a, int n);
494 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
495 int BN_lshift1(BIGNUM *r, const BIGNUM *a);
496 int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,BN_CTX *ctx);
498 int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
499 const BIGNUM *m,BN_CTX *ctx);
500 int BN_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
501 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
502 int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
503 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont);
504 int BN_mod_exp_mont_word(BIGNUM *r, BN_ULONG a, const BIGNUM *p,
505 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
506 int BN_mod_exp2_mont(BIGNUM *r, const BIGNUM *a1, const BIGNUM *p1,
507 const BIGNUM *a2, const BIGNUM *p2,const BIGNUM *m,
509 int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
510 const BIGNUM *m,BN_CTX *ctx);
512 int BN_mask_bits(BIGNUM *a,int n);
514 int BN_print_fp(FILE *fp, const BIGNUM *a);
517 int BN_print(BIO *fp, const BIGNUM *a);
519 int BN_print(void *fp, const BIGNUM *a);
521 int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx);
522 int BN_rshift(BIGNUM *r, const BIGNUM *a, int n);
523 int BN_rshift1(BIGNUM *r, const BIGNUM *a);
524 void BN_clear(BIGNUM *a);
525 BIGNUM *BN_dup(const BIGNUM *a);
526 int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
527 int BN_set_bit(BIGNUM *a, int n);
528 int BN_clear_bit(BIGNUM *a, int n);
529 char * BN_bn2hex(const BIGNUM *a);
530 char * BN_bn2dec(const BIGNUM *a);
531 int BN_hex2bn(BIGNUM **a, const char *str);
532 int BN_dec2bn(BIGNUM **a, const char *str);
533 int BN_asc2bn(BIGNUM **a, const char *str);
534 int BN_gcd(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx);
535 int BN_kronecker(const BIGNUM *a,const BIGNUM *b,BN_CTX *ctx); /* returns -2 for error */
536 BIGNUM *BN_mod_inverse(BIGNUM *ret,
537 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
538 BIGNUM *BN_mod_sqrt(BIGNUM *ret,
539 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
543 BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,
544 const BIGNUM *add, const BIGNUM *rem,
546 int BN_is_prime(const BIGNUM *p,int nchecks,
549 int BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
555 int BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add,
556 const BIGNUM *rem, BN_GENCB *cb);
557 int BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb);
558 int BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx,
563 int BN_mod_mul_montgomery(BIGNUM *r,const BIGNUM *a,const BIGNUM *b,
567 int BN_from_montgomery(BIGNUM *r,const BIGNUM *a,
570 int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx);
573 const BIGNUM *mod, BN_CTX *ctx);
579 BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod);
582 int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
583 int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
584 int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *);
585 int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
594 const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
595 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
596 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
607 int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
608 int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
610 int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
611 const BIGNUM *m, BN_CTX *ctx);
612 int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
617 * The BIGNUM::neg property of BIGNUMs representing binary polynomials is
624 int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/
626 int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/
627 int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
628 const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */
629 int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
631 int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p,
633 int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
634 const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */
635 int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
636 const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */
637 int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
639 int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
647 int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]);
649 int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
651 int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
653 int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const int p[],
655 int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
657 int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
659 int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,
661 int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
663 int BN_GF2m_poly2arr(const BIGNUM *a, int p[], int max);
664 int BN_GF2m_arr2poly(const int p[], BIGNUM *a);
668 int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
669 int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
670 int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
671 int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
672 int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
674 const BIGNUM *BN_get0_nist_prime_192(void);
675 const BIGNUM *BN_get0_nist_prime_224(void);
676 const BIGNUM *BN_get0_nist_prime_256(void);
677 const BIGNUM *BN_get0_nist_prime_384(void);
678 const BIGNUM *BN_get0_nist_prime_521(void);
685 BIGNUM *bn_expand2(BIGNUM *a, int words);
687 BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
690 /* Bignum consistency macros
692 * bignum data after direct manipulations on the data. There is also an
695 * bn_fix_top() has become an overabused duct-tape because bignum data is
702 * - bn_check_top() tries to pollute unused words even if the bignum 'top' is
708 * that manipulates the bignum) it is converted to bn_correct_top(), and if it
731 const BIGNUM *_bnum1 = (a); \
752 const BIGNUM *_bnum2 = (a); \
791 BIGNUM *get_rfc2409_prime_768(BIGNUM *bn);
792 BIGNUM *get_rfc2409_prime_1024(BIGNUM *bn);
795 BIGNUM *get_rfc3526_prime_1536(BIGNUM *bn);
796 BIGNUM *get_rfc3526_prime_2048(BIGNUM *bn);
797 BIGNUM *get_rfc3526_prime_3072(BIGNUM *bn);
798 BIGNUM *get_rfc3526_prime_4096(BIGNUM *bn);
799 BIGNUM *get_rfc3526_prime_6144(BIGNUM *bn);
800 BIGNUM *get_rfc3526_prime_8192(BIGNUM *bn);
802 int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);