fixed a bunch of compiler warnings, pgp end certificate listing
[strongswan.git] / src / pluto / pkcs1.c
1 /* Support of PKCS#1 private key data structures
2 * Copyright (C) 2005 Jan Hutter, Martin Willi
3 * Copyright (C) 2002-2005 Andreas Steffen
4 * Hochschule fuer Technik Rapperswil, Switzerland
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * RCSID $Id$
17 */
18
19 #include <stddef.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <freeswan.h>
24 #include <libsha2/sha2.h>
25
26 #include <asn1/asn1.h>
27 #include <asn1/asn1_parser.h>
28 #include <asn1/oid.h>
29
30 #include "constants.h"
31 #include "defs.h"
32 #include "mp_defs.h"
33 #include "log.h"
34 #include "pkcs1.h"
35 #include "md2.h"
36 #include "md5.h"
37 #include "sha1.h"
38 #include "rnd.h"
39
40 const struct fld RSA_private_field[] =
41 {
42 { "Modulus", offsetof(RSA_private_key_t, pub.n) },
43 { "PublicExponent", offsetof(RSA_private_key_t, pub.e) },
44
45 { "PrivateExponent", offsetof(RSA_private_key_t, d) },
46 { "Prime1", offsetof(RSA_private_key_t, p) },
47 { "Prime2", offsetof(RSA_private_key_t, q) },
48 { "Exponent1", offsetof(RSA_private_key_t, dP) },
49 { "Exponent2", offsetof(RSA_private_key_t, dQ) },
50 { "Coefficient", offsetof(RSA_private_key_t, qInv) },
51 };
52
53 /**
54 * ASN.1 definition of a PKCS#1 RSA private key
55 */
56 static const asn1Object_t privkeyObjects[] = {
57 { 0, "RSAPrivateKey", ASN1_SEQUENCE, ASN1_NONE }, /* 0 */
58 { 1, "version", ASN1_INTEGER, ASN1_BODY }, /* 1 */
59 { 1, "modulus", ASN1_INTEGER, ASN1_BODY }, /* 2 */
60 { 1, "publicExponent", ASN1_INTEGER, ASN1_BODY }, /* 3 */
61 { 1, "privateExponent", ASN1_INTEGER, ASN1_BODY }, /* 4 */
62 { 1, "prime1", ASN1_INTEGER, ASN1_BODY }, /* 5 */
63 { 1, "prime2", ASN1_INTEGER, ASN1_BODY }, /* 6 */
64 { 1, "exponent1", ASN1_INTEGER, ASN1_BODY }, /* 7 */
65 { 1, "exponent2", ASN1_INTEGER, ASN1_BODY }, /* 8 */
66 { 1, "coefficient", ASN1_INTEGER, ASN1_BODY }, /* 9 */
67 { 1, "otherPrimeInfos", ASN1_SEQUENCE, ASN1_OPT |
68 ASN1_LOOP }, /* 10 */
69 { 2, "otherPrimeInfo", ASN1_SEQUENCE, ASN1_NONE }, /* 11 */
70 { 3, "prime", ASN1_INTEGER, ASN1_BODY }, /* 12 */
71 { 3, "exponent", ASN1_INTEGER, ASN1_BODY }, /* 13 */
72 { 3, "coefficient", ASN1_INTEGER, ASN1_BODY }, /* 14 */
73 { 1, "end opt or loop", ASN1_EOC, ASN1_END }, /* 15 */
74 { 0, "exit", ASN1_EOC, ASN1_EXIT }
75 };
76 #define PKCS1_PRIV_KEY_VERSION 1
77 #define PKCS1_PRIV_KEY_MODULUS 2
78 #define PKCS1_PRIV_KEY_PUB_EXP 3
79 #define PKCS1_PRIV_KEY_COEFF 9
80
81 /**
82 * Forms the FreeS/WAN keyid from the public exponent e and modulus n
83 */
84 void form_keyid(chunk_t e, chunk_t n, char* keyid, unsigned *keysize)
85 {
86 /* eliminate leading zero bytes in modulus from ASN.1 coding */
87 while (n.len > 1 && *n.ptr == 0x00)
88 {
89 n.ptr++; n.len--;
90 }
91
92 /* form the FreeS/WAN keyid */
93 keyid[0] = '\0'; /* in case of splitkeytoid failure */
94 splitkeytoid(e.ptr, e.len, n.ptr, n.len, keyid, KEYID_BUF);
95
96 /* return the RSA modulus size in octets */
97 *keysize = n.len;
98 }
99
100 /**
101 * Initialize an RSA_public_key_t object
102 */
103 void init_RSA_public_key(RSA_public_key_t *rsa, chunk_t e, chunk_t n)
104 {
105 n_to_mpz(&rsa->e, e.ptr, e.len);
106 n_to_mpz(&rsa->n, n.ptr, n.len);
107
108 form_keyid(e, n, rsa->keyid, &rsa->k);
109 }
110
111 #ifdef DEBUG
112 static void RSA_show_key_fields(RSA_private_key_t *k, int fieldcnt)
113 {
114 const struct fld *p;
115
116 DBG_log(" keyid: *%s", k->pub.keyid);
117
118 for (p = RSA_private_field; p < &RSA_private_field[fieldcnt]; p++)
119 {
120 MP_INT *n = (MP_INT *) ((char *)k + p->offset);
121 size_t sz = mpz_sizeinbase(n, 16);
122 char buf[RSA_MAX_OCTETS * 2 + 2]; /* ought to be big enough */
123
124 passert(sz <= sizeof(buf));
125 mpz_get_str(buf, 16, n);
126
127 DBG_log(" %s: 0x%s", p->name, buf);
128 }
129 }
130
131 /**
132 * debugging info that compromises security!
133 */
134 void RSA_show_private_key(RSA_private_key_t *k)
135 {
136 RSA_show_key_fields(k, countof(RSA_private_field));
137 }
138
139 void RSA_show_public_key(RSA_public_key_t *k)
140 {
141 /* Kludge: pretend that it is a private key, but only display the
142 * first two fields (which are the public key).
143 */
144 passert(offsetof(RSA_private_key_t, pub) == 0);
145 RSA_show_key_fields((RSA_private_key_t *)k, 2);
146 }
147 #endif
148
149 err_t RSA_private_key_sanity(RSA_private_key_t *k)
150 {
151 /* note that the *last* error found is reported */
152 err_t ugh = NULL;
153 mpz_t t, u, q1;
154
155 #ifdef DEBUG /* debugging info that compromises security */
156 DBG(DBG_PRIVATE, RSA_show_private_key(k));
157 #endif
158
159 /* PKCS#1 1.5 section 6 requires modulus to have at least 12 octets.
160 * We actually require more (for security).
161 */
162 if (k->pub.k < RSA_MIN_OCTETS)
163 return RSA_MIN_OCTETS_UGH;
164
165 /* we picked a max modulus size to simplify buffer allocation */
166 if (k->pub.k > RSA_MAX_OCTETS)
167 return RSA_MAX_OCTETS_UGH;
168
169 mpz_init(t);
170 mpz_init(u);
171 mpz_init(q1);
172
173 /* check that n == p * q */
174 mpz_mul(u, &k->p, &k->q);
175 if (mpz_cmp(u, &k->pub.n) != 0)
176 ugh = "n != p * q";
177
178 /* check that e divides neither p-1 nor q-1 */
179 mpz_sub_ui(t, &k->p, 1);
180 mpz_mod(t, t, &k->pub.e);
181 if (mpz_cmp_ui(t, 0) == 0)
182 ugh = "e divides p-1";
183
184 mpz_sub_ui(t, &k->q, 1);
185 mpz_mod(t, t, &k->pub.e);
186 if (mpz_cmp_ui(t, 0) == 0)
187 ugh = "e divides q-1";
188
189 /* check that d is e^-1 (mod lcm(p-1, q-1)) */
190 /* see PKCS#1v2, aka RFC 2437, for the "lcm" */
191 mpz_sub_ui(q1, &k->q, 1);
192 mpz_sub_ui(u, &k->p, 1);
193 mpz_gcd(t, u, q1); /* t := gcd(p-1, q-1) */
194 mpz_mul(u, u, q1); /* u := (p-1) * (q-1) */
195 mpz_divexact(u, u, t); /* u := lcm(p-1, q-1) */
196
197 mpz_mul(t, &k->d, &k->pub.e);
198 mpz_mod(t, t, u);
199 if (mpz_cmp_ui(t, 1) != 0)
200 ugh = "(d * e) mod (lcm(p-1, q-1)) != 1";
201
202 /* check that dP is d mod (p-1) */
203 mpz_sub_ui(u, &k->p, 1);
204 mpz_mod(t, &k->d, u);
205 if (mpz_cmp(t, &k->dP) != 0)
206 ugh = "dP is not congruent to d mod (p-1)";
207
208 /* check that dQ is d mod (q-1) */
209 mpz_sub_ui(u, &k->q, 1);
210 mpz_mod(t, &k->d, u);
211 if (mpz_cmp(t, &k->dQ) != 0)
212 ugh = "dQ is not congruent to d mod (q-1)";
213
214 /* check that qInv is (q^-1) mod p */
215 mpz_mul(t, &k->qInv, &k->q);
216 mpz_mod(t, t, &k->p);
217 if (mpz_cmp_ui(t, 1) != 0)
218 ugh = "qInv is not conguent ot (q^-1) mod p";
219
220 mpz_clear(t);
221 mpz_clear(u);
222 mpz_clear(q1);
223 return ugh;
224 }
225
226 /**
227 * Check the equality of two RSA public keys
228 */
229 bool same_RSA_public_key(const RSA_public_key_t *a, const RSA_public_key_t *b)
230 {
231 return a == b
232 || (a->k == b->k && mpz_cmp(&a->n, &b->n) == 0 && mpz_cmp(&a->e, &b->e) == 0);
233 }
234
235 /**
236 * Parses a PKCS#1 private key
237 */
238 bool pkcs1_parse_private_key(chunk_t blob, RSA_private_key_t *key)
239 {
240 asn1_parser_t *parser;
241 chunk_t object, modulus, exp;
242 int objectID;
243 bool success = FALSE;
244
245 parser = asn1_parser_create(privkeyObjects, blob);
246 parser->set_flags(parser, FALSE, TRUE);
247
248 while (parser->iterate(parser, &objectID, &object))
249 {
250 if (objectID == PKCS1_PRIV_KEY_VERSION)
251 {
252 if (object.len > 0 && *object.ptr != 0)
253 {
254 plog(" wrong PKCS#1 private key version");
255 goto end;
256 }
257 }
258 else if (objectID >= PKCS1_PRIV_KEY_MODULUS &&
259 objectID <= PKCS1_PRIV_KEY_COEFF)
260 {
261 MP_INT *u = (MP_INT *) ((char *)key
262 + RSA_private_field[objectID - PKCS1_PRIV_KEY_MODULUS].offset);
263
264 n_to_mpz(u, object.ptr, object.len);
265
266 if (objectID == PKCS1_PRIV_KEY_MODULUS)
267 modulus = object;
268 else if (objectID == PKCS1_PRIV_KEY_PUB_EXP)
269 exp = object;
270 }
271 }
272 success = parser->success(parser);
273
274 end:
275 parser->destroy(parser);
276
277 if (success)
278 {
279 err_t ugh;
280
281 form_keyid(exp, modulus, key->pub.keyid, &key->pub.k);
282 ugh = RSA_private_key_sanity(key);
283 success = (ugh == NULL);
284 }
285 return success;
286 }
287
288 /**
289 * Compute a digest over a binary blob
290 */
291 bool compute_digest(chunk_t tbs, int alg, chunk_t *digest)
292 {
293 switch (alg)
294 {
295 case OID_MD2:
296 case OID_MD2_WITH_RSA:
297 {
298 MD2_CTX context;
299
300 MD2Init(&context);
301 MD2Update(&context, tbs.ptr, tbs.len);
302 MD2Final(digest->ptr, &context);
303 digest->len = MD2_DIGEST_SIZE;
304 return TRUE;
305 }
306 case OID_MD5:
307 case OID_MD5_WITH_RSA:
308 {
309 MD5_CTX context;
310
311 MD5Init(&context);
312 MD5Update(&context, tbs.ptr, tbs.len);
313 MD5Final(digest->ptr, &context);
314 digest->len = MD5_DIGEST_SIZE;
315 return TRUE;
316 }
317 case OID_SHA1:
318 case OID_SHA1_WITH_RSA:
319 case OID_SHA1_WITH_RSA_OIW:
320 {
321 SHA1_CTX context;
322
323 SHA1Init(&context);
324 SHA1Update(&context, tbs.ptr, tbs.len);
325 SHA1Final(digest->ptr, &context);
326 digest->len = SHA1_DIGEST_SIZE;
327 return TRUE;
328 }
329 case OID_SHA256:
330 case OID_SHA256_WITH_RSA:
331 {
332 sha256_context context;
333
334 sha256_init(&context);
335 sha256_write(&context, tbs.ptr, tbs.len);
336 sha256_final(&context);
337 memcpy(digest->ptr, context.sha_out, SHA2_256_DIGEST_SIZE);
338 digest->len = SHA2_256_DIGEST_SIZE;
339 return TRUE;
340 }
341 case OID_SHA384:
342 case OID_SHA384_WITH_RSA:
343 {
344 sha512_context context;
345
346 sha384_init(&context);
347 sha512_write(&context, tbs.ptr, tbs.len);
348 sha512_final(&context);
349 memcpy(digest->ptr, context.sha_out, SHA2_384_DIGEST_SIZE);
350 digest->len = SHA2_384_DIGEST_SIZE;
351 return TRUE;
352 }
353 case OID_SHA512:
354 case OID_SHA512_WITH_RSA:
355 {
356 sha512_context context;
357
358 sha512_init(&context);
359 sha512_write(&context, tbs.ptr, tbs.len);
360 sha512_final(&context);
361 memcpy(digest->ptr, context.sha_out, SHA2_512_DIGEST_SIZE);
362 digest->len = SHA2_512_DIGEST_SIZE;
363 return TRUE;
364 }
365 default:
366 digest->len = 0;
367 return FALSE;
368 }
369 }
370
371 /**
372 * Compute an RSA signature with PKCS#1 padding
373 */
374 void sign_hash(const RSA_private_key_t *k, const u_char *hash_val,
375 size_t hash_len, u_char *sig_val, size_t sig_len)
376 {
377 chunk_t ch;
378 mpz_t t1, t2;
379 size_t padlen;
380 u_char *p = sig_val;
381
382 DBG(DBG_CONTROL | DBG_CRYPT,
383 DBG_log("signing hash with RSA Key *%s", k->pub.keyid)
384 )
385 /* PKCS#1 v1.5 8.1 encryption-block formatting */
386 *p++ = 0x00;
387 *p++ = 0x01; /* BT (block type) 01 */
388 padlen = sig_len - 3 - hash_len;
389 memset(p, 0xFF, padlen);
390 p += padlen;
391 *p++ = 0x00;
392 memcpy(p, hash_val, hash_len);
393 passert(p + hash_len - sig_val == (ptrdiff_t)sig_len);
394
395 /* PKCS#1 v1.5 8.2 octet-string-to-integer conversion */
396 n_to_mpz(t1, sig_val, sig_len); /* (could skip leading 0x00) */
397
398 /* PKCS#1 v1.5 8.3 RSA computation y = x^c mod n
399 * Better described in PKCS#1 v2.0 5.1 RSADP.
400 * There are two methods, depending on the form of the private key.
401 * We use the one based on the Chinese Remainder Theorem.
402 */
403 mpz_init(t2);
404
405 mpz_powm(t2, t1, &k->dP, &k->p); /* m1 = c^dP mod p */
406
407 mpz_powm(t1, t1, &k->dQ, &k->q); /* m2 = c^dQ mod Q */
408
409 mpz_sub(t2, t2, t1); /* h = qInv (m1 - m2) mod p */
410 mpz_mod(t2, t2, &k->p);
411 mpz_mul(t2, t2, &k->qInv);
412 mpz_mod(t2, t2, &k->p);
413
414 mpz_mul(t2, t2, &k->q); /* m = m2 + h q */
415 mpz_add(t1, t1, t2);
416
417 /* PKCS#1 v1.5 8.4 integer-to-octet-string conversion */
418 ch = mpz_to_n(t1, sig_len);
419 memcpy(sig_val, ch.ptr, sig_len);
420 free(ch.ptr);
421
422 mpz_clear(t1);
423 mpz_clear(t2);
424 }
425
426 /**
427 * Encrypt data with an RSA public key after padding
428 */
429 chunk_t RSA_encrypt(const RSA_public_key_t *key, chunk_t in)
430 {
431 u_char padded[RSA_MAX_OCTETS];
432 u_char *pos = padded;
433 int padding = key->k - in.len - 3;
434 int i;
435
436 if (padding < 8 || key->k > RSA_MAX_OCTETS)
437 return chunk_empty;
438
439 /* add padding according to PKCS#1 7.2.1 1.+2. */
440 *pos++ = 0x00;
441 *pos++ = 0x02;
442
443 /* pad with pseudo random bytes unequal to zero */
444 for (i = 0; i < padding; i++)
445 {
446 get_rnd_bytes(pos, padding);
447 while (!*pos)
448 {
449 get_rnd_bytes(pos, 1);
450 }
451 pos++;
452 }
453
454 /* append the padding terminator */
455 *pos++ = 0x00;
456
457 /* now add the data */
458 memcpy(pos, in.ptr, in.len);
459 DBG(DBG_RAW,
460 DBG_dump_chunk("data for rsa encryption:\n", in);
461 DBG_dump("padded data for rsa encryption:\n", padded, key->k)
462 )
463
464 /* convert chunk to integer (PKCS#1 7.2.1 3.a) */
465 {
466 chunk_t out;
467 mpz_t m, c;
468
469 mpz_init(c);
470 n_to_mpz(m, padded, key->k);
471
472 /* encrypt(PKCS#1 7.2.1 3.b) */
473 mpz_powm(c, m, &key->e, &key->n);
474
475 /* convert integer back to a chunk (PKCS#1 7.2.1 3.c) */
476 out = mpz_to_n(c, key->k);
477 mpz_clear(c);
478 mpz_clear(m);
479
480 DBG(DBG_RAW,
481 DBG_dump_chunk("rsa encrypted data:\n", out)
482 )
483 return out;
484 }
485 }
486
487 /**
488 * Decrypt data with an RSA private key and remove padding
489 */
490 bool RSA_decrypt(const RSA_private_key_t *key, chunk_t in, chunk_t *out)
491 {
492 chunk_t padded, plaintext;
493 u_char *pos;
494 mpz_t t1, t2;
495
496 n_to_mpz(t1, in.ptr,in.len);
497
498 /* PKCS#1 v1.5 8.3 RSA computation y = x^c mod n
499 * Better described in PKCS#1 v2.0 5.1 RSADP.
500 * There are two methods, depending on the form of the private key.
501 * We use the one based on the Chinese Remainder Theorem.
502 */
503 mpz_init(t2);
504
505 mpz_powm(t2, t1, &key->dP, &key->p); /* m1 = c^dP mod p */
506 mpz_powm(t1, t1, &key->dQ, &key->q); /* m2 = c^dQ mod Q */
507
508 mpz_sub(t2, t2, t1); /* h = qInv (m1 - m2) mod p */
509 mpz_mod(t2, t2, &key->p);
510 mpz_mul(t2, t2, &key->qInv);
511 mpz_mod(t2, t2, &key->p);
512
513 mpz_mul(t2, t2, &key->q); /* m = m2 + h q */
514 mpz_add(t1, t1, t2);
515
516 padded = mpz_to_n(t1, key->pub.k);
517 mpz_clear(t1);
518 mpz_clear(t2);
519
520 DBG(DBG_PRIVATE,
521 DBG_dump_chunk("rsa decrypted data with padding:\n", padded)
522 )
523 pos = padded.ptr;
524
525 /* PKCS#1 v1.5 8.1 encryption-block formatting (EB = 00 || 02 || PS || 00 || D) */
526
527 /* check for hex pattern 00 02 in decrypted message */
528 if ((*pos++ != 0x00) || (*(pos++) != 0x02))
529 {
530 plog("incorrect padding - probably wrong RSA key");
531 chunk_clear(&padded);
532 return FALSE;
533 }
534 padded.len -= 2;
535
536 /* the plaintext data starts after first 0x00 byte */
537 while (padded.len-- > 0 && *pos++ != 0x00)
538
539 if (padded.len == 0)
540 {
541 plog("no plaintext data");
542 free(padded.ptr);
543 return FALSE;
544 }
545
546 plaintext = chunk_create(pos, padded.len);
547 *out = chunk_clone(plaintext);
548 chunk_clear(&padded);
549 return TRUE;
550 }
551
552 /**
553 * Build signatureValue
554 */
555 chunk_t pkcs1_build_signature(chunk_t tbs, int hash_alg,
556 const RSA_private_key_t *key, bool bit_string)
557 {
558
559 size_t siglen = key->pub.k;
560
561 u_char digest_buf[MAX_DIGEST_LEN];
562 chunk_t digest = { digest_buf, MAX_DIGEST_LEN };
563 chunk_t digestInfo, signatureValue;
564 u_char *pos;
565
566 if (!compute_digest(tbs, hash_alg, &digest))
567 {
568 return chunk_empty;
569 }
570
571 /* according to PKCS#1 v2.1 digest must be packaged into
572 * an ASN.1 structure for encryption
573 */
574 digestInfo = asn1_wrap(ASN1_SEQUENCE, "cm"
575 , asn1_algorithmIdentifier(hash_alg)
576 , asn1_simple_object(ASN1_OCTET_STRING, digest));
577
578 /* generate the RSA signature */
579 if (bit_string)
580 {
581 pos = asn1_build_object(&signatureValue, ASN1_BIT_STRING, 1 + siglen);
582 *pos++ = 0x00;
583 }
584 else
585 {
586 pos = asn1_build_object(&signatureValue, ASN1_OCTET_STRING, siglen);
587 }
588 sign_hash(key, digestInfo.ptr, digestInfo.len, pos, siglen);
589 free(digestInfo.ptr);
590
591 return signatureValue;
592 }
593
594 /**
595 * Build a DER-encoded PKCS#1 private key object
596 */
597 chunk_t pkcs1_build_private_key(const RSA_private_key_t *key)
598 {
599 chunk_t pkcs1 = asn1_wrap(ASN1_SEQUENCE, "cmmmmmmmm"
600 , ASN1_INTEGER_0
601 , asn1_integer_from_mpz(&key->pub.n)
602 , asn1_integer_from_mpz(&key->pub.e)
603 , asn1_integer_from_mpz(&key->d)
604 , asn1_integer_from_mpz(&key->p)
605 , asn1_integer_from_mpz(&key->q)
606 , asn1_integer_from_mpz(&key->dP)
607 , asn1_integer_from_mpz(&key->dQ)
608 , asn1_integer_from_mpz(&key->qInv));
609
610 DBG(DBG_PRIVATE,
611 DBG_dump_chunk("PKCS#1 encoded private key:", pkcs1)
612 )
613 return pkcs1;
614 }
615
616 /**
617 * Build a DER-encoded PKCS#1 public key object
618 */
619 chunk_t pkcs1_build_public_key(const RSA_public_key_t *rsa)
620 {
621 return asn1_wrap(ASN1_SEQUENCE, "mm"
622 , asn1_integer_from_mpz(&rsa->n)
623 , asn1_integer_from_mpz(&rsa->e));
624 }
625
626 /**
627 * Build a DER-encoded publicKeyInfo object
628 */
629 chunk_t pkcs1_build_publicKeyInfo(const RSA_public_key_t *rsa)
630 {
631 chunk_t publicKey;
632 chunk_t rawKey = pkcs1_build_public_key(rsa);
633 u_char *pos;
634
635 pos = asn1_build_object(&publicKey, ASN1_BIT_STRING, 1 + rawKey.len);
636 *pos++ = 0x00;
637 mv_chunk(&pos, rawKey);
638
639 return asn1_wrap(ASN1_SEQUENCE, "cm"
640 , asn1_algorithmIdentifier(OID_RSA_ENCRYPTION)
641 , publicKey);
642 }
643
644 void free_RSA_public_content(RSA_public_key_t *rsa)
645 {
646 mpz_clear(&rsa->n);
647 mpz_clear(&rsa->e);
648 }
649
650 void free_RSA_private_content(RSA_private_key_t *rsak)
651 {
652 free_RSA_public_content(&rsak->pub);
653 mpz_clear(&rsak->d);
654 mpz_clear(&rsak->p);
655 mpz_clear(&rsak->q);
656 mpz_clear(&rsak->dP);
657 mpz_clear(&rsak->dQ);
658 mpz_clear(&rsak->qInv);
659 }