summaryrefslogtreecommitdiff
path: root/sys/src/cmd/unix/drawterm/libsec/genstrongprime.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2013-11-23 01:05:33 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2013-11-23 01:05:33 +0100
commit2f9ae0f8ac8610e13ced184847b57b87fe5db580 (patch)
treef9ad2223d518585a2cfe9ea1c73e1e37d07bf637 /sys/src/cmd/unix/drawterm/libsec/genstrongprime.c
parentea5797c0731203c09ec5fb7172e77eab2750f1a9 (diff)
removing (outdated) drawterm
drawterm is much better maintained by russ cox, so removing this outdated copy. for a more recent version, go to: http://swtch.com/drawterm/
Diffstat (limited to 'sys/src/cmd/unix/drawterm/libsec/genstrongprime.c')
-rw-r--r--sys/src/cmd/unix/drawterm/libsec/genstrongprime.c57
1 files changed, 0 insertions, 57 deletions
diff --git a/sys/src/cmd/unix/drawterm/libsec/genstrongprime.c b/sys/src/cmd/unix/drawterm/libsec/genstrongprime.c
deleted file mode 100644
index 27c43a966..000000000
--- a/sys/src/cmd/unix/drawterm/libsec/genstrongprime.c
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "os.h"
-#include <mp.h>
-#include <libsec.h>
-
-// Gordon's algorithm for generating a strong prime
-// Menezes et al () Handbook, p.150
-void
-genstrongprime(mpint *p, int n, int accuracy)
-{
- mpint *s, *t, *r, *i;
-
- if(n < 64)
- n = 64;
-
- s = mpnew(n/2);
- genprime(s, (n/2)-16, accuracy);
- t = mpnew(n/2);
- genprime(t, n-mpsignif(s)-32, accuracy);
-
- // first r = 2it + 1 that's prime
- i = mpnew(16);
- r = mpnew(0);
- itomp(0x8000, i);
- mpleft(t, 1, t); // 2t
- mpmul(i, t, r); // 2it
- mpadd(r, mpone, r); // 2it + 1
- for(;;){
- if(probably_prime(r, 18))
- break;
- mpadd(r, t, r); // r += 2t
- }
-
- // p0 = 2(s**(r-2) mod r)s - 1
- itomp(2, p);
- mpsub(r, p, p);
- mpexp(s, p, r, p);
- mpmul(s, p, p);
- mpleft(p, 1, p);
- mpsub(p, mpone, p);
-
- // first p = p0 + 2irs that's prime
- itomp(0x8000, i);
- mpleft(r, 1, r); // 2r
- mpmul(r, s, r); // 2rs
- mpmul(r, i, i); // 2irs
- mpadd(p, i, p); // p0 + 2irs
- for(;;){
- if(probably_prime(p, accuracy))
- break;
- mpadd(p, r, p); // p += 2rs
- }
-
- mpfree(i);
- mpfree(s);
- mpfree(r);
- mpfree(t);
-}