我正在寻找 gcry_mpi_t
类型的定义。我正在研究 GnuPG 的代码,它使用 libgcrypt,而 libgcrypt 又使用后者作为负责存储模数、RSA key 的素数等的类型。通常在 /libgcrypt-1.8 中。 2/cipher/rsa.c
你可以找到:
typedef struct
{
gcry_mpi_t n; /* modulus */
gcry_mpi_t e; /* exponent */
} RSA_public_key;
typedef struct
{
gcry_mpi_t n; /* public modulus */
gcry_mpi_t e; /* public exponent */
gcry_mpi_t d; /* exponent */
gcry_mpi_t p; /* prime p. */
gcry_mpi_t q; /* prime q. */
gcry_mpi_t u; /* inverse of p mod q. */
} RSA_secret_key;
我找到了this SO post其中提到了我试图定义的特定类型,但没有说明它是如何定义的。
我的目标是在介绍 RSA 及其实现方式的基本 CS 类中使用该定义。因此,我希望展示如何通过专门设计的struct
来处理特定的 RSA 变量,以实现高效的内存管理。
但是,到目前为止,我无法在 libgcrypt 代码中找到定义它的正确代码段。谢谢!
最佳答案
src/gcrypt.h.in (用于生成 <gcrypt.h>
header :
/* The data objects used to hold multi precision integers. */
struct gcry_mpi;
typedef struct gcry_mpi *gcry_mpi_t;
如此公开gcry_mpi_t
被定义为指向不完整结构的指针,允许实现保持私有(private)。如果您只是查看已安装的 header ,您将找不到完整的定义。不过,对于内部使用,src/mpi.h定义struct gcry_mpi
如:
struct gcry_mpi
{
int alloced; /* Array size (# of allocated limbs). */
int nlimbs; /* Number of valid limbs. */
int sign; /* Indicates a negative number and is also used
for opaque MPIs to store the length. */
unsigned int flags; /* Bit 0: Array to be allocated in secure memory space.*/
/* Bit 2: The limb is a pointer to some m_alloced data.*/
/* Bit 4: Immutable MPI - the MPI may not be modified. */
/* Bit 5: Constant MPI - the MPI will not be freed. */
mpi_limb_t *d; /* Array with the limbs */
};
关于c - libgcrypt-1.8.2 中的 gcry_mpi_t 类型定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48566724/