e4fbc5fef3a5eeb522618a0b367f7d04a2fcf6e6
[platform/upstream/nettle.git] / rsa-decrypt-tr.c
1 /* rsa-decrypt-tr.c
2
3    RSA decryption, using randomized RSA blinding to be more resistant
4    to timing attacks.
5
6    Copyright (C) 2001, 2012 Niels Möller, Nikos Mavrogiannopoulos
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
13      * the GNU Lesser General Public License as published by the Free
14        Software Foundation; either version 3 of the License, or (at your
15        option) any later version.
16
17    or
18
19      * the GNU General Public License as published by the Free
20        Software Foundation; either version 2 of the License, or (at your
21        option) any later version.
22
23    or both in parallel, as here.
24
25    GNU Nettle is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28    General Public License for more details.
29
30    You should have received copies of the GNU General Public License and
31    the GNU Lesser General Public License along with this program.  If
32    not, see http://www.gnu.org/licenses/.
33 */
34
35 #if HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include "rsa.h"
40
41 #include "bignum.h"
42 #include "pkcs1.h"
43
44 int
45 rsa_decrypt_tr(const struct rsa_public_key *pub,
46                const struct rsa_private_key *key,
47                void *random_ctx, nettle_random_func *random,
48                size_t *length, uint8_t *message,
49                const mpz_t gibberish)
50 {
51   mpz_t m;
52   int res;
53
54   mpz_init_set(m, gibberish);
55
56   res = (rsa_compute_root_tr (pub, key, random_ctx, random, m, gibberish)
57          && pkcs1_decrypt (key->size, m, length, message));
58
59   mpz_clear(m);
60   return res;
61 }