Data Structures - gavincabbage/grsa GitHub Wiki
The GRSA library includes two data structures, grsa_key
and grsa_keypair
, used to represent RSA keys and keypairs respectively. Keypairs are generated pseudo-randomly using entropy from /dev/urandom
. Finding a better entropy pool is a current goal for the project.
RSA Key
An RSA key structure maintains three members: the length of the key in bytes, the public modulus and the key's exponent. Complementary public and private keys both include the same public modulus and length, but have different exponents.
typedef struct grsa_key
{
size_t bytes; /* Keysize in bytes. */
mpz_t modulus; /* Public modulus. */
mpz_t exponent; /* Public or private exponent. */
} grsa_key;
RSA Keypair
A valid RSA keypair consists of a pair of pointers to complementary public and private keys.
typedef struct grsa_keypair
{
grsa_key *pub; /* Public key. */
grsa_key *priv; /* Private key. */
} grsa_keypair;
Usage
A new keypair can be generated using grsa_generate_keypair()
. Key lengths between 1024 and 8192 bits are recommended to balance security and speed. Verify that a given keypair structure is a valid RSA keypair with grsa_verify_keypair()
. Once generated, the public and private keys can be used to encrypt, decrypt, sign and verify data with the library's core functions. Keys can also be exported and imported to and from data buffers themselves. After use, be careful to clear all initialized structures with grsa_clrkey()
and grsa_clrkeypair()
to avoid memory leaks.
Gavin Cabbage, 2013.
Please see the included MIT License for more information.