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)

以下是我正在做的事情的总结:

  1. 选择一个素数 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 表示一组素数。
  2. 选择一个素数 p_i,其中 q = 2 * prod{ q_j } + 1 表示一组素数。
  3. 在 Diffie-Hellman 的某些实现中注入 q_j 作为后门模数。
  4. 等待受害者(例如 Alice 计算 n = pq,Bob 计算 A = g^a (mod n))。
  5. 求解 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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...