projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Declare @pss_preverify@ instead of repeating @pss_resign@.
[u/mdw/catacomb]
/
rabin.c
diff --git
a/rabin.c
b/rabin.c
index
e6cd488
..
915dc14
100644
(file)
--- a/
rabin.c
+++ b/
rabin.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: rabin.c,v 1.
6 2001/06/16 12:56:38
mdw Exp $
+ * $Id: rabin.c,v 1.
7 2002/01/13 13:42:53
mdw Exp $
*
* Miller-Rabin primality test
*
*
* Miller-Rabin primality test
*
@@
-30,6
+30,10
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: rabin.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: rabin.c,v $
+ * Revision 1.7 2002/01/13 13:42:53 mdw
+ * More efficient Rabin-Miller test: with random witnesses, skip redundant
+ * Montgomerization. (Being bijective, it can't affect the distribution.)
+ *
* Revision 1.6 2001/06/16 12:56:38 mdw
* Fixes for interface change to @mpmont_expr@ and @mpmont_mexpr@.
*
* Revision 1.6 2001/06/16 12:56:38 mdw
* Fixes for interface change to @mpmont_expr@ and @mpmont_mexpr@.
*
@@
-98,7
+102,7
@@
void rabin_destroy(rabin *r)
mpmont_destroy(&r->mm);
}
mpmont_destroy(&r->mm);
}
-/* --- @rabin_test@ --- *
+/* --- @rabin_test@
, @rabin_rtest@
--- *
*
* Arguments: @rabin *r@ = pointer to Rabin-Miller context
* @mp *g@ = base to test the number against
*
* Arguments: @rabin *r@ = pointer to Rabin-Miller context
* @mp *g@ = base to test the number against
@@
-107,10
+111,11
@@
void rabin_destroy(rabin *r)
* if it succeeded.
*
* Use: Performs a single iteration of the Rabin-Miller primality
* if it succeeded.
*
* Use: Performs a single iteration of the Rabin-Miller primality
- * test.
+ * test. The @rtest@ variant assumes that %$g$% is either
+ * already in Montgomery representation, or you don't care.
*/
*/
-int rabin_test(rabin *r, mp *g)
+int rabin_
r
test(rabin *r, mp *g)
{
mp *y;
mp *dd, *spare = MP_NEW;
{
mp *y;
mp *dd, *spare = MP_NEW;
@@
-123,8
+128,7
@@
int rabin_test(rabin *r, mp *g)
* @y@ here has an extra factor of %$R$%.
*/
* @y@ here has an extra factor of %$R$%.
*/
- y = mpmont_mul(&r->mm, MP_NEW, g, r->mm.r2);
- y = mpmont_expr(&r->mm, y, y, r->r);
+ y = mpmont_expr(&r->mm, MP_NEW, g, r->r);
if (MP_EQ(y, r->mm.r) || MP_EQ(y, r->m1)) {
rc = PGEN_PASS;
goto done;
if (MP_EQ(y, r->mm.r) || MP_EQ(y, r->m1)) {
rc = PGEN_PASS;
goto done;
@@
-157,6
+161,15
@@
done:
return (rc);
}
return (rc);
}
+int rabin_test(rabin *r, mp *g)
+{
+ int rc;
+ g = mpmont_mul(&r->mm, MP_NEW, g, r->mm.r2);
+ rc = rabin_rtest(r, g);
+ mp_drop(g);
+ return (rc);
+}
+
/* --- @rabin_iters@ --- *
*
* Arguments: @unsigned len@ = number of bits in value
/* --- @rabin_iters@ --- *
*
* Arguments: @unsigned len@ = number of bits in value