Initial RSA support.
[u/mdw/catacomb] / rsa.h
diff --git a/rsa.h b/rsa.h
new file mode 100644 (file)
index 0000000..aa6e44b
--- /dev/null
+++ b/rsa.h
@@ -0,0 +1,123 @@
+/* -*-c-*-
+ *
+ * $Id: rsa.h,v 1.1 1999/12/22 15:50:45 mdw Exp $
+ *
+ * The RSA public-key cryptosystem
+ *
+ * (c) 1999 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * Catacomb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: rsa.h,v $
+ * Revision 1.1  1999/12/22 15:50:45  mdw
+ * Initial RSA support.
+ *
+ */
+
+#ifndef CATACOMB_RSA_H
+#define CATACOMB_RSA_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#ifndef CATACOMB_GRAND_H
+#  include "grand.h"
+#endif
+
+#ifndef CATACOMB_MP_H
+#  include "mp.h"
+#endif
+
+#ifndef CATACOMB_PGEN_H
+#  include "pgen.h"
+#endif
+
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct rsa_param {
+  mp *p, *q;
+  mp *n;
+  mp *q_inv;
+  mp *e, *d, *dp, *dq;
+} rsa_param;
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @rsa_gen@ --- *
+ *
+ * Arguments:  @rsa_param *rp@ = pointer to block to be filled in
+ *             @unsigned nbits@ = required modulus size in bits
+ *             @grand *r@ = random number source
+ *             @unsigned n@ = number of attempts to make
+ *             @pgen_proc *event@ = event handler function
+ *             @void *ectx@ = argument for the event handler
+ *
+ * Returns:    Zero if all went well, nonzero otherwise.
+ *
+ * Use:                Constructs a pair of strong RSA primes and other useful RSA
+ *             parameters.  A small encryption exponent is chosen if
+ *             possible.
+ */
+
+extern int rsa_gen(rsa_param */*rp*/, unsigned /*nbits*/,
+                  grand */*r*/, unsigned /*n*/,
+                  pgen_proc */*event*/, void */*ectx*/);
+
+/* --- @rsa_decrypt@ --- *
+ *
+ * Arguments:  @rsa_param *rp@ = pointer to RSA parameters
+ *             @mp *d@ = destination
+ *             @mp *c@ = ciphertext message
+ *             @grand *r@ = pointer to random number source for blinding
+ *
+ * Returns:    Correctly decrypted message.
+ *
+ * Use:                Performs RSA decryption, very carefully.
+ */
+
+extern mp *rsa_decrypt(rsa_param */*rp*/, mp */*d*/, mp */*c*/,
+                      grand */*r*/);
+
+/* --- @rsa_recover@ --- *
+ *
+ * Arguments:  @rsa_param *rp@ = pointer to parameter block
+ *
+ * Returns:    Zero if all went well, nonzero if the parameters make no
+ *             sense.
+ *
+ * Use:                Derives the full set of RSA parameters given a minimal set.
+ */
+
+extern int rsa_recover(rsa_param */*rp*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif