Mercurial > dropbear
annotate rsa.c @ 16:09ab3354aa21 libtomcrypt
propagate of e8bea23df30f9f46c647d06db3b223427b4e3604 and b0b6b4a8843b94d9f049cb5ffe0b1ae91ec1bf8b from branch 'au.asn.ucc.matt.ltc-orig' to 'au.asn.ucc.matt.ltc-db'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 15 Jun 2004 14:27:14 +0000 |
parents | d7da3b1e1540 |
children |
rev | line source |
---|---|
0
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * LibTomCrypt is a library that provides various cryptographic |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * algorithms in a highly modular and flexible manner. |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * The library is free for all purposes without any express |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * guarantee it works. |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 /* RSA Code by Tom St Denis */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 #include "mycrypt.h" |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 #ifdef MRSA |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 int rsa_signpad(const unsigned char *in, unsigned long inlen, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 unsigned char *out, unsigned long *outlen) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 unsigned long x, y; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 _ARGCHK(in != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 _ARGCHK(out != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 _ARGCHK(outlen != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 if (*outlen < (3 * inlen)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 return CRYPT_BUFFER_OVERFLOW; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 /* check inlen */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 if (inlen > MAX_RSA_SIZE/8) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 return CRYPT_PK_INVALID_SIZE; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 for (y = x = 0; x < inlen; x++) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 out[y++] = (unsigned char)0xFF; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 for (x = 0; x < inlen; x++) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 out[y++] = in[x]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 for (x = 0; x < inlen; x++) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 out[y++] = (unsigned char)0xFF; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 *outlen = 3 * inlen; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 int rsa_pad(const unsigned char *in, unsigned long inlen, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 unsigned char *out, unsigned long *outlen, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 int wprng, prng_state *prng) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 unsigned char buf[3*(MAX_RSA_SIZE/8)]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 unsigned long x; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 int err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 _ARGCHK(in != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 _ARGCHK(out != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 _ARGCHK(outlen != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 /* is output big enough? */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 if (*outlen < (3 * inlen)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 return CRYPT_BUFFER_OVERFLOW; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 /* get random padding required */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 if ((err = prng_is_valid(wprng)) != CRYPT_OK) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 return err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 /* check inlen */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 if (inlen > (MAX_RSA_SIZE/8)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 return CRYPT_PK_INVALID_SIZE; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 if (prng_descriptor[wprng].read(buf, inlen*2-2, prng) != (inlen*2 - 2)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 return CRYPT_ERROR_READPRNG; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 /* pad it like a sandwhich |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 * Looks like 0xFF R1 M R2 0xFF |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 * |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 * Where R1/R2 are random and exactly equal to the length of M minus one byte. |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 for (x = 0; x < inlen-1; x++) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 out[x+1] = buf[x]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 for (x = 0; x < inlen; x++) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 out[x+inlen] = in[x]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 for (x = 0; x < inlen-1; x++) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 out[x+inlen+inlen] = buf[x+inlen-1]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 /* last and first bytes are 0xFF */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 out[0] = out[inlen+inlen+inlen-1] = (unsigned char)0xFF; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 /* clear up and return */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 #ifdef CLEAN_STACK |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 zeromem(buf, sizeof(buf)); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 #endif |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 *outlen = inlen*3; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 int rsa_signdepad(const unsigned char *in, unsigned long inlen, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 unsigned char *out, unsigned long *outlen) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 unsigned long x; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 _ARGCHK(in != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 _ARGCHK(out != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 _ARGCHK(outlen != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 if (*outlen < inlen/3) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 return CRYPT_BUFFER_OVERFLOW; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 /* check padding bytes */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 for (x = 0; x < inlen/3; x++) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 if (in[x] != (unsigned char)0xFF || in[x+(inlen/3)+(inlen/3)] != (unsigned char)0xFF) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 return CRYPT_INVALID_PACKET; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 for (x = 0; x < inlen/3; x++) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 out[x] = in[x+(inlen/3)]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 *outlen = inlen/3; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 int rsa_depad(const unsigned char *in, unsigned long inlen, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 unsigned char *out, unsigned long *outlen) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 unsigned long x; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 _ARGCHK(in != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 _ARGCHK(out != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 _ARGCHK(outlen != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 if (*outlen < inlen/3) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 return CRYPT_BUFFER_OVERFLOW; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 for (x = 0; x < inlen/3; x++) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 out[x] = in[x+(inlen/3)]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 *outlen = inlen/3; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 unsigned long y, z; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 int err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 _ARGCHK(out != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 _ARGCHK(outlen != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 _ARGCHK(key != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 /* can we store the static header? */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 if (*outlen < (PACKET_SIZE + 1)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 return CRYPT_BUFFER_OVERFLOW; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 /* type valid? */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 if (!(key->type == PK_PRIVATE || key->type == PK_PRIVATE_OPTIMIZED) && |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 (type == PK_PRIVATE || type == PK_PRIVATE_OPTIMIZED)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
167 return CRYPT_PK_INVALID_TYPE; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
168 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 /* start at offset y=PACKET_SIZE */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 y = PACKET_SIZE; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
173 /* output key type */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
174 out[y++] = type; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
175 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 /* output modulus */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
177 OUTPUT_BIGNUM(&key->N, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 /* output public key */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
180 OUTPUT_BIGNUM(&key->e, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
181 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 if (type == PK_PRIVATE || type == PK_PRIVATE_OPTIMIZED) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 OUTPUT_BIGNUM(&key->d, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
185 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 if (type == PK_PRIVATE_OPTIMIZED) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
187 OUTPUT_BIGNUM(&key->dQ, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
188 OUTPUT_BIGNUM(&key->dP, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
189 OUTPUT_BIGNUM(&key->pQ, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
190 OUTPUT_BIGNUM(&key->qP, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 OUTPUT_BIGNUM(&key->p, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
192 OUTPUT_BIGNUM(&key->q, out, y, z); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
194 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 /* store packet header */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 packet_store_header(out, PACKET_SECT_RSA, PACKET_SUB_KEY); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
198 /* copy to the user buffer */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
199 *outlen = y; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
201 /* clear stack and return */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
202 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
203 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key) |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
206 { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
207 unsigned long x, y; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
208 int err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
209 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 _ARGCHK(in != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
211 _ARGCHK(key != NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
213 /* check length */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
214 if (inlen < (1+PACKET_SIZE)) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
215 return CRYPT_INVALID_PACKET; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
216 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
217 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
218 /* test packet header */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
219 if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_RSA, PACKET_SUB_KEY)) != CRYPT_OK) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 return err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 /* init key */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 if ((err = mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP, &key->qP, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 &key->pQ, &key->p, &key->q, NULL)) != MP_OKAY) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 return mpi_to_ltc_error(err); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
229 /* get key type */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
230 y = PACKET_SIZE; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 key->type = (int)in[y++]; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
232 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 /* load the modulus */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 INPUT_BIGNUM(&key->N, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
235 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
236 /* load public exponent */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 INPUT_BIGNUM(&key->e, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 /* get private exponent */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
240 if (key->type == PK_PRIVATE || key->type == PK_PRIVATE_OPTIMIZED) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
241 INPUT_BIGNUM(&key->d, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
242 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
244 /* get CRT private data if required */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
245 if (key->type == PK_PRIVATE_OPTIMIZED) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
246 INPUT_BIGNUM(&key->dQ, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
247 INPUT_BIGNUM(&key->dP, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
248 INPUT_BIGNUM(&key->pQ, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
249 INPUT_BIGNUM(&key->qP, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
250 INPUT_BIGNUM(&key->p, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
251 INPUT_BIGNUM(&key->q, in, x, y, inlen); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
252 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
253 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 /* free up ram not required */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
255 if (key->type != PK_PRIVATE_OPTIMIZED) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
256 mp_clear_multi(&key->dQ, &key->dP, &key->pQ, &key->qP, &key->p, &key->q, NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
258 if (key->type != PK_PRIVATE && key->type != PK_PRIVATE_OPTIMIZED) { |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
259 mp_clear(&key->d); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
261 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
262 return CRYPT_OK; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
263 error: |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 mp_clear_multi(&key->d, &key->e, &key->N, &key->dQ, &key->dP, |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
265 &key->pQ, &key->qP, &key->p, &key->q, NULL); |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
266 return err; |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
267 } |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
268 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
269 #include "rsa_sys.c" |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
270 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
271 #endif /* RSA */ |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
272 |
d7da3b1e1540
put back the 0.95 makefile which was inadvertently merged over
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
273 |