Skip to content

Commit 2d45b50

Browse files
Add new primes (#89)
Co-authored-by: Keith Fung <keithrfung@users.noreply.github.com>
1 parent 91174bb commit 2d45b50

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/electionguard/chaum_pedersen.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def is_valid(
163163
)
164164

165165
# The equation 𝐴^𝑣𝑖 = 𝑏𝑖𝑀𝑖^𝑐𝑖 mod 𝑝
166-
consistent_kv = (
166+
consistent_av = (
167167
in_bounds_alpha
168168
and in_bounds_b
169169
and in_bounds_c
@@ -183,7 +183,7 @@ def is_valid(
183183
and in_bounds_q
184184
and same_c
185185
and consistent_gv
186-
and consistent_kv
186+
and consistent_av
187187
)
188188

189189
if not success:
@@ -202,7 +202,7 @@ def is_valid(
202202
"in_bounds_q": in_bounds_q,
203203
"same_c": same_c,
204204
"consistent_gv": consistent_gv,
205-
"consistent_kv": consistent_kv,
205+
"consistent_av": consistent_av,
206206
"k": k,
207207
"q": q,
208208
"proof": self,
@@ -432,7 +432,7 @@ def make_constant_chaum_pedersen(
432432
Produces a proof that a given encryption corresponds to a specific total value.
433433
434434
:param message: An ElGamal ciphertext
435-
:param constant: The plaintext constant value used to make the ElGamal ciphertext
435+
:param constant: The plaintext constant value used to make the ElGamal ciphertext (L in the spec)
436436
:param r: The aggregate nonce used creating the ElGamal ciphertext
437437
:param k: The ElGamal public key for the election
438438
:param seed: Used to generate other random values here
@@ -441,9 +441,9 @@ def make_constant_chaum_pedersen(
441441

442442
# Pick one random number in Q.
443443
u = Nonces(seed, "constant-chaum-pedersen-proof")[0]
444-
a = g_pow_p(u)
445-
b = pow_p(k, u)
446-
c = hash_elems(alpha, beta, a, b)
444+
a = g_pow_p(u) # 𝑔^𝑢𝑖 mod 𝑝
445+
b = pow_p(k, u) # 𝐴^𝑢𝑖 mod 𝑝
446+
c = hash_elems(alpha, beta, a, b) # sha256(𝑄', A, B, a, b)
447447
v = a_plus_bc_q(u, c, r)
448448

449449
return ConstantChaumPedersenProof(a, b, c, v, constant)

src/electionguard/group.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
# Constants used by ElectionGuard
1010
Q: Final[int] = pow(2, 256) - 189
11-
P: Final[int] = pow(2, 4096) - 69 * Q - 2650872664557734482243044168410288960
11+
P: Final[
12+
int
13+
] = 1044388881413152506691752710716624382579964249047383780384233483283953907971553643537729993126875883902173634017777416360502926082946377942955704498542097614841825246773580689398386320439747911160897731551074903967243883427132918813748016269754522343505285898816777211761912392772914485521155521641049273446207578961939840619466145806859275053476560973295158703823395710210329314709715239251736552384080845836048778667318931418338422443891025911884723433084701207771901944593286624979917391350564662632723703007964229849154756196890615252286533089643184902706926081744149289517418249153634178342075381874131646013444796894582106870531535803666254579602632453103741452569793905551901541856173251385047414840392753585581909950158046256810542678368121278509960520957624737942914600310646609792665012858397381435755902851312071248102599442308951327039250818892493767423329663783709190716162023529669217300939783171415808233146823000766917789286154006042281423733706462905243774854543127239500245873582012663666430583862778167369547603016344242729592244544608279405999759391099775667746401633668308698186721172238255007962658564443858927634850415775348839052026675785694826386930175303143450046575460843879941791946313299322976993405829119
1214
R: Final[int] = ((P - 1) * pow(Q, -1, P)) % P
13-
G: Final[int] = pow(2, R, P)
15+
G: Final[
16+
int
17+
] = 14245109091294741386751154342323521003543059865261911603340669522218159898070093327838595045175067897363301047764229640327930333001123401070596314469603183633790452807428416775717923182949583875381833912370889874572112086966300498607364501764494811956017881198827400327403252039184448888877644781610594801053753235453382508543906993571248387749420874609737451803650021788641249940534081464232937193671929586747339353451021712752406225276255010281004857233043241332527821911604413582442915993833774890228705495787357234006932755876972632840760599399514028393542345035433135159511099877773857622699742816228063106927776147867040336649025152771036361273329385354927395836330206311072577683892664475070720408447257635606891920123791602538518516524873664205034698194561673019535564273204744076336022130453963648114321050173994259620611015189498335966173440411967562175734606706258335095991140827763942280037063180207172918769921712003400007923888084296685269233298371143630883011213745082207405479978418089917768242592557172834921185990876960527013386693909961093302289646193295725135238595082039133488721800071459503353417574248679728577942863659802016004283193163470835709405666994892499382890912238098413819320185166580019604608311466
1418
G_INV: Final[int] = pow(G, -1, P)
1519
Q_MINUS_ONE: Final[int] = Q - 1
1620

tests/test_chaum_pedersen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_cp_proofs_simple(self):
157157
integers(0, 100),
158158
integers(0, 100),
159159
)
160-
def test_ccp_proof(
160+
def test_cp_proof(
161161
self,
162162
keypair: ElGamalKeyPair,
163163
nonce: ElementModQ,

tests/test_elgamal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
g_pow_p,
1919
G,
2020
P,
21+
Q,
2122
ZERO_MOD_Q,
2223
TWO_MOD_Q,
2324
ONE_MOD_Q,
@@ -87,7 +88,7 @@ def test_elgamal_encryption_decryption_with_known_nonce_inverses(
8788
@given(elgamal_keypairs())
8889
def test_elgamal_generated_keypairs_are_within_range(self, keypair: ElGamalKeyPair):
8990
self.assertLess(keypair.public_key.to_int(), P)
90-
self.assertLess(keypair.secret_key.to_int(), G)
91+
self.assertLess(keypair.secret_key.to_int(), Q)
9192
self.assertEqual(g_pow_p(keypair.secret_key), keypair.public_key)
9293

9394
@given(

0 commit comments

Comments
 (0)