projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve bulk performance by making better use of Montgomery
[u/mdw/catacomb]
/
mpmont.c
diff --git
a/mpmont.c
b/mpmont.c
index
cabb2cb
..
e7b9bb7
100644
(file)
--- a/
mpmont.c
+++ b/
mpmont.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mpmont.c,v 1.
8 1999/12/22 15:55:00
mdw Exp $
+ * $Id: mpmont.c,v 1.
9 2000/06/17 11:45:09
mdw Exp $
*
* Montgomery reduction
*
*
* Montgomery reduction
*
@@
-30,6
+30,11
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mpmont.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mpmont.c,v $
+ * Revision 1.9 2000/06/17 11:45:09 mdw
+ * Major memory management overhaul. Added arena support. Use the secure
+ * arena for secret integers. Replace and improve the MP management macros
+ * (e.g., replace MP_MODIFY by MP_DEST).
+ *
* Revision 1.8 1999/12/22 15:55:00 mdw
* Adjust Karatsuba parameters.
*
* Revision 1.8 1999/12/22 15:55:00 mdw
* Adjust Karatsuba parameters.
*
@@
-105,7
+110,7
@@
void mpmont_create(mpmont *mm, mp *m)
void mpmont_create(mpmont *mm, mp *m)
{
size_t n = MP_LEN(m);
void mpmont_create(mpmont *mm, mp *m)
{
size_t n = MP_LEN(m);
- mp *r2 = mp_
create(2 * n + 1
);
+ mp *r2 = mp_
new(2 * n + 1, 0
);
mp r;
/* --- Validate the arguments --- */
mp r;
/* --- Validate the arguments --- */
@@
-213,13
+218,12
@@
mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
/* --- Initial conditioning of the arguments --- */
/* --- Initial conditioning of the arguments --- */
- if (d == a)
- MP_MODIFY(d, 2 * n + 1);
- else {
- MP_MODIFY(d, 2 * n + 1);
- MPX_COPY(d->v, d->vl, a->v, a->vl);
- }
-
+ a = MP_COPY(a);
+ if (d)
+ MP_DROP(d);
+ d = a;
+ MP_DEST(d, 2 * n + 1, a->f);
+
dv = d->v; dvl = d->vl;
mv = mm->m->v; mvl = mm->m->vl;
dv = d->v; dvl = d->vl;
mv = mm->m->v; mvl = mm->m->vl;
@@
-235,7
+239,6
@@
mp *mpmont_reduce(mpmont *mm, mp *d, mp *a)
/* --- Wrap everything up --- */
/* --- Wrap everything up --- */
- d->f = a->f & MP_BURN;
memmove(d->v, d->v + n, MPWS(MP_LEN(d) - n));
d->vl -= n;
if (MP_CMP(d, >=, mm->m))
memmove(d->v, d->v + n, MPWS(MP_LEN(d) - n));
d->vl -= n;
if (MP_CMP(d, >=, mm->m))
@@
-289,7
+292,7
@@
mp *mpmont_mul(mpmont *mm, mp *d, mp *a, mp *b)
a = MP_COPY(a);
b = MP_COPY(b);
a = MP_COPY(a);
b = MP_COPY(b);
- MP_
MODIFY(d, 2 * n + 1
);
+ MP_
DEST(d, 2 * n + 1, a->f | b->f | MP_UNDEF
);
dv = d->v; dvl = d->vl;
MPX_ZERO(dv, dvl);
av = a->v; avl = a->vl;
dv = d->v; dvl = d->vl;
MPX_ZERO(dv, dvl);
av = a->v; avl = a->vl;
@@
-351,7
+354,7
@@
mp *mpmont_expr(mpmont *mm, mp *d, mp *a, mp *e)
mpscan sc;
mp *ar = mpmont_mul(mm, MP_NEW, a, mm->r2);
mp *x = MP_COPY(mm->r);
mpscan sc;
mp *ar = mpmont_mul(mm, MP_NEW, a, mm->r2);
mp *x = MP_COPY(mm->r);
- mp *spare = MP_NEW;
+ mp *spare =
(e->f & MP_BURN) ? MP_NEWSEC :
MP_NEW;
mp_scan(&sc, e);
mp_scan(&sc, e);