diff options
author | Guillaume LE VAILLANT <guillaume.le.vaillant@openmailbox.org> | 2015-04-11 08:27:22 +0100 |
---|---|---|
committer | Nathan Froyd <froydnj@gmail.com> | 2016-02-14 17:12:35 -0500 |
commit | 60c37e8bdccdaac1c430d1a2982f1df5129e2944 (patch) | |
tree | 1f9db4331cf9339b46a5ed3e329c4d3973895295 /src/math.lisp | |
parent | d5bcd134fbf4f580fb98cda92509e06edf7cc931 (diff) |
Add key generation for RSA and DSA
Allow signing more than 20 bytes with DSA if the key is long enough
Diffstat (limited to 'src/math.lisp')
-rw-r--r-- | src/math.lisp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/math.lisp b/src/math.lisp index 93541b3..cfc5416 100644 --- a/src/math.lisp +++ b/src/math.lisp @@ -157,7 +157,8 @@ probability (1:2^128 chance of returning a composite number)." finally (return p))) (defun find-generator (p &optional (prng *prng*)) - "Find a random generator of the multiplicative group (Z/pZ)* where p is a safe prime." + "Find a random generator of the multiplicative group (Z/pZ)* +where p is a safe prime number." (assert (> p 3)) (loop with factors = (list 2 (/ (1- p) 2)) @@ -166,3 +167,14 @@ probability (1:2^128 chance of returning a composite number)." for d in factors never (= 1 (expt-mod g (/ (1- p) d) p))) finally (return g))) + +(defun find-subgroup-generator (p q &optional (prng *prng*)) + "Find a random generator of a subgroup of order Q of the multiplicative +group (Z/pZ)* where p is a prime number." + (let ((f (/ (1- p) q))) + (assert (integerp f)) + (loop + for h = (+ 2 (strong-random (- p 3) prng)) + for g = (expt-mod h f p) + while (= 1 g) + finally (return g)))) |