c - libgcrypt-1.8.2 中的 gcry_mpi_t 类型定义

标签 c rsa gnupg libgcrypt

我正在寻找 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/

相关文章:

c - 预期的标识符什么的?

openssl - 是否可以从 Rust-openssl 中的密码生成 RSA key 对?

javascript - 为什么同一个 GPG key 可以有两个不同的 ASCII 装甲?

python - 使用 pyCrypto 的 RSA python 公钥

c - 启用 HANDLE_PRAGMA_PACK_WITH_EXPANSION

c - 返回非 NULL 字符串会导致编译错误

c - buffer.ifr_hwaddr.sa_data[s] 中 u_char[6] 中的 MAC 地址

java - 为什么我的 RSA 2048 公钥是 294 字节长?

java - 如何将DSA证书转换为RSA证书?

python - OpenPGP/X.509 桥 : how to verify public key?