Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/electionguard/dlog.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# support for computing discrete logs, with a cache so they're never recomputed

import asyncio
from typing import Dict
from typing import Dict, Optional

from .group import G, ElementModP, ONE_MOD_P, mult_p, int_to_p_unchecked

__dlog_cache: Dict[ElementModP, int] = {ONE_MOD_P: 0}
__dlog_max_elem = ONE_MOD_P
__dlog_max_exp = 0
__dlog_lock = asyncio.Lock()

__dlog_lock: Optional[asyncio.Lock] = None


def discrete_log(e: ElementModP) -> int:
Expand Down Expand Up @@ -38,6 +39,10 @@ async def __discrete_log_internal(e: ElementModP) -> int:
global __dlog_max_exp
global __dlog_lock

if __dlog_lock is None:
# Initialize the lock on on first function call per process
__dlog_lock = asyncio.Lock()
Comment thread
AddressXception marked this conversation as resolved.

async with __dlog_lock:
g = int_to_p_unchecked(G)
while e != __dlog_max_elem:
Expand Down