【发布时间】:2014-05-06 18:33:48
【问题描述】:
为了更好地理解 RSA,我一直在研究 GunPG 1.4 的源代码,特别是 rsa.c 文件中的 RSA 实现。正如标题所说,我无法弄清楚填充发生在哪里。
因此,通常在 RSA 中,填充是在加密之前完成的,并在解密期间取消。加密首先从我们看到的第 409 行开始
int
rsa_encrypt( int algo, MPI *resarr, MPI data, MPI *pkey )
{
RSA_public_key pk;
if( algo != 1 && algo != 2 )
return G10ERR_PUBKEY_ALGO;
pk.n = pkey[0];
pk.e = pkey[1];
resarr[0] = mpi_alloc( mpi_get_nlimbs( pk.n ) );
public( resarr[0], data, &pk );
return 0;
}
这看起来很简单,它在第 220 行将数据提供给更高的“公共”函数。公共负责计算重要的 (c = m^e mod n) 过程。这一切看起来像:
static void
public(MPI output, MPI input, RSA_public_key *pkey )
{
if( output == input ) { /* powm doesn't like output and input the same */
MPI x = mpi_alloc( mpi_get_nlimbs(input)*2 );
mpi_powm( x, input, pkey->e, pkey->n );
mpi_set(output, x);
mpi_free(x);
}
else
mpi_powm( output, input, pkey->e, pkey->n );
}
等一下……现在看来,public 正在将该计算的工作传递给位于 mpi-pow.c 文件中的 mpi_powm()。我会为您省去细节,但该功能会变得很长。
在所有这一切的某个地方,某种 PKCS#1 填充和取消填充(或类似的东西)正在发生,但我无法弄清楚我的一生在哪里。谁能帮我看看填充发生在哪里?
【问题讨论】:
标签: encryption rsa padding gnupg