You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`mod_mul`: multiplies `a` by `b` and finds the non-negative remainder respective to modulus `m`
673
+
-`mod_exp`, `mod_pow`: computes `a` to the `b`-th power modulo `m` (r=a^b % m). This function uses less
674
+
time and space than `exp`. Do not call this function when `m` is even and any of the parameters
675
+
have the `BN_FLG_CONSTTIME` flag set.
676
+
677
+
```lua
678
+
localbn=require("resty.openssl.bn")
679
+
locala=bn.new(123456)
680
+
localb=bn.new(9876)
681
+
localr
682
+
-- the followings are equal
683
+
r=a:mod_add(b, 3)
684
+
r=bn.mod_add(a, b, 3)
685
+
r=a:mod_add(9876, 3)
686
+
r=bn.mod_add(a, 9876, 3)
687
+
r=bn.mod_add(123456, b, 3)
688
+
r=bn.mod_add(123456, 9876, 3)
533
689
```
534
690
535
691
[Back to TOC](#table-of-contents)
536
692
693
+
### bn:mod_sqr
694
+
695
+
**syntax**: *r = a:mod_sqr(m)*
696
+
697
+
**syntax**: *r = bn.mod_sqr(a, m)*
698
+
699
+
Takes the square of `a` modulo `m`.
700
+
701
+
[Back to TOC](#table-of-contents)
702
+
703
+
### bn:lshift, bn:rshift
704
+
705
+
**syntax**: *r = bn:lshift(bit)*
706
+
707
+
**syntax**: *r = bn.lshift(a, bit)*
708
+
709
+
**syntax**: *r = bn:rshift(bit)*
710
+
711
+
**syntax**: *r = bn.rshift(a, bit)*
712
+
713
+
Bit shift `a` to `bit` bits.
714
+
715
+
[Back to TOC](#table-of-contents)
716
+
717
+
### bn:is_zero, bn:is_one, bn:is_odd, bn:is_word
718
+
719
+
**syntax**: *ok = bn:is_zero()*
720
+
721
+
**syntax**: *ok = bn:is_one()*
722
+
723
+
**syntax**: *ok = bn:is_odd()*
724
+
725
+
**syntax**: *ok, err = bn:is_word(n)*
726
+
727
+
Checks if `bn` is `0`, `1`, and odd number or a number `n` respectively.
728
+
729
+
[Back to TOC](#table-of-contents)
730
+
731
+
### bn:is_prime
732
+
733
+
**syntax**: *ok, err = bn:is_prime(nchecks?)*
734
+
735
+
Checks if `bn` is a prime number. Returns `true` if it is prime with an
736
+
error probability of less than 0.25^`nchecks` and error if any. If omitted,
737
+
`nchecks` is set to 0 which means to select number of iterations basedon the
738
+
size of the number
739
+
740
+
> This function perform a Miller-Rabin probabilistic primality test with nchecks iterations. If nchecks == BN_prime_checks (0), a number of iterations is used that yields a false positive rate of at most 2^-64 for random input. The error rate depends on the size of the prime and goes down for bigger primes. The rate is 2^-80 starting at 308 bits, 2^-112 at 852 bits, 2^-128 at 1080 bits, 2^-192 at 3747 bits and 2^-256 at 6394 bits.
741
+
742
+
> When the source of the prime is not random or not trusted, the number of checks needs to be much higher to reach the same level of assurance: It should equal half of the targeted security level in bits (rounded up to the next integer if necessary). For instance, to reach the 128 bit security level, nchecks should be set to 64.
743
+
744
+
See also [BN_is_prime](https://www.openssl.org/docs/man1.1.1/man3/BN_is_prime.html).
745
+
746
+
[Back to TOC](#table-of-contents)
747
+
537
748
## resty.openssl.cipher
538
749
539
750
Module to interact with symmetric cryptography (EVP_CIPHER).
@@ -831,7 +1042,7 @@ local key, err = kdf.derive({
0 commit comments