Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - basemath - bb_group.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.8.0 lcov report (development 19222-cc5b867) Lines: 499 544 91.7 %
Date: 2016-07-28 07:10:28 Functions: 32 33 97.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2004  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /***********************************************************************/
      15             : /**                                                                   **/
      16             : /**             GENERIC ALGORITHMS ON BLACKBOX GROUP                  **/
      17             : /**                                                                   **/
      18             : /***********************************************************************/
      19             : #include "pari.h"
      20             : #include "paripriv.h"
      21             : #undef pow /* AIX: pow(a,b) is a macro, wrongly expanded on grp->pow(a,b,c) */
      22             : 
      23             : /***********************************************************************/
      24             : /**                                                                   **/
      25             : /**                    POWERING                                       **/
      26             : /**                                                                   **/
      27             : /***********************************************************************/
      28             : 
      29             : /* return (n>>(i+1-l)) & ((1<<l)-1) */
      30             : static ulong
      31      911233 : int_block(GEN n, long i, long l)
      32             : {
      33      911233 :   long q = divsBIL(i), r = remsBIL(i)+1, lr;
      34      911366 :   GEN nw = int_W(n, q);
      35      911366 :   ulong w = (ulong) *nw, w2;
      36      911366 :   if (r>=l) return (w>>(r-l))&((1UL<<l)-1);
      37       58713 :   w &= (1UL<<r)-1; lr = l-r;
      38       58713 :   w2 = (ulong) *int_precW(nw); w2 >>= (BITS_IN_LONG-lr);
      39       58713 :   return (w<<lr)|w2;
      40             : }
      41             : 
      42             : /* assume n != 0, t_INT. Compute x^|n| using sliding window powering */
      43             : static GEN
      44     7477209 : sliding_window_powu(GEN x, ulong n, long e, void *E, GEN (*sqr)(void*,GEN),
      45             :                                                      GEN (*mul)(void*,GEN,GEN))
      46             : {
      47             :   pari_sp av;
      48     7477209 :   long i, l = expu(n), u = (1UL<<(e-1));
      49             :   long w, v;
      50     7477327 :   GEN tab = cgetg(1+u, t_VEC);
      51     7477676 :   GEN x2 = sqr(E, x), z = NULL, tw;
      52     7293179 :   gel(tab, 1) = x;
      53     7293179 :   for (i=2; i<=u; i++) gel(tab,i) = mul(E, gel(tab,i-1), x2);
      54     7290814 :   av = avma;
      55    66505630 :   while (l>=0)
      56             :   {
      57    51738279 :     if (e > l+1) e = l+1;
      58    51738279 :     w = (n>>(l+1-e)) & ((1UL<<e)-1); v = vals(w); l-=e;
      59    51849113 :     tw = gel(tab, 1+(w>>(v+1)));
      60    51849113 :     if (z)
      61             :     {
      62    44372324 :       for (i=1; i<=e-v; i++) z = sqr(E, z);
      63    44276085 :       z = mul(E, z, tw);
      64     7476789 :     } else z = tw;
      65    51728906 :     for (i=1; i<=v; i++) z = sqr(E, z);
      66   147062328 :     while (l>=0)
      67             :     {
      68    87695564 :       if (gc_needed(av,1))
      69             :       {
      70           0 :         if (DEBUGMEM>1) pari_warn(warnmem,"sliding_window_powu (%ld)", l);
      71           0 :         z = gerepilecopy(av, z);
      72             :       }
      73    87900812 :       if (n&(1UL<<l)) break;
      74    43615322 :       z = sqr(E, z); l--;
      75             :     }
      76             :   }
      77     7476537 :   return z;
      78             : }
      79             : 
      80             : 
      81             : /* assume n != 0, t_INT. Compute x^|n| using sliding window powering */
      82             : static GEN
      83       72501 : sliding_window_pow(GEN x, GEN n, long e, void *E, GEN (*sqr)(void*,GEN),
      84             :                                                   GEN (*mul)(void*,GEN,GEN))
      85             : {
      86             :   pari_sp av;
      87       72501 :   long i, l = expi(n), u = (1UL<<(e-1));
      88             :   long w, v;
      89       72503 :   GEN tab = cgetg(1+u, t_VEC);
      90       72501 :   GEN x2 = sqr(E, x), z = NULL, tw;
      91       72261 :   gel(tab, 1) = x;
      92       72261 :   for (i=2; i<=u; i++) gel(tab,i) = mul(E, gel(tab,i-1), x2);
      93       72258 :   av = avma;
      94     1056085 :   while (l>=0)
      95             :   {
      96      911365 :     if (e > l+1) e = l+1;
      97      911365 :     w = int_block(n,l,e); v = vals(w); l-=e;
      98      913005 :     tw = gel(tab, 1+(w>>(v+1)));
      99      913005 :     if (z)
     100             :     {
     101      840495 :       for (i=1; i<=e-v; i++) z = sqr(E, z);
     102      838715 :       z = mul(E, z, tw);
     103       72510 :     } else z = tw;
     104      911289 :     for (i=1; i<=v; i++) z = sqr(E, z);
     105     6234909 :     while (l>=0)
     106             :     {
     107     5250964 :       if (gc_needed(av,1))
     108             :       {
     109          54 :         if (DEBUGMEM>1) pari_warn(warnmem,"sliding_window_pow (%ld)", l);
     110          54 :         z = gerepilecopy(av, z);
     111             :       }
     112     5250964 :       if (int_bit(n,l)) break;
     113     4413358 :       z = sqr(E, z); l--;
     114             :     }
     115             :   }
     116       72462 :   return z;
     117             : }
     118             : 
     119             : /* assume n != 0, t_INT. Compute x^|n| using leftright binary powering */
     120             : static GEN
     121    46385769 : leftright_binary_powu(GEN x, ulong n, void *E, GEN (*sqr)(void*,GEN),
     122             :                                               GEN (*mul)(void*,GEN,GEN))
     123             : {
     124    46385769 :   pari_sp av = avma;
     125             :   GEN  y;
     126             :   int j;
     127             : 
     128    46385769 :   if (n == 1) return x;
     129    46385769 :   y = x; j = 1+bfffo(n);
     130             :   /* normalize, i.e set highest bit to 1 (we know n != 0) */
     131    46385769 :   n<<=j; j = BITS_IN_LONG-j;
     132             :   /* first bit is now implicit */
     133   125185894 :   for (; j; n<<=1,j--)
     134             :   {
     135    78800138 :     y = sqr(E,y);
     136    78800124 :     if (n & HIGHBIT) y = mul(E,y,x); /* first bit set: multiply by base */
     137    78800125 :     if (gc_needed(av,1))
     138             :     {
     139           0 :       if (DEBUGMEM>1) pari_warn(warnmem,"leftright_powu (%d)", j);
     140           0 :       y = gerepilecopy(av, y);
     141             :     }
     142             :   }
     143    46385756 :   return y;
     144             : }
     145             : 
     146             : GEN
     147    53943857 : gen_powu_i(GEN x, ulong n, void *E, GEN (*sqr)(void*,GEN),
     148             :                                     GEN (*mul)(void*,GEN,GEN))
     149             : {
     150             :   long l;
     151    53943857 :   if (n == 1) return x;
     152    53862603 :   l = expu(n);
     153    53863577 :   if (l<=8)
     154    46385770 :     return leftright_binary_powu(x, n, E, sqr, mul);
     155             :   else
     156     7477807 :     return sliding_window_powu(x, n, l<=24? 2: 3, E, sqr, mul);
     157             : }
     158             : 
     159             : GEN
     160     1178828 : gen_powu(GEN x, ulong n, void *E, GEN (*sqr)(void*,GEN),
     161             :                                   GEN (*mul)(void*,GEN,GEN))
     162             : {
     163     1178828 :   pari_sp av = avma;
     164     1178828 :   if (n == 1) return gcopy(x);
     165     1157464 :   return gerepilecopy(av, gen_powu_i(x,n,E,sqr,mul));
     166             : }
     167             : 
     168             : GEN
     169    21466542 : gen_pow_i(GEN x, GEN n, void *E, GEN (*sqr)(void*,GEN),
     170             :                                  GEN (*mul)(void*,GEN,GEN))
     171             : {
     172             :   long l, e;
     173    21466542 :   if (lgefint(n)==3) return gen_powu_i(x, uel(n,2), E, sqr, mul);
     174       72502 :   l = expi(n);
     175       72503 :   if      (l<=64)  e = 3;
     176       34311 :   else if (l<=160) e = 4;
     177        6087 :   else if (l<=384) e = 5;
     178        1166 :   else if (l<=896) e = 6;
     179         648 :   else             e = 7;
     180       72503 :   return sliding_window_pow(x, n, e, E, sqr, mul);
     181             : }
     182             : 
     183             : GEN
     184     1867149 : gen_pow(GEN x, GEN n, void *E, GEN (*sqr)(void*,GEN),
     185             :                                GEN (*mul)(void*,GEN,GEN))
     186             : {
     187     1867149 :   pari_sp av = avma;
     188     1867149 :   return gerepilecopy(av, gen_pow_i(x,n,E,sqr,mul));
     189             : }
     190             : 
     191             : /* assume n > 0. Compute x^n using left-right binary powering */
     192             : GEN
     193      215188 : gen_powu_fold_i(GEN x, ulong n, void *E, GEN  (*sqr)(void*,GEN),
     194             :                                          GEN (*msqr)(void*,GEN))
     195             : {
     196      215188 :   pari_sp av = avma;
     197             :   GEN y;
     198             :   int j;
     199             : 
     200      215188 :   if (n == 1) return x;
     201      215188 :   y = x; j = 1+bfffo(n);
     202             :   /* normalize, i.e set highest bit to 1 (we know n != 0) */
     203      215188 :   n<<=j; j = BITS_IN_LONG-j;
     204             :   /* first bit is now implicit */
     205     2668710 :   for (; j; n<<=1,j--)
     206             :   {
     207     2453522 :     if (n & HIGHBIT) y = msqr(E,y); /* first bit set: multiply by base */
     208     1943341 :     else y = sqr(E,y);
     209     2453522 :     if (gc_needed(av,1))
     210             :     {
     211           0 :       if (DEBUGMEM>1) pari_warn(warnmem,"gen_powu_fold (%d)", j);
     212           0 :       y = gerepilecopy(av, y);
     213             :     }
     214             :   }
     215      215188 :   return y;
     216             : }
     217             : GEN
     218           0 : gen_powu_fold(GEN x, ulong n, void *E, GEN (*sqr)(void*,GEN),
     219             :                                        GEN (*msqr)(void*,GEN))
     220             : {
     221           0 :   pari_sp av = avma;
     222           0 :   if (n == 1) return gcopy(x);
     223           0 :   return gerepilecopy(av, gen_powu_fold_i(x,n,E,sqr,msqr));
     224             : }
     225             : 
     226             : /* assume N != 0, t_INT. Compute x^|N| using left-right binary powering */
     227             : GEN
     228      144376 : gen_pow_fold_i(GEN x, GEN N, void *E, GEN (*sqr)(void*,GEN),
     229             :                                       GEN (*msqr)(void*,GEN))
     230             : {
     231      144376 :   long ln = lgefint(N);
     232      144376 :   if (ln == 3) return gen_powu_fold_i(x, N[2], E, sqr, msqr);
     233             :   else
     234             :   {
     235       65272 :     GEN nd = int_MSW(N), y = x;
     236       65272 :     ulong n = *nd;
     237             :     long i;
     238             :     int j;
     239       65272 :     pari_sp av = avma;
     240             : 
     241       65272 :     if (n == 1)
     242        6303 :       j = 0;
     243             :     else
     244             :     {
     245       58969 :       j = 1+bfffo(n); /* < BIL */
     246             :       /* normalize, i.e set highest bit to 1 (we know n != 0) */
     247       58969 :       n <<= j; j = BITS_IN_LONG - j;
     248             :     }
     249             :     /* first bit is now implicit */
     250       65272 :     for (i=ln-2;;)
     251             :     {
     252     7398242 :       for (; j; n<<=1,j--)
     253             :       {
     254     7225553 :         if (n & HIGHBIT) y = msqr(E,y); /* first bit set: multiply by base */
     255     6365123 :         else y = sqr(E,y);
     256     7225010 :         if (gc_needed(av,1))
     257             :         {
     258           0 :           if (DEBUGMEM>1) pari_warn(warnmem,"gen_pow_fold (%d)", j);
     259           0 :           y = gerepilecopy(av, y);
     260             :         }
     261             :       }
     262      172689 :       if (--i == 0) return y;
     263      107960 :       nd = int_precW(nd);
     264      107960 :       n = *nd; j = BITS_IN_LONG;
     265      107960 :     }
     266             :   }
     267             : }
     268             : GEN
     269       79105 : gen_pow_fold(GEN x, GEN n, void *E, GEN (*sqr)(void*,GEN),
     270             :                                     GEN (*msqr)(void*,GEN))
     271             : {
     272       79105 :   pari_sp av = avma;
     273       79105 :   return gerepilecopy(av, gen_pow_fold_i(x,n,E,sqr,msqr));
     274             : }
     275             : 
     276             : GEN
     277     3451410 : gen_powers(GEN x, long l, int use_sqr, void *E, GEN (*sqr)(void*,GEN),
     278             :                                       GEN (*mul)(void*,GEN,GEN), GEN (*one)(void*))
     279             : {
     280             :   long i;
     281     3451410 :   GEN V = cgetg(l+2,t_VEC);
     282     3451410 :   gel(V,1) = one(E); if (l==0) return V;
     283     3439964 :   gel(V,2) = gcopy(x); if (l==1) return V;
     284     2128890 :   gel(V,3) = sqr(E,x);
     285     2128890 :   if (use_sqr)
     286     5108492 :     for(i = 4; i < l+2; i++)
     287     8924003 :       gel(V,i) = (i&1)? sqr(E,gel(V, (i+1)>>1))
     288     5264030 :                       : mul(E,gel(V, i-1),x);
     289             :   else
     290     1506759 :     for(i = 4; i < l+2; i++)
     291      826390 :       gel(V,i) = mul(E,gel(V,i-1),x);
     292     2128889 :   return V;
     293             : }
     294             : 
     295             : GEN
     296     2745071 : gen_product(GEN x, void *data, GEN (*mul)(void *,GEN,GEN))
     297             : {
     298             :   pari_sp ltop;
     299     2745071 :   long i,k,lx = lg(x);
     300             :   pari_timer ti;
     301     2745071 :   if (DEBUGLEVEL>7) timer_start(&ti);
     302             : 
     303     2745109 :   if (lx == 1) return gen_1;
     304     2744430 :   if (lx == 2) return gcopy(gel(x,1));
     305     2572888 :   x = leafcopy(x); k = lx;
     306     2572988 :   ltop = avma;
     307    10448482 :   while (k > 2)
     308             :   {
     309     5302633 :     if (DEBUGLEVEL>7)
     310           0 :       timer_printf(&ti,"gen_product: remaining objects %ld",k-1);
     311     5303427 :     lx = k; k = 1;
     312    18676508 :     for (i=1; i<lx-1; i+=2)
     313    13374453 :       gel(x,k++) = mul(data,gel(x,i),gel(x,i+1));
     314     5302055 :     if (i < lx) gel(x,k++) = gel(x,i);
     315     5302055 :     if (gc_needed(ltop,1))
     316           8 :       gerepilecoeffs(ltop,x+1,k-1);
     317             :   }
     318     2572861 :   return gel(x,1);
     319             : }
     320             : 
     321             : /***********************************************************************/
     322             : /**                                                                   **/
     323             : /**                    DISCRETE LOGARITHM                             **/
     324             : /**                                                                   **/
     325             : /***********************************************************************/
     326             : 
     327             : static GEN
     328    51744627 : iter_rho(GEN x, GEN g, GEN q, GEN A, ulong h, void *E, const struct bb_group *grp)
     329             : {
     330    51744627 :   GEN a = gel(A,1);
     331    51744627 :   switch((h|grp->hash(a))%3UL)
     332             :   {
     333             :     case 0:
     334    17253394 :       return mkvec3(grp->pow(E,a,gen_2),Fp_mulu(gel(A,2),2,q),
     335    17253394 :                                         Fp_mulu(gel(A,3),2,q));
     336             :     case 1:
     337    17247956 :       return mkvec3(grp->mul(E,a,x),addis(gel(A,2),1),gel(A,3));
     338             :     case 2:
     339    17243277 :       return mkvec3(grp->mul(E,a,g),gel(A,2),addis(gel(A,3),1));
     340             :   }
     341           0 :   return NULL;
     342             : }
     343             : 
     344             : /*Generic Pollard rho discrete log algorithm*/
     345             : static GEN
     346          49 : gen_Pollard_log(GEN x, GEN g, GEN q, void *E, const struct bb_group *grp)
     347             : {
     348          49 :   pari_sp av=avma;
     349          49 :   GEN A, B, l, sqrt4q = sqrti(shifti(q,4));
     350          49 :   ulong i, h = 0, imax = itou_or_0(sqrt4q);
     351          49 :   if (!imax) imax = ULONG_MAX;
     352             :   do {
     353             :  rho_restart:
     354          49 :     A = B = mkvec3(x,gen_1,gen_0);
     355          49 :     i=0;
     356             :     do {
     357    17248209 :       if (i>imax)
     358             :       {
     359           0 :         h++;
     360           0 :         if (DEBUGLEVEL)
     361           0 :           pari_warn(warner,"changing Pollard rho hash seed to %ld",h);
     362           0 :         goto rho_restart;
     363             :       }
     364    17248209 :       A = iter_rho(x, g, q, A, h, E, grp);
     365    17248209 :       B = iter_rho(x, g, q, B, h, E, grp);
     366    17248209 :       B = iter_rho(x, g, q, B, h, E, grp);
     367    17248209 :       if (gc_needed(av,2))
     368             :       {
     369        1725 :         if(DEBUGMEM>1) pari_warn(warnmem,"gen_Pollard_log");
     370        1725 :         gerepileall(av, 2, &A, &B);
     371             :       }
     372    17248209 :       i++;
     373    17248209 :     } while (!grp->equal(gel(A,1), gel(B,1)));
     374          49 :     gel(A,2) = modii(gel(A,2), q);
     375          49 :     gel(B,2) = modii(gel(B,2), q);
     376          49 :     h++;
     377          49 :   } while (equalii(gel(A,2), gel(B,2)));
     378          49 :   l = Fp_div(Fp_sub(gel(B,3), gel(A,3),q),Fp_sub(gel(A,2), gel(B,2), q), q);
     379          49 :   return gerepileuptoint(av, l);
     380             : }
     381             : 
     382             : /* compute a hash of g^(i-1), 1<=i<=n. Return [sorted hash, perm, g^-n] */
     383             : GEN
     384     2200105 : gen_Shanks_init(GEN g, long n, void *E, const struct bb_group *grp)
     385             : {
     386     2200105 :   GEN p1 = g, G, perm, table = cgetg(n+1,t_VECSMALL);
     387     2200105 :   pari_sp av=avma;
     388             :   long i;
     389     2200105 :   table[1] = grp->hash(grp->pow(E,g,gen_0));
     390    11068540 :   for (i=2; i<=n; i++)
     391             :   {
     392     8868435 :     table[i] = grp->hash(p1);
     393     8868435 :     p1 = grp->mul(E,p1,g);
     394     8868435 :     if (gc_needed(av,2))
     395             :     {
     396           0 :       if(DEBUGMEM>1) pari_warn(warnmem,"gen_Shanks_log, baby = %ld", i);
     397           0 :       p1 = gerepileupto(av, p1);
     398             :     }
     399             :   }
     400     2200105 :   G = gerepileupto(av, grp->pow(E,p1,gen_m1)); /* g^-n */
     401     2200105 :   perm = vecsmall_indexsort(table);
     402     2200105 :   table = vecsmallpermute(table,perm);
     403     2200105 :   return mkvec4(table,perm,g,G);
     404             : }
     405             : /* T from gen_Shanks_init(g,n). Return v < n*N such that x = g^v or NULL */
     406             : GEN
     407     2200553 : gen_Shanks(GEN T, GEN x, ulong N, void *E, const struct bb_group *grp)
     408             : {
     409     2200553 :   pari_sp av=avma;
     410     2200553 :   GEN table = gel(T,1), perm = gel(T,2), g = gel(T,3), G = gel(T,4);
     411     2200553 :   GEN p1 = x;
     412     2200553 :   long n = lg(table)-1;
     413             :   ulong k;
     414    12329573 :   for (k=0; k<N; k++)
     415             :   { /* p1 = x G^k, G = g^-n */
     416    12087730 :     long h = grp->hash(p1), i = zv_search(table, h);
     417    12087730 :     if (i)
     418             :     {
     419     1959455 :       do i--; while (i && table[i] == h);
     420     1958710 :       for (i++; i <= n && table[i] == h; i++)
     421             :       {
     422     1958710 :         GEN v = addiu(muluu(n,k), perm[i]-1);
     423     1958710 :         if (grp->equal(grp->pow(E,g,v),x)) return gerepileuptoint(av,v);
     424           0 :         if (DEBUGLEVEL)
     425           0 :           err_printf("gen_Shanks_log: false positive %lu, %lu\n", k,h);
     426             :       }
     427             :     }
     428    10129020 :     p1 = grp->mul(E,p1,G);
     429    10129020 :     if (gc_needed(av,2))
     430             :     {
     431           0 :       if(DEBUGMEM>1) pari_warn(warnmem,"gen_Shanks_log, k = %lu", k);
     432           0 :       p1 = gerepileupto(av, p1);
     433             :     }
     434             :   }
     435      241843 :   return NULL;
     436             : }
     437             : /* Generic Shanks baby-step/giant-step algorithm. Return log_g(x), ord g = q.
     438             :  * One-shot: use gen_Shanks_init/log if many logs are desired; early abort
     439             :  * if log < sqrt(q) */
     440             : static GEN
     441       95528 : gen_Shanks_log(GEN x, GEN g, GEN q, void *E, const struct bb_group *grp)
     442             : {
     443       95528 :   pari_sp av=avma, av1;
     444             :   long lbaby, i, k;
     445             :   GEN p1, table, giant, perm, ginv;
     446       95528 :   p1 = sqrti(q);
     447       95528 :   if (cmpiu(p1,LGBITS) >= 0)
     448           0 :     pari_err_OVERFLOW("gen_Shanks_log [order too large]");
     449       95528 :   lbaby = itos(p1)+1; table = cgetg(lbaby+1,t_VECSMALL);
     450       95528 :   ginv = grp->pow(E,g,gen_m1);
     451       95528 :   av1 = avma;
     452      886149 :   for (p1=x, i=1;;i++)
     453             :   {
     454      886149 :     if (grp->equal1(p1)) { avma = av; return stoi(i-1); }
     455      875550 :     table[i] = grp->hash(p1); if (i==lbaby) break;
     456      790621 :     p1 = grp->mul(E,p1,ginv);
     457      790621 :     if (gc_needed(av1,2))
     458             :     {
     459           7 :       if(DEBUGMEM>1) pari_warn(warnmem,"gen_Shanks_log, baby = %ld", i);
     460           7 :       p1 = gerepileupto(av1, p1);
     461             :     }
     462      790621 :   }
     463       84929 :   p1 = giant = gerepileupto(av1, grp->mul(E,x,grp->pow(E, p1, gen_m1)));
     464       84929 :   perm = vecsmall_indexsort(table);
     465       84929 :   table = vecsmallpermute(table,perm);
     466       84929 :   av1 = avma;
     467      457182 :   for (k=1; k<= lbaby; k++)
     468             :   {
     469      457182 :     long h = grp->hash(p1), i = zv_search(table, h);
     470      457182 :     if (i)
     471             :     {
     472       84929 :       while (table[i] == h && i) i--;
     473       84929 :       for (i++; i <= lbaby && table[i] == h; i++)
     474             :       {
     475       84929 :         GEN v = addiu(mulss(lbaby-1,k),perm[i]-1);
     476       84929 :         if (grp->equal(grp->pow(E,g,v),x)) return gerepileuptoint(av,v);
     477           0 :         if (DEBUGLEVEL)
     478           0 :           err_printf("gen_Shanks_log: false positive %ld, %lu\n", k,h);
     479             :       }
     480             :     }
     481      372253 :     p1 = grp->mul(E,p1,giant);
     482      372253 :     if (gc_needed(av1,2))
     483             :     {
     484           7 :       if(DEBUGMEM>1) pari_warn(warnmem,"gen_Shanks_log, k = %ld", k);
     485           7 :       p1 = gerepileupto(av1, p1);
     486             :     }
     487             :   }
     488           0 :   avma = av; return cgetg(1, t_VEC); /* no solution */
     489             : }
     490             : 
     491             : /*Generic discrete logarithme in a group of prime order p*/
     492             : GEN
     493      457590 : gen_plog(GEN x, GEN g, GEN p, void *E, const struct bb_group *grp)
     494             : {
     495      457590 :   if (grp->easylog)
     496             :   {
     497      418237 :     GEN e = grp->easylog(E, x, g, p);
     498      418237 :     if (e) return e;
     499             :   }
     500      124299 :   if (grp->equal1(x)) return gen_0;
     501      124257 :   if (grp->equal(x,g)) return gen_1;
     502       95577 :   if (expi(p)<32) return gen_Shanks_log(x,g,p,E,grp);
     503          49 :   return gen_Pollard_log(x, g, p, E, grp);
     504             : }
     505             : 
     506             : GEN
     507     5593708 : dlog_get_ordfa(GEN o)
     508             : {
     509     5593708 :   if (!o) return NULL;
     510     5593708 :   switch(typ(o))
     511             :   {
     512             :     case t_INT:
     513     4265476 :       if (signe(o) > 0) return mkvec2(o, Z_factor(o));
     514           7 :       break;
     515             :     case t_MAT:
     516     1134668 :       if (is_Z_factorpos(o)) return mkvec2(factorback(o), o);
     517          14 :       break;
     518             :     case t_VEC:
     519      193557 :       if (lg(o) == 3 && signe(gel(o,1)) > 0 && is_Z_factorpos(gel(o,2))) return o;
     520           0 :       break;
     521             :   }
     522          28 :   pari_err_TYPE("generic discrete logarithm (order factorization)",o);
     523           0 :   return NULL; /* not reached */
     524             : }
     525             : GEN
     526       75807 : dlog_get_ord(GEN o)
     527             : {
     528       75807 :   if (!o) return NULL;
     529       75807 :   switch(typ(o))
     530             :   {
     531             :     case t_INT:
     532       56491 :       if (signe(o) > 0) return o;
     533           7 :       break;
     534             :     case t_MAT:
     535          14 :       o = factorback(o);
     536           0 :       if (typ(o) == t_INT && signe(o) > 0) return o;
     537           0 :       break;
     538             :     case t_VEC:
     539       19295 :       if (lg(o) != 3) break;
     540       19295 :       o = gel(o,1);
     541       19295 :       if (typ(o) == t_INT && signe(o) > 0) return o;
     542           0 :       break;
     543             :   }
     544          14 :   pari_err_TYPE("generic discrete logarithm (order factorization)",o);
     545           0 :   return NULL; /* not reached */
     546             : }
     547             : 
     548             : /* grp->easylog() is an optional trapdoor function that catch easy logarithms*/
     549             : /* Generic Pohlig-Hellman discrete logarithm*/
     550             : /* smallest integer n such that g^n=a. Assume g has order ord */
     551             : GEN
     552      239192 : gen_PH_log(GEN a, GEN g, GEN ord, void *E, const struct bb_group *grp)
     553             : {
     554      239192 :   pari_sp av = avma;
     555             :   GEN v,t0,a0,b,q,g_q,n_q,ginv0,qj,ginv;
     556             :   GEN fa, ex;
     557             :   long e,i,j,l;
     558             : 
     559      239192 :   if (grp->equal(g, a)) /* frequent special case */
     560       49218 :     return grp->equal1(g)? gen_0: gen_1;
     561      189974 :   if (grp->easylog)
     562             :   {
     563      189876 :     GEN e = grp->easylog(E, a, g, ord);
     564      189848 :     if (e) return e;
     565             :   }
     566      101516 :   v = dlog_get_ordfa(ord);
     567      101516 :   ord= gel(v,1);
     568      101516 :   fa = gel(v,2);
     569      101516 :   ex = gel(fa,2);
     570      101516 :   fa = gel(fa,1); l = lg(fa);
     571      101516 :   ginv = grp->pow(E,g,gen_m1);
     572      101516 :   v = cgetg(l, t_VEC);
     573      276243 :   for (i=1; i<l; i++)
     574             :   {
     575      174734 :     q = gel(fa,i);
     576      174734 :     e = itos(gel(ex,i));
     577      174734 :     if (DEBUGLEVEL>5)
     578           0 :       err_printf("Pohlig-Hellman: DL mod %Ps^%ld\n",q,e);
     579      174734 :     qj = new_chunk(e+1);
     580      174734 :     gel(qj,0) = gen_1;
     581      174734 :     gel(qj,1) = q;
     582      174734 :     for (j=2; j<=e; j++) gel(qj,j) = mulii(gel(qj,j-1), q);
     583      174734 :     t0 = diviiexact(ord, gel(qj,e));
     584      174734 :     a0 = grp->pow(E, a, t0);
     585      174734 :     ginv0 = grp->pow(E, ginv, t0); /* order q^e */
     586      174734 :     if (grp->equal1(ginv0))
     587             :     {
     588          14 :       gel(v,i) = mkintmod(gen_0, gen_1);
     589          14 :       continue;
     590             :     }
     591      174727 :     do { g_q = grp->pow(E,g, mulii(t0, gel(qj,--e))); /* order q */
     592      174727 :     } while (grp->equal1(g_q));
     593      174720 :     n_q = gen_0;
     594      266837 :     for (j=0;; j++)
     595             :     { /* n_q = sum_{i<j} b_i q^i */
     596      266837 :       b = grp->pow(E,a0, gel(qj,e-j));
     597             :       /* early abort: cheap and very effective */
     598      266837 :       if (j == 0 && !grp->equal1(grp->pow(E,b,q))) {
     599           7 :         avma = av; return cgetg(1, t_VEC);
     600             :       }
     601      266830 :       b = gen_plog(b, g_q, q, E, grp);
     602      266830 :       if (typ(b) != t_INT) { avma = av; return cgetg(1, t_VEC); }
     603      266830 :       n_q = addii(n_q, mulii(b, gel(qj,j)));
     604      266830 :       if (j == e) break;
     605             : 
     606       92117 :       a0 = grp->mul(E,a0, grp->pow(E,ginv0, b));
     607       92117 :       ginv0 = grp->pow(E,ginv0, q);
     608       92117 :     }
     609      174713 :     gel(v,i) = mkintmod(n_q, gel(qj,e+1));
     610             :   }
     611      101509 :   return gerepileuptoint(av, lift(chinese1_coprime_Z(v)));
     612             : }
     613             : 
     614             : /***********************************************************************/
     615             : /**                                                                   **/
     616             : /**                    ORDER OF AN ELEMENT                            **/
     617             : /**                                                                   **/
     618             : /***********************************************************************/
     619             : /*Find the exact order of a assuming a^o==1*/
     620             : GEN
     621     2913332 : gen_order(GEN a, GEN o, void *E, const struct bb_group *grp)
     622             : {
     623     2913332 :   pari_sp av = avma;
     624             :   long i, l;
     625             :   GEN m;
     626             : 
     627     2913332 :   m = dlog_get_ordfa(o);
     628     2913332 :   if (!m) pari_err_TYPE("gen_order [missing order]",a);
     629     2913332 :   o = gel(m,1);
     630     2913332 :   m = gel(m,2); l = lgcols(m);
     631     9326949 :   for (i = l-1; i; i--)
     632             :   {
     633     6413617 :     GEN t, y, p = gcoeff(m,i,1);
     634     6413617 :     long j, e = itos(gcoeff(m,i,2));
     635     6413617 :     if (l == 2) {
     636      571935 :       t = gen_1;
     637      571935 :       y = a;
     638             :     } else {
     639     5841682 :       t = diviiexact(o, powiu(p,e));
     640     5841682 :       y = grp->pow(E, a, t);
     641             :     }
     642     6413617 :     if (grp->equal1(y)) o = t;
     643             :     else {
     644     6086308 :       for (j = 1; j < e; j++)
     645             :       {
     646     2063862 :         y = grp->pow(E, y, p);
     647     2063862 :         if (grp->equal1(y)) break;
     648             :       }
     649     4539714 :       if (j < e) {
     650      517268 :         if (j > 1) p = powiu(p, j);
     651      517268 :         o = mulii(t, p);
     652             :       }
     653             :     }
     654             :   }
     655     2913332 :   return gerepilecopy(av, o);
     656             : }
     657             : 
     658             : /*Find the exact order of a assuming a^o==1, return [order,factor(order)] */
     659             : GEN
     660     2270720 : gen_factored_order(GEN a, GEN o, void *E, const struct bb_group *grp)
     661             : {
     662     2270720 :   pari_sp av = avma;
     663             :   long i, l, ind;
     664             :   GEN m, F, P;
     665             : 
     666     2270720 :   m = dlog_get_ordfa(o);
     667     2270720 :   if (!m) pari_err_TYPE("gen_factored_order [missing order]",a);
     668     2270720 :   o = gel(m,1);
     669     2270720 :   m = gel(m,2); l = lgcols(m);
     670     2270720 :   P = cgetg(l, t_COL); ind = 1;
     671     2270720 :   F = cgetg(l, t_COL);
     672     5456648 :   for (i = l-1; i; i--)
     673             :   {
     674     3185928 :     GEN t, y, p = gcoeff(m,i,1);
     675     3185928 :     long j, e = itos(gcoeff(m,i,2));
     676     3185928 :     if (l == 2) {
     677     1392248 :       t = gen_1;
     678     1392248 :       y = a;
     679             :     } else {
     680     1793680 :       t = diviiexact(o, powiu(p,e));
     681     1793680 :       y = grp->pow(E, a, t);
     682             :     }
     683     3185928 :     if (grp->equal1(y)) o = t;
     684             :     else {
     685     3995926 :       for (j = 1; j < e; j++)
     686             :       {
     687      849979 :         y = grp->pow(E, y, p);
     688      849979 :         if (grp->equal1(y)) break;
     689             :       }
     690     3156641 :       gel(P,ind) = p;
     691     3156641 :       gel(F,ind) = utoipos(j);
     692     3156641 :       if (j < e) {
     693       10694 :         if (j > 1) p = powiu(p, j);
     694       10694 :         o = mulii(t, p);
     695             :       }
     696     3156641 :       ind++;
     697             :     }
     698             :   }
     699     2270720 :   setlg(P, ind); P = vecreverse(P);
     700     2270720 :   setlg(F, ind); F = vecreverse(F);
     701     2270720 :   return gerepilecopy(av, mkvec2(o, mkmat2(P,F)));
     702             : }
     703             : 
     704             : /* E has order o[1], ..., or o[#o], draw random points until all solutions
     705             :  * but one are eliminated */
     706             : GEN
     707         917 : gen_select_order(GEN o, void *E, const struct bb_group *grp)
     708             : {
     709         917 :   pari_sp ltop = avma, btop;
     710             :   GEN lastgood, so, vo;
     711         917 :   long lo = lg(o), nbo=lo-1;
     712         917 :   if (nbo == 1) return icopy(gel(o,1));
     713         448 :   so = ZV_indexsort(o); /* minimize max( o[i+1] - o[i] ) */
     714         448 :   vo = zero_zv(lo);
     715         448 :   lastgood = gel(o, so[nbo]);
     716         448 :   btop = avma;
     717             :   for(;;)
     718             :   {
     719         448 :     GEN lasto = gen_0;
     720         448 :     GEN P = grp->rand(E), t = mkvec(gen_0);
     721             :     long i;
     722         623 :     for (i = 1; i < lo; i++)
     723             :     {
     724         623 :       GEN newo = gel(o, so[i]);
     725         623 :       if (vo[i]) continue;
     726         623 :       t = grp->mul(E,t, grp->pow(E, P, subii(newo,lasto)));/*P^o[i]*/
     727         623 :       lasto = newo;
     728         623 :       if (!grp->equal1(t))
     729             :       {
     730         539 :         if (--nbo == 1) { avma=ltop; return icopy(lastgood); }
     731          91 :         vo[i] = 1;
     732             :       }
     733             :       else
     734          84 :         lastgood = lasto;
     735             :     }
     736           0 :     avma = btop;
     737           0 :   }
     738             : }
     739             : 
     740             : /*******************************************************************/
     741             : /*                                                                 */
     742             : /*                          n-th ROOT                              */
     743             : /*                                                                 */
     744             : /*******************************************************************/
     745             : /* Assume l is prime. Return a generator of the l-th Sylow and set *zeta to an element
     746             :  * of order l.
     747             :  *
     748             :  * q = l^e*r, e>=1, (r,l)=1
     749             :  * UNCLEAN */
     750             : static GEN
     751      289152 : gen_lgener(GEN l, long e, GEN r,GEN *zeta, void *E, const struct bb_group *grp)
     752             : {
     753      289152 :   const pari_sp av1 = avma;
     754             :   GEN m, m1;
     755             :   long i;
     756      220560 :   for (;; avma = av1)
     757             :   {
     758      509712 :     m1 = m = grp->pow(E, grp->rand(E), r);
     759      509712 :     if (grp->equal1(m)) continue;
     760      911258 :     for (i=1; i<e; i++)
     761             :     {
     762      622107 :       m = grp->pow(E,m,l);
     763      622106 :       if (grp->equal1(m)) break;
     764             :     }
     765      412589 :     if (i==e) break;
     766      220560 :   }
     767      289152 :   *zeta = m; return m1;
     768             : }
     769             : 
     770             : /* Let G be a cyclic group of order o>1. Returns a (random) generator */
     771             : 
     772             : GEN
     773       14665 : gen_gener(GEN o, void *E, const struct bb_group *grp)
     774             : {
     775       14665 :   pari_sp ltop = avma, av;
     776             :   long i, lpr;
     777       14665 :   GEN F, N, pr, z=NULL;
     778       14665 :   F = dlog_get_ordfa(o);
     779       14665 :   N = gel(F,1); pr = gel(F,2); lpr = lgcols(pr);
     780       14665 :   av = avma;
     781             : 
     782       48811 :   for (i = 1; i < lpr; i++)
     783             :   {
     784       34146 :     GEN l = gcoeff(pr,i,1);
     785       34146 :     long e = itos(gcoeff(pr,i,2));
     786       34146 :     GEN r = diviiexact(N,powis(l,e));
     787       34146 :     GEN zetan, zl = gen_lgener(l,e,r,&zetan,E,grp);
     788       34146 :     z = i==1 ? zl: grp->mul(E,z,zl);
     789       34146 :     if (gc_needed(av,2))
     790             :     { /* n can have lots of prime factors*/
     791           0 :       if(DEBUGMEM>1) pari_warn(warnmem,"gen_gener");
     792           0 :       z = gerepileupto(av, z);
     793             :     }
     794             :   }
     795       14665 :   return gerepileupto(ltop, z);
     796             : }
     797             : 
     798             : /* solve x^l = a , l prime in G of order q.
     799             :  *
     800             :  * q =  (l^e)*r, e >= 1, (r,l) = 1
     801             :  * y is not an l-th power, hence generates the l-Sylow of G
     802             :  * m = y^(q/l) != 1 */
     803             : static GEN
     804      255076 : gen_Shanks_sqrtl(GEN a, GEN l, long e, GEN r, GEN y, GEN m,void *E,
     805             :                  const struct bb_group *grp)
     806             : {
     807      255076 :   pari_sp av = avma;
     808             :   long k;
     809             :   GEN p1, u1, u2, v, w, z, dl;
     810             : 
     811      255076 :   (void)bezout(r,l,&u1,&u2);
     812      255076 :   v = grp->pow(E,a,u2);
     813      255076 :   w = grp->pow(E,v,l);
     814      255076 :   w = grp->mul(E,w,grp->pow(E,a,gen_m1));
     815      700883 :   while (!grp->equal1(w))
     816             :   {
     817      196466 :     k = 0;
     818      196466 :     p1 = w;
     819             :     do
     820             :     {
     821      335536 :       z = p1; p1 = grp->pow(E,p1,l);
     822      335536 :       k++;
     823      335536 :     } while(!grp->equal1(p1));
     824      196466 :     if (k==e) { avma = av; return NULL; }
     825      190760 :     dl = gen_plog(z,m,l,E,grp);
     826      190760 :     if (typ(dl) != t_INT) { avma = av; return NULL; }
     827      190760 :     dl = negi(dl);
     828      190760 :     p1 = grp->pow(E, grp->pow(E,y, dl), powiu(l,e-k-1));
     829      190760 :     m = grp->pow(E,m,dl);
     830      190760 :     e = k;
     831      190760 :     v = grp->mul(E,p1,v);
     832      190760 :     y = grp->pow(E,p1,l);
     833      190759 :     w = grp->mul(E,y,w);
     834      190759 :     if (gc_needed(av,1))
     835             :     {
     836           0 :       if(DEBUGMEM>1) pari_warn(warnmem,"gen_Shanks_sqrtl");
     837           0 :       gerepileall(av,4, &y,&v,&w,&m);
     838             :     }
     839             :   }
     840      249354 :   return gerepilecopy(av, v);
     841             : }
     842             : /* Return one solution of x^n = a in a cyclic group of order q
     843             :  *
     844             :  * 1) If there is no solution, return NULL.
     845             :  *
     846             :  * 2) If there is a solution, there are exactly m of them [m = gcd(q-1,n)].
     847             :  * If zetan!=NULL, *zetan is set to a primitive m-th root of unity so that
     848             :  * the set of solutions is { x*zetan^k; k=0..m-1 }
     849             :  */
     850             : GEN
     851      271659 : gen_Shanks_sqrtn(GEN a, GEN n, GEN q, GEN *zetan, void *E, const struct bb_group *grp)
     852             : {
     853      271659 :   pari_sp ltop = avma;
     854             :   GEN m, u1, u2, z;
     855             :   int is_1;
     856             : 
     857      271659 :   if (is_pm1(n))
     858             :   {
     859           0 :     if (zetan) *zetan = grp->pow(E,a,gen_0);
     860           0 :     return signe(n) < 0? grp->pow(E,a,gen_m1): gcopy(a);
     861             :   }
     862      271659 :   is_1 = grp->equal1(a);
     863      271657 :   if (is_1 && !zetan) return gcopy(a);
     864             : 
     865      261388 :   m = bezout(n,q,&u1,&u2);
     866      261387 :   z = grp->pow(E,a,gen_0);
     867      261385 :   if (!is_pm1(m))
     868             :   {
     869      254959 :     GEN F = Z_factor(m);
     870             :     long i, j, e;
     871             :     GEN r, zeta, y, l;
     872      254959 :     pari_sp av1 = avma;
     873      504245 :     for (i = nbrows(F); i; i--)
     874             :     {
     875      255001 :       l = gcoeff(F,i,1);
     876      255001 :       j = itos(gcoeff(F,i,2));
     877      255003 :       e = Z_pvalrem(q,l,&r);
     878      255004 :       y = gen_lgener(l,e,r,&zeta,E,grp);
     879      255006 :       if (zetan) z = grp->mul(E,z, grp->pow(E,y,powiu(l,e-j)));
     880      255006 :       if (!is_1) {
     881             :         do
     882             :         {
     883      255076 :           a = gen_Shanks_sqrtl(a,l,e,r,y,zeta,E,grp);
     884      255062 :           if (!a) { avma = ltop; return NULL;}
     885      249356 :         } while (--j);
     886             :       }
     887      249286 :       if (gc_needed(ltop,1))
     888             :       { /* n can have lots of prime factors*/
     889           0 :         if(DEBUGMEM>1) pari_warn(warnmem,"gen_Shanks_sqrtn");
     890           0 :         gerepileall(av1, zetan? 2: 1, &a, &z);
     891             :       }
     892             :     }
     893             :   }
     894      255671 :   if (!equalii(m, n))
     895        6447 :     a = grp->pow(E,a,modii(u1,q));
     896      255670 :   if (zetan)
     897             :   {
     898         119 :     *zetan = z;
     899         119 :     gerepileall(ltop,2,&a,zetan);
     900             :   }
     901             :   else /* is_1 is 0: a was modified above -> gerepileupto valid */
     902      255551 :     a = gerepileupto(ltop, a);
     903      255670 :   return a;
     904             : }
     905             : 
     906             : /*******************************************************************/
     907             : /*                                                                 */
     908             : /*               structure of groups with pairing                  */
     909             : /*                                                                 */
     910             : /*******************************************************************/
     911             : 
     912             : static GEN
     913       39515 : ellgroup_d2(GEN N, GEN d)
     914             : {
     915       39515 :   GEN r = gcdii(N, d);
     916       39515 :   GEN F1 = gel(Z_factor(r), 1);
     917       39515 :   long i, j, l1 = lg(F1);
     918       39515 :   GEN F = cgetg(3, t_MAT);
     919       39515 :   gel(F,1) = cgetg(l1, t_COL);
     920       39515 :   gel(F,2) = cgetg(l1, t_COL);
     921       69517 :   for (i = 1, j = 1; i < l1; ++i)
     922             :   {
     923       30002 :     long v = Z_pval(N, gel(F1, i));
     924       30002 :     if (v<=1) continue;
     925       15554 :     gcoeff(F, j  , 1) = gel(F1, i);
     926       15554 :     gcoeff(F, j++, 2) = stoi(v);
     927             :   }
     928       39515 :   setlg(F[1],j); setlg(F[2],j);
     929       39515 :   return j==1 ? NULL : mkvec2(factorback(F), F);
     930             : }
     931             : 
     932             : GEN
     933       39592 : gen_ellgroup(GEN N, GEN d, GEN *pt_m, void *E, const struct bb_group *grp,
     934             :              GEN pairorder(void *E, GEN P, GEN Q, GEN m, GEN F))
     935             : {
     936       39592 :   pari_sp av = avma;
     937             :   GEN N0, N1, F;
     938       39592 :   if (pt_m) *pt_m = gen_1;
     939       39592 :   if (is_pm1(N)) return cgetg(1,t_VEC);
     940       39515 :   F = ellgroup_d2(N, d);
     941       39515 :   if (!F) {avma = av; return mkveccopy(N);}
     942       14861 :   N0 = gel(F,1); N1 = diviiexact(N, N0);
     943             :   while(1)
     944             :   {
     945       26237 :     pari_sp av2 = avma;
     946             :     GEN P, Q, d, s, t, m;
     947             : 
     948       26237 :     P = grp->pow(E,grp->rand(E), N1);
     949       26237 :     s = gen_order(P, F, E, grp); if (equalii(s, N0)) {avma = av; return mkveccopy(N);}
     950             : 
     951       20547 :     Q = grp->pow(E,grp->rand(E), N1);
     952       20547 :     t = gen_order(Q, F, E, grp); if (equalii(t, N0)) {avma = av; return mkveccopy(N);}
     953             : 
     954       17970 :     m = lcmii(s, t);
     955       17970 :     d = pairorder(E, P, Q, m, F);
     956             :     /* structure is [N/d, d] iff m d == N0. Note that N/d = N1 m */
     957       17970 :     if (is_pm1(d) && equalii(m, N0)) {avma = av; return mkveccopy(N);}
     958       17942 :     if (equalii(mulii(m, d), N0))
     959             :     {
     960        6566 :       GEN g = mkvec2(mulii(N1,m), d);
     961        6566 :       if (pt_m) *pt_m = m;
     962        6566 :       gerepileall(av,pt_m?2:1,&g,pt_m);
     963        6566 :       return g;
     964             :     }
     965       11376 :     avma = av2;
     966       11376 :   }
     967             : }
     968             : 
     969             : GEN
     970        2646 : gen_ellgens(GEN D1, GEN d2, GEN m, void *E, const struct bb_group *grp,
     971             :              GEN pairorder(void *E, GEN P, GEN Q, GEN m, GEN F))
     972             : {
     973        2646 :   pari_sp ltop = avma, av;
     974             :   GEN F, d1, dm;
     975             :   GEN P, Q, d, s;
     976        2646 :   F = dlog_get_ordfa(D1);
     977        2646 :   d1 = gel(F, 1), dm =  diviiexact(d1,m);
     978        2646 :   av = avma;
     979             :   do
     980             :   {
     981        7028 :     avma = av;
     982        7028 :     P = grp->rand(E);
     983        7028 :     s = gen_order(P, F, E, grp);
     984        7028 :   } while (!equalii(s, d1));
     985        2646 :   av = avma;
     986             :   do
     987             :   {
     988        5211 :     avma = av;
     989        5211 :     Q = grp->rand(E);
     990        5211 :     d = pairorder(E, grp->pow(E, P, dm), grp->pow(E, Q, dm), m, F);
     991        5211 :   } while (!equalii(d, d2));
     992        2646 :   return gerepilecopy(ltop, mkvec2(P,Q));
     993             : }

Generated by: LCOV version 1.11