RSA FUNCTIONS(3BM)

NAME
genRSAKeySet, getRSAPublicKey, getRSAPrivateKey, RSAEncrypt, RSADecrypt, RSASign, RSAVerify, randBytesNeededForRSA, freeRSAKeys, freeRSASig, RSAPrivateKeyDesEncrypt, RSAPrivateKeyDesDecrypt

SYNOPSIS
#include <libcrypt.h>

int randBytesNeededForRSA(int modbits, int publicExpBits)

RSAKeySet *genRSAKeySet(modulusBits, publicExpBits, randomStart)
int modulusBits, publicExpBits;
BigInt randomStart;

RSAPublicKey *getRSAPublicKey(RSAKeySet)
RSAKeySet *RSAKeySet;

RSAPrivateKey *getRSAPrivateKey(RSAKeySet)
RSAKeySet *RSAKeySet;

BigInt RSAEncrypt(message, RSAPubKey)
BigInt message;
RSAPublicKey *RSAPubKey;

BigInt RSADecrypt(message, RSAPrivKey)
BigInt message;
RSAPrivateKey *RSAPrivKey;

BigInt quantized_RSADecrypt(message, RSAPrivKey)
BigInt message;
RSAPrivateKey *RSAPrivKey;

RSASignature *RSASign(message, RSAPrivKey)
BigInt message;
RSAPRivateKey *RSAPrivKey;

RSASignature *quantized_RSASign(message, RSAPrivKey)
BigInt message;
RSAPRivateKey *RSAPrivKey;

Boolean RSAVerify(message, signature, RSAPubKey)
BigInt message;
RSASignature *signature;
RSAPublicKey *RSAPubKey;

freeRSAKeys(RSAKeySet)
RSAKeySet *RSAKeySet;

freeRSASig(RSASig)
RSASignature *RSASig;

void RSAPrivateKeyDesEncrypt(rsakey, deskey)
RSAPrivateKey *rsakey;
unsigned char deskey[8];

void RSAPrivateKeyDesDecrypt(rsakey, deskey)
RSAPrivateKey *rsakey;
unsigned char deskey[8];

DESCRIPTION

For all of these functions $BigInt$ arguments are assumed to be initialized $BigInts$. $bigInit(0)$ should be used for initialization of empty $BigInts$. If more space is needed than is provided the functions themselves take care of the space allocation.

These functions assume the general RSA cryptosystem in which a public exponent $e$, a private exponent $d$, and a modulus $n$ are needed to do encryption and decryption. For message $m$, encryption is done by calculating $E(m) = m sup size +2 e mod~n$ and decryption by calculating $D(E(m)) = m = E(m) sup size +2 d mod~ n$. Decryption may be sped up using the Chinese Remainder Theorem if the factorization of $n$ is known.

$randBytesNeededForRSA$ returns the number of bytes needed for a non-NULL $randomStart$ in the key generation routine following.

$genRSAKeySet$ takes as input the length needed for the modulus and the length (in bits) needed for the public exponent and generates $n$, $e$ and $d$. It also generates the necessary pieces for Chinese Remainder Theorem modular exponentiation. These pieces are included as part of the private key. The structure which $genRSAKeySet$ returns contains both the public and private keys. These can be retrieved by using $getRSAPublicKey$ and $getRSAPrivateKey$ with the key set as argument. If $randomStart$ is NULL, the default, pseudo-random number generator (desRandom()) is used. If it is not NULL, fill it with the appropriate number of bytes retrieved using $randBytesNeededForRSA$ using the RNG of your choice.

$RSAEncrypt$ does the modular exponentiation $m sup size +2 e mod~ n$. and returns the $BigInt$ result.

$RSADecrypt$ uses the private key and the Chinese Remainder Theorem to do the same calculation much more quickly. The quantized version use STD_QUANTUM milliseconds as the quantum for execution to defend against Kocher-style timing attacks. (The same is true of quantized_RSASign). STD_QUANTUM is defined in libcrypt.h and should be tuned to your environment.

$RSASign$ computes an RSA signature using an RSA private key (actually just an RSA Decryption).

$RSAVerify$ verifies that an RSA signature was indeed generated using the given message (actually an RSA encryption of the signature using an RSA public key is compared to the message).

$freeRSAKeySet$ frees the key set structure and all of its associated BigInts.

$freeRSASig$ frees the RSA signature (actually just a BigInt).

$RSAPrivateKeyDes[En/De]crypt$ should be used to use DES to [en/de]crypt an RSA private key. $f[put/get]RSAPrivateKey$ can then be used to store/retrieve the private key.

SEE ALSO
bigInit(3BM), bigTest(3BM), bigBits(3BM), bigToBuf(3BM), bufToBig(3BM), fBigPrint(3BM), atobig(3BM), bigPow(3BM), randomBytes(3BM), fputRSAPrivateKey(3BM), start_quantize(3BM), end_quantize(3BM)