/* --- @gfreduce_dump@ --- *
*
- * Arguments: @gfreduce *r@ = structure to dump
+ * Arguments: @const gfreduce *r@ = structure to dump
* @FILE *fp@ = file to dump on
*
* Returns: ---
* Use: Dumps a reduction context.
*/
-void gfreduce_dump(gfreduce *r, FILE *fp)
+void gfreduce_dump(const gfreduce *r, FILE *fp)
{
size_t i;
/* --- @gfreduce_do@ --- *
*
- * Arguments: @gfreduce *r@ = reduction context
+ * Arguments: @const gfreduce *r@ = reduction context
* @mp *d@ = destination
* @mp *x@ = source
*
}
}
-mp *gfreduce_do(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_do(const gfreduce *r, mp *d, mp *x)
{
mpw *v, *vl;
const gfreduce_instr *il;
/* --- @gfreduce_sqrt@ --- *
*
- * Arguments: @gfreduce *r@ = pointer to reduction context
+ * Arguments: @const gfreduce *r@ = pointer to reduction context
* @mp *d@ = destination
* @mp *x@ = some polynomial
*
* Returns: The square root of @x@ modulo @r->p@, or null.
*/
-mp *gfreduce_sqrt(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_sqrt(const gfreduce *r, mp *d, mp *x)
{
mp *y = MP_COPY(x);
mp *z, *spare = MP_NEW;
/* --- @gfreduce_trace@ --- *
*
- * Arguments: @gfreduce *r@ = pointer to reduction context
+ * Arguments: @const gfreduce *r@ = pointer to reduction context
* @mp *x@ = some polynomial
*
* Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
* we only need a single bit to represent it.
*/
-int gfreduce_trace(gfreduce *r, mp *x)
+int gfreduce_trace(const gfreduce *r, mp *x)
{
mp *y = MP_COPY(x);
mp *spare = MP_NEW;
/* --- @gfreduce_halftrace@ --- *
*
- * Arguments: @gfreduce *r@ = pointer to reduction context
+ * Arguments: @const gfreduce *r@ = pointer to reduction context
* @mp *d@ = destination
* @mp *x@ = some polynomial
*
* if %$x \in \gf{2^m}$% with %$m$% odd).
*/
-mp *gfreduce_halftrace(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_halftrace(const gfreduce *r, mp *d, mp *x)
{
mp *y = MP_COPY(x);
mp *spare = MP_NEW;
/* --- @gfreduce_quadsolve@ --- *
*
- * Arguments: @gfreduce *r@ = pointer to reduction context
+ * Arguments: @const gfreduce *r@ = pointer to reduction context
* @mp *d@ = destination
* @mp *x@ = some polynomial
*
* returns the one with zero scalar coefficient.
*/
-mp *gfreduce_quadsolve(gfreduce *r, mp *d, mp *x)
+mp *gfreduce_quadsolve(const gfreduce *r, mp *d, mp *x)
{
unsigned long m = mp_bits(r->p) - 1;
mp *t;
*
* Choose %$\rho \inr \gf{2^m}$% with %$\Tr(\rho) = 1$%. Let
* %$z = \sum_{0\le i<m} \rho^{2^i} \sum_{0\le j<i} x^{2^j} = {}$%
+ * %$\sum_{1\le i<m} \rho^{2^i} (x + \sum_{1\le j<i} x^{2^j} = {}$%
* %$\rho^2 x + \rho^4 (x + x^2) + \rho^8 (x + x^2 + x^4) + \cdots + {}$%
* %$\rho^{2^{m-1}} (x + x^2 + x^{2^{m-2}})$%. Then %$z^2 = {}$%
* %$\sum_{0\le i<m} \rho^{2^{i+1}} \sum_{0\le j<i} x^{2^{j+1}} = {}$%
- * %$\sum_{1\le i\le m} \rho^{2^i} \sum_{1\le j\le i} x^{2^j}$% and,
- * somewhat miraculously, %$z^2 + z = \sum_{0\le i<m} \rho^{2^i} x + {}$%
- * %$\rho \sum_{1\le i<m} x^{2^i} = x \Tr(\rho) + \rho \Tr(x)$%. Again,
+ * %$\sum_{1\le i\le m} \rho^{2^i} \sum_{1\le j<i} x^{2^j} = {}$%
+ * %$\sum_{1\le i<m} \rho^{2^i} \sum_{1\le j<i} x^{2^j} + {}$%
+ * %$\rho^{2^m} \sum_{1\le j<m} x^{2^j}$%; and, somewhat miraculously,
+ * %$z^2 + z = \sum_{1\le i<m} \rho^{2^i} x + {}$%
+ * %$\rho \sum_{1\le i<m} x^{2^i} = x (\Tr(\rho) + \rho) + {}$%
+ * %$\rho (\Tr(x) + x) = x \Tr(\rho) + \rho \Tr(x)$%. Again,
* this gives us the root we want whenever %$\Tr(x) = 0$%.
*
* The loop below calculates %$w = \Tr(\rho)$% and %$z$% simultaneously,
/* --- @gfreduce_exp@ --- *
*
- * Arguments: @gfreduce *gr@ = pointer to reduction context
+ * Arguments: @const gfreduce *gr@ = pointer to reduction context
* @mp *d@ = fake destination
* @mp *a@ = base
* @mp *e@ = exponent
* Returns: Result, %$a^e \bmod m$%.
*/
-mp *gfreduce_exp(gfreduce *gr, mp *d, mp *a, mp *e)
+mp *gfreduce_exp(const gfreduce *gr, mp *d, mp *a, mp *e)
{
mp *x = MP_ONE;
mp *spare = (e->f & MP_BURN) ? MP_NEWSEC : MP_NEW;