source: trunk/third/ssh/rsa.h @ 12646

Revision 12646, 3.2 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12645, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2
3rsa.h
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8                   All rights reserved
9
10Created: Fri Mar  3 22:01:06 1995 ylo
11
12RSA key generation, encryption and decryption.
13
14*/
15
16/*
17 * $Id: rsa.h,v 1.1.1.2 1999-03-08 17:43:40 danw Exp $
18 * $Log: not supported by cvs2svn $
19 * Revision 1.3  1997/03/26  07:11:51  kivinen
20 *      Fixed prototypes.
21 *
22 * Revision 1.2  1996/02/19 16:09:38  huima
23 *      Comments fixed.
24 *
25 * Revision 1.1.1.1  1996/02/18  21:38:10  ylo
26 *      Imported ssh-1.2.13.
27 *
28 * Revision 1.3  1995/07/13  01:33:11  ylo
29 *      Fixed comments and label used to protect again multiple inclusion.
30 *
31 * Revision 1.2  1995/07/13  01:31:43  ylo
32 *      Removed "Last modified" header.
33 *      Added cvs log.
34 *
35 * $Endlog$
36 */
37
38#ifndef RSA_H
39#define RSA_H
40
41#include "gmp.h"
42#include "randoms.h"
43
44typedef struct
45{
46  unsigned int bits;            /* Modulus size in bits. */
47  MP_INT e;                     /* Public exponent. */
48  MP_INT n;                     /* Modulus. */
49} RSAPublicKey;
50
51typedef struct
52{
53  unsigned int bits;            /* Modulus size in bits. */
54  MP_INT n;                     /* Modulus. */
55  MP_INT e;                     /* Public exponent. */
56  MP_INT d;                     /* Private exponent. */
57  MP_INT u;                     /* Multiplicative inverse of p mod q. */
58  MP_INT p;                     /* Prime number p. */
59  MP_INT q;                     /* Prime number q. */
60} RSAPrivateKey;
61
62/* Generates a random integer of the desired number of bits. */
63void rsa_random_integer(MP_INT *ret, RandomState *state, unsigned int bits);
64
65/* Makes and returns a random prime of the desired number of bits.
66   Note that the random number generator must be initialized properly
67   before using this.
68
69   The generated prime will have the highest bit set, and will have
70   the two lowest bits set. */
71void rsa_random_prime(MP_INT *ret, RandomState *state, unsigned int bits);
72
73/* Generates RSA public and private keys.  This initializes the data
74   structures; they should be freed with rsa_clear_private_key and
75   rsa_clear_public_key. */
76void rsa_generate_key(RSAPrivateKey *prv, RSAPublicKey *pub,
77                      RandomState *state, unsigned int bits);
78
79/* Frees any memory associated with the private key. */
80void rsa_clear_private_key(RSAPrivateKey *prv);
81
82/* Frees any memory associated with the public key. */
83void rsa_clear_public_key(RSAPublicKey *pub);
84
85/* Performs a private-key RSA operation (encrypt/decrypt). */
86void rsa_private(MP_INT *output, MP_INT *input, RSAPrivateKey *prv);
87
88/* Performs a public-key RSA operation (encrypt/decrypt). */
89void rsa_public(MP_INT *output, MP_INT *input, RSAPublicKey *pub);
90
91/* Sets MP_INT memory allocation routines to ones that clear any memory
92   when freed. */
93void rsa_set_mp_memory_allocation(void);
94
95/* Indicates whether the rsa module is permitted to show messages on
96   the terminal. */
97void rsa_set_verbose(int verbose);
98
99/************* Kludge functions for RSAREF compatibility *******************/
100
101/* These functions are a kludge but can be implemented using rsaref. */
102
103/* It is not assumed that output != input. */
104
105/* Encrypt input using the public key.  Input should be a 256 bit value. */
106void rsa_public_encrypt(MP_INT *output, MP_INT *input, RSAPublicKey *key,
107                        RandomState *state);
108
109/* Performs a private key decrypt operation. */
110void rsa_private_decrypt(MP_INT *output, MP_INT *input, RSAPrivateKey *key);
111
112#endif /* RSA_H */
Note: See TracBrowser for help on using the repository browser.