One*_*iot 5 encryption rsa gnupg padding
为了更好地理解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;
}
Run Code Online (Sandbox Code Playgroud)
这似乎很容易,它将数据提供给第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 );
}
Run Code Online (Sandbox Code Playgroud)
等一下......现在看起来公共正在将该计算的工作传递给位于mpi-pow.c文件中的mpi_powm().我会告诉你细节,但这个功能真的很长.
在某些地方,某种类型的PKCS#1填充和取消填充(或类似的东西)正在发生,但我无法弄清楚我的生活在哪里.任何人都可以帮我看看填充发生在哪里?