如何解决Pohlig-Hellman 的实现无法解决大指数 编辑
我正在尝试创建 Pohlig-Hellman algorithm 的实现,以便创建一个实用程序来在 Diffie-Hellman 协议的实现中制作/利用后门。该项目的灵感来自 NCC Group 的 2016 white-paper。
我目前有一个实现,here,它适用于相对较小的指数——即给定一个线性同余,g^x = h (mod n)
,对于一些特制的模数,n = pq
,其中 {{ 1}} 和 p
是质数,我的实现可以解决 q
小于 x
的值。
但是,如果 min{ p,q }
大于 x
的最小素因数,那么我的实现将给出不正确的解决方案。我怀疑问题可能不在于我对 Pohlig-Hellman 的实现本身,而在于我传递给它的参数。所有代码都可以在上面提供的链接中找到,但我会在这里复制相关的代码片段:
n
上面是我对 Pohlig-Hellman 的实现,下面是我称之为在 Diffie-Hellman 协议的某些实现中利用后门的地方。
#
# Implementation of Pohlig-Hellman algorithm
#
# The `crt` function implements the Chinese Remainder Theorem,and the `pollard` function implements
# Pollard's Rho algorithm for discrete logarithms (see /dph/crt.py and /dph/pollard.py).
#
def pohlig(G,H,P,factors):
g = [pow(G,divexact(P - 1,f),P) for f in factors]
h = [pow(H,P) for f in factors]
if Config.verbose:
x = []
total = len(factors)
for i,(gi,hi) in enumerate(zip(g,h),start=1):
print('Solving discrete logarithm {}/{}...'.format(str(i).rjust(len(str(total))),total))
result = pollard(gi,hi,P)
x.append(result)
print(f'x = 0x{result.digits(16)}')
else:
x = [pollard(gi,P) for gi,hi in zip(g,h)]
return crt(x,factors)
以下是我正在做的事情的总结:
- 选择一个素数
def _exp(args): g = args.g h = args.h p_factors = list(map(mpz,args.p_factors.split(','))) try: p_factors.remove(2) except ValueError: pass q_factors = list(map(mpz,args.q_factors.split(','))) try: q_factors.remove(2) except ValueError: pass p = 2 * _product(*p_factors) + 1 q = 2 * _product(*q_factors) + 1 if Config.verbose: print(f'p = 0x{p.digits(16)}') print(f'q = 0x{q.digits(16)}') print() print(f'Compute the discrete logarithm modulo `p`') print(f'-----------------------------------------') px = pohlig(g % p,h % p,p,p_factors) if Config.verbose: print() print(f'Compute the discrete logarithm modulo `q`') print(f'-----------------------------------------') qx = pohlig(g % q,h % q,q,q_factors) if Config.verbose: print() x = crt([px,qx],[p,q]) print(f'x = 0x{x.digits(16)}')
,其中p = 2 * prod{ p_i } + 1
表示一组素数。 - 选择一个素数
p_i
,其中q = 2 * prod{ q_j } + 1
表示一组素数。 - 在 Diffie-Hellman 的某些实现中注入
q_j
作为后门模数。 - 等待受害者(例如 Alice 计算
n = pq
,Bob 计算A = g^a (mod n)
)。 - 求解 Alice 或 Bob 的秘密指数
B = g^b (mod n)
或a
,并计算他们的共享密钥b
。
第 5 步是通过执行两次 Pohlig-Hellman 算法来求解 K = A^b = B^a (mod n)
和 x (mod p)
,然后使用中国剩余定理来求解 x (mod q)
。
编辑
我在第 5 步的描述中所指的 x (mod n)
是 Alice 的秘密指数 x
或 Bob 的秘密指数 a
,具体取决于我们选择的求解,因为只需要一个来计算共享密钥 b
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。