Mercurial > dropbear
comparison mycrypt_pk.h @ 15:6362d3854bb4 libtomcrypt-orig
0.96 release of LibTomCrypt
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 15 Jun 2004 14:07:21 +0000 |
parents | 7faae8f46238 |
children | 5d99163f7e32 |
comparison
equal
deleted
inserted
replaced
3:7faae8f46238 | 15:6362d3854bb4 |
---|---|
1 /* ---- NUMBER THEORY ---- */ | 1 /* ---- NUMBER THEORY ---- */ |
2 #ifdef MPI | 2 #ifdef MPI |
3 | 3 |
4 #include "tommath.h" | 4 #include "ltc_tommath.h" |
5 | 5 |
6 /* in/out macros */ | 6 /* in/out macros */ |
7 #define OUTPUT_BIGNUM(num, out, y, z) \ | 7 #define OUTPUT_BIGNUM(num, out, y, z) \ |
8 { \ | 8 { \ |
9 if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; } \ | 9 if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; } \ |
84 /* Min and Max RSA key sizes (in bits) */ | 84 /* Min and Max RSA key sizes (in bits) */ |
85 #define MIN_RSA_SIZE 1024 | 85 #define MIN_RSA_SIZE 1024 |
86 #define MAX_RSA_SIZE 4096 | 86 #define MAX_RSA_SIZE 4096 |
87 | 87 |
88 /* Stack required for temps (plus padding) */ | 88 /* Stack required for temps (plus padding) */ |
89 #define RSA_STACK (8 + (MAX_RSA_SIZE/8)) | 89 // #define RSA_STACK (8 + (MAX_RSA_SIZE/8)) |
90 | 90 |
91 typedef struct Rsa_key { | 91 typedef struct Rsa_key { |
92 int type; | 92 int type; |
93 mp_int e, d, N, qP, pQ, dP, dQ, p, q; | 93 mp_int e, d, N, qP, pQ, dP, dQ, p, q; |
94 } rsa_key; | 94 } rsa_key; |
95 | 95 |
96 extern int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key); | 96 extern int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key); |
97 | 97 |
98 extern int rsa_exptmod(const unsigned char *in, unsigned long inlen, | 98 extern int rsa_exptmod(const unsigned char *in, unsigned long inlen, |
99 unsigned char *out, unsigned long *outlen, int which, | 99 unsigned char *out, unsigned long *outlen, int which, |
100 rsa_key *key); | 100 prng_state *prng, int prng_idx, |
101 | 101 rsa_key *key); |
102 extern int rsa_pad(const unsigned char *in, unsigned long inlen, | 102 |
103 unsigned char *out, unsigned long *outlen, | 103 #ifdef RSA_TIMING |
104 int wprng, prng_state *prng); | 104 |
105 | 105 extern int tim_exptmod(prng_state *prng, int prng_idx, |
106 extern int rsa_signpad(const unsigned char *in, unsigned long inlen, | 106 mp_int *c, mp_int *e, mp_int *d, mp_int *n, mp_int *m); |
107 unsigned char *out, unsigned long *outlen); | 107 |
108 | 108 #else |
109 extern int rsa_depad(const unsigned char *in, unsigned long inlen, | 109 |
110 unsigned char *out, unsigned long *outlen); | 110 #define tim_exptmod(prng, prng_idx, c, e, d, n, m) mpi_to_ltc_error(mp_exptmod(c, d, n, m)) |
111 | 111 |
112 extern int rsa_signdepad(const unsigned char *in, unsigned long inlen, | 112 #endif |
113 unsigned char *out, unsigned long *outlen); | |
114 | |
115 | 113 |
116 extern void rsa_free(rsa_key *key); | 114 extern void rsa_free(rsa_key *key); |
117 | 115 |
118 extern int rsa_encrypt_key(const unsigned char *inkey, unsigned long inlen, | 116 int rsa_encrypt_key(const unsigned char *inkey, unsigned long inlen, |
119 unsigned char *outkey, unsigned long *outlen, | 117 unsigned char *outkey, unsigned long *outlen, |
120 prng_state *prng, int wprng, rsa_key *key); | 118 const unsigned char *lparam, unsigned long lparamlen, |
121 | 119 prng_state *prng, int prng_idx, int hash_idx, rsa_key *key); |
122 extern int rsa_decrypt_key(const unsigned char *in, unsigned long inlen, | 120 |
123 unsigned char *outkey, unsigned long *keylen, | 121 int rsa_decrypt_key(const unsigned char *in, unsigned long inlen, |
124 rsa_key *key); | 122 unsigned char *outkey, unsigned long *keylen, |
125 | 123 const unsigned char *lparam, unsigned long lparamlen, |
126 extern int rsa_sign_hash(const unsigned char *in, unsigned long inlen, | 124 prng_state *prng, int prng_idx, |
127 unsigned char *out, unsigned long *outlen, | 125 int hash_idx, int *res, |
128 rsa_key *key); | 126 rsa_key *key); |
129 | 127 |
130 extern int rsa_verify_hash(const unsigned char *sig, unsigned long siglen, | 128 int rsa_sign_hash(const unsigned char *msghash, unsigned long msghashlen, |
131 const unsigned char *hash, int *stat, rsa_key *key); | 129 unsigned char *sig, unsigned long *siglen, |
132 | 130 prng_state *prng, int prng_idx, |
133 extern int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); | 131 int hash_idx, unsigned long saltlen, |
134 extern int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); | 132 rsa_key *key); |
133 | |
134 int rsa_verify_hash(const unsigned char *sig, unsigned long siglen, | |
135 const unsigned char *msghash, unsigned long msghashlen, | |
136 prng_state *prng, int prng_idx, | |
137 int hash_idx, unsigned long saltlen, | |
138 int *stat, rsa_key *key); | |
139 | |
140 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key); | |
141 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key); | |
142 | |
135 #endif | 143 #endif |
136 | 144 |
137 /* ---- DH Routines ---- */ | 145 /* ---- DH Routines ---- */ |
138 #ifdef MDH | 146 #ifdef MDH |
139 | 147 |