/* -*-c-*-
*
- * $Id: rsa.h,v 1.1 1999/12/22 15:50:45 mdw Exp $
+ * $Id: rsa.h,v 1.2 2000/06/17 12:07:36 mdw Exp $
*
* The RSA public-key cryptosystem
*
/*----- Revision history --------------------------------------------------*
*
* $Log: rsa.h,v $
+ * Revision 1.2 2000/06/17 12:07:36 mdw
+ * Add key fetching interface. Add new rsa_decrypt interface.
+ *
* Revision 1.1 1999/12/22 15:50:45 mdw
* Initial RSA support.
*
# include "grand.h"
#endif
+#ifndef CATACOMB_KEY_H
+# include "key.h"
+#endif
+
#ifndef CATACOMB_MP_H
# include "mp.h"
#endif
/*----- Data structures ---------------------------------------------------*/
-typedef struct rsa_param {
- mp *p, *q;
+typedef struct rsa_pub {
mp *n;
- mp *q_inv;
+ mp *e;
+} rsa_pub;
+
+typedef struct rsa_param {
+ mp *n, *p, *q, *q_inv;
mp *e, *d, *dp, *dq;
-} rsa_param;
+} rsa_param, rsa_priv;
+
+typedef struct rsa_decctx {
+ rsa_param *rp;
+ grand *r;
+ mpmont nm, pm, qm;
+} rsa_decctx;
+
+/*----- Key fetching ------------------------------------------------------*/
+
+extern const key_fetchdef rsa_pubfetch[];
+#define RSA_PUBFETCHSZ 4
+
+extern const key_fetchdef rsa_privfetch[];
+#define RSA_PRIVFETCHSZ 12
/*----- Functions provided ------------------------------------------------*/
grand */*r*/, unsigned /*n*/,
pgen_proc */*event*/, void */*ectx*/);
+/* --- @rsa_deccreate@ --- *
+ *
+ * Arguments: @rsa_decctx *rd@ = pointer to an RSA decryption context
+ * @rsa_priv *rp@ = pointer to RSA private key
+ * @grand *r@ = pointer to random number source for blinding
+ *
+ * Returns: ---
+ *
+ * Use: Initializes an RSA decryption context. Keeping a context
+ * for several decryption or signing operations provides a minor
+ * performance benefit.
+ *
+ * The random number source may be null if blinding is not
+ * desired. This improves decryption speed, at the risk of
+ * permitting timing attacks.
+ */
+
+extern void rsa_deccreate(rsa_decctx */*rd*/, rsa_param */*rp*/,
+ grand */*r*/);
+
+/* --- @rsa_decdestroy@ --- *
+ *
+ * Arguments: @rsa_decctx *rd@ = pointer to an RSA decryption context
+ *
+ * Returns: ---
+ *
+ * Use: Destroys an RSA decryption context.
+ */
+
+extern void rsa_decdestroy(rsa_decctx */*rd*/);
+
+/* --- @rsa_dec@ --- *
+ *
+ * Arguments: @rsa_decctx *rd@ = pointer to RSA decryption context
+ * @mp *d@ = destination
+ * @mp *c@ = ciphertext message
+ *
+ * Returns: The recovered plaintext message.
+ *
+ * Use: Performs RSA decryption. This function takes advantage of
+ * knowledge of the key factors in order to speed up
+ * decryption. It also blinds the ciphertext prior to
+ * decryption and unblinds it afterwards to thwart timing
+ * attacks.
+ */
+
+extern mp *rsa_dec(rsa_decctx */*rd*/, mp */*d*/, mp */*c*/);
+
/* --- @rsa_decrypt@ --- *
*
* Arguments: @rsa_param *rp@ = pointer to RSA parameters