Add key fetching interface. Add new rsa_decrypt interface.
authormdw <mdw>
Sat, 17 Jun 2000 12:07:36 +0000 (12:07 +0000)
committermdw <mdw>
Sat, 17 Jun 2000 12:07:36 +0000 (12:07 +0000)
rsa.h

diff --git a/rsa.h b/rsa.h
index aa6e44b..0aabdd2 100644 (file)
--- a/rsa.h
+++ b/rsa.h
@@ -1,6 +1,6 @@
 /* -*-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
  *
@@ -30,6 +30,9 @@
 /*----- 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 ------------------------------------------------*/
 
@@ -87,6 +111,54 @@ extern int rsa_gen(rsa_param */*rp*/, unsigned /*nbits*/,
                   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