projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Elliptic curves on binary fields work.
[u/mdw/catacomb]
/
mp-arith.c
diff --git
a/mp-arith.c
b/mp-arith.c
index
a070675
..
59198cf
100644
(file)
--- a/
mp-arith.c
+++ b/
mp-arith.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mp-arith.c,v 1.1
4 2002/10/15 19:18:31
mdw Exp $
+ * $Id: mp-arith.c,v 1.1
6.2.2 2004/03/20 00:14:03
mdw Exp $
*
* Basic arithmetic on multiprecision integers
*
*
* Basic arithmetic on multiprecision integers
*
@@
-30,6
+30,18
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mp-arith.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mp-arith.c,v $
+ * Revision 1.16.2.2 2004/03/20 00:14:03 mdw
+ * Bug fix.
+ *
+ * Revision 1.16.2.1 2003/06/10 13:21:10 mdw
+ * Fix bug dividing small things by large ones.
+ *
+ * Revision 1.16 2003/05/16 09:09:24 mdw
+ * Fix @mp_lsl2c@. Turns out to be surprisingly tricky.
+ *
+ * Revision 1.15 2002/10/19 17:56:50 mdw
+ * Fix bit operations. Test them (a bit) better.
+ *
* Revision 1.14 2002/10/15 19:18:31 mdw
* New operation to negate numbers.
*
* Revision 1.14 2002/10/15 19:18:31 mdw
* New operation to negate numbers.
*
@@
-88,13
+100,18
@@
/*----- Main code ---------------------------------------------------------*/
/*----- Main code ---------------------------------------------------------*/
-/* --- @mp_lsl@, @mp_lsr@ --- *
+/* --- @mp_lsl@, @mp_ls
lc@, @mp_ls
r@ --- *
*
* Arguments: @mp *d@ = destination
* @mp *a@ = source
* @size_t n@ = number of bits to move
*
* Returns: Result, @a@ shifted left or right by @n@.
*
* Arguments: @mp *d@ = destination
* @mp *a@ = source
* @size_t n@ = number of bits to move
*
* Returns: Result, @a@ shifted left or right by @n@.
+ *
+ * Use: Bitwise shift operators. @mp_lslc@ fills the bits introduced
+ * on the right with ones instead of zeroes: it's used
+ * internally by @mp_lsl2c@, though it may be useful on its
+ * own.
*/
mp *mp_lsl(mp *d, mp *a, size_t n)
*/
mp *mp_lsl(mp *d, mp *a, size_t n)
@@
-106,6
+123,15
@@
mp *mp_lsl(mp *d, mp *a, size_t n)
return (d);
}
return (d);
}
+mp *mp_lslc(mp *d, mp *a, size_t n)
+{
+ MP_DEST(d, MP_LEN(a) + (n + MPW_BITS - 1) / MPW_BITS, a->f);
+ mpx_lslc(d->v, d->vl, a->v, a->vl, n);
+ d->f = a->f & (MP_NEG | MP_BURN);
+ MP_SHRINK(d);
+ return (d);
+}
+
mp *mp_lsr(mp *d, mp *a, size_t n)
{
MP_DEST(d, MP_LEN(a), a->f);
mp *mp_lsr(mp *d, mp *a, size_t n)
{
MP_DEST(d, MP_LEN(a), a->f);
@@
-130,7
+156,7
@@
mp *mp_lsl2c(mp *d, mp *a, size_t n)
if (!(a->f & MP_NEG))
return (mp_lsl(d, a, n));
d = mp_not2c(d, a);
if (!(a->f & MP_NEG))
return (mp_lsl(d, a, n));
d = mp_not2c(d, a);
- d = mp_lsl(d, d, n);
+ d = mp_lsl
c
(d, d, n);
d = mp_not2c(d, d);
return (d);
}
d = mp_not2c(d, d);
return (d);
}
@@
-290,10
+316,10
@@
mp *mp_neg(mp *d, mp *a)
MP_SHRINK(a);
MP_COPY(a);
MP_SHRINK(a);
MP_COPY(a);
- if (d) MP_DROP(d);
- if (a->v == a->vl) {
+ if (d)
+ MP_DROP(d);
+ if (a->v == a->vl)
return (a);
return (a);
- }
MP_DEST(a, MP_LEN(a), a->f);
a->f ^= MP_NEG;
return (a);
MP_DEST(a, MP_LEN(a), a->f);
a->f ^= MP_NEG;
return (a);
@@
-318,7
+344,7
@@
mp *mp_neg(mp *d, mp *a)
\
mp *mp_bit##string(mp *d, mp *a, mp *b) \
{ \
\
mp *mp_bit##string(mp *d, mp *a, mp *b) \
{ \
- MP_DEST(d, MAX(MP_LEN(a), MP_LEN(b)),
a->f | b->f);
\
+ MP_DEST(d, MAX(MP_LEN(a), MP_LEN(b)),
(a->f | b->f) & ~MP_NEG);
\
mpx_bit##string(d->v, d->vl, a->v, a->vl, b->v, b->vl); \
d->f = (a->f | b->f) & MP_BURN; \
MP_SHRINK(d); \
mpx_bit##string(d->v, d->vl, a->v, a->vl, b->v, b->vl); \
d->f = (a->f | b->f) & MP_BURN; \
MP_SHRINK(d); \
@@
-599,7
+625,7
@@
void mp_div(mp **qq, mp **rr, mp *a, mp *b)
if (r)
MP_DROP(r);
r = a;
if (r)
MP_DROP(r);
r = a;
- MP_DEST(r, M
P_LEN(a
) + 2, a->f | b->f);
+ MP_DEST(r, M
AX(MP_LEN(a), MP_LEN(b)
) + 2, a->f | b->f);
/* --- Fix up the quotient too --- */
/* --- Fix up the quotient too --- */