Skip to content

Commit 3130eee

Browse files
dirichlet_group_init: return flag instead of abort when prime factor is too large
1 parent 8836e83 commit 3130eee

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

dirichlet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dirichlet_group_size(const dirichlet_group_t G)
6464

6565
ulong dirichlet_group_num_primitive(const dirichlet_group_t G);
6666

67-
void dirichlet_group_init(dirichlet_group_t G, ulong q);
67+
int dirichlet_group_init(dirichlet_group_t G, ulong q);
6868
void dirichlet_subgroup_init(dirichlet_group_t H, const dirichlet_group_t G, ulong h);
6969
void dirichlet_group_clear(dirichlet_group_t G);
7070
void dirichlet_group_dlog_precompute(dirichlet_group_t G, ulong num);

dirichlet/group_init.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ dirichlet_group_lift_generators(dirichlet_group_t G)
103103
}
104104
}
105105

106-
void
106+
int
107107
dirichlet_group_init(dirichlet_group_t G, ulong q)
108108
{
109109
slong k;
@@ -123,6 +123,12 @@ dirichlet_group_init(dirichlet_group_t G, ulong q)
123123
n_factor_init(&fac);
124124
n_factor(&fac, q, 1);
125125

126+
#if FLINT_BITS == 64
127+
for (k = 0; k < fac.num; k++)
128+
if (fac.p[k] > UWORD(1000000000000))
129+
return 0;
130+
#endif
131+
126132
G->num = fac.num + G->neven;
127133
G->P = flint_malloc(G->num * sizeof(dirichlet_prime_group_struct));
128134
G->generators = flint_malloc(G->num * sizeof(ulong));
@@ -145,6 +151,8 @@ dirichlet_group_init(dirichlet_group_t G, ulong q)
145151
dirichlet_prime_group_init(&G->P[k], p, e);
146152
}
147153
dirichlet_group_lift_generators(G);
154+
155+
return 1;
148156
}
149157

150158
void

doc/source/dirichlet.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Multiplicative group modulo *q*
4848
An *dirichlet_group_t* is defined as an array of *dirichlet_group_struct*
4949
of length 1, permitting it to be passed by reference.
5050

51-
.. function:: void dirichlet_group_init(dirichlet_group_t G, ulong q)
51+
.. function:: int dirichlet_group_init(dirichlet_group_t G, ulong q)
5252

5353
Initializes *G* to the group of Dirichlet characters mod *q*.
5454

@@ -69,8 +69,9 @@ Multiplicative group modulo *q*
6969
safely be called even with large *q*.
7070

7171
For implementation reasons, the largest prime factor of *q* must not
72-
exceed `10^{12}` (an abort will be raised). This restriction could
73-
be removed in the future.
72+
exceed `10^{12}`. This restriction could
73+
be removed in the future. The function returns 1 on success and 0
74+
if a factor is too large.
7475

7576
.. function:: void dirichlet_subgroup_init(dirichlet_group_t H, const dirichlet_group_t G, ulong h)
7677

0 commit comments

Comments
 (0)