]>
git.ipfire.org Git - thirdparty/nettle.git/blob - rsa-decrypt-tr.c
3 RSA decryption, using randomized RSA blinding to be more resistant
6 Copyright (C) 2001, 2012 Niels Möller, Nikos Mavrogiannopoulos
8 This file is part of GNU Nettle.
10 GNU Nettle is free software: you can redistribute it and/or
11 modify it under the terms of either:
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.
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.
23 or both in parallel, as here.
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.
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/.
39 #include "rsa-internal.h"
40 #include "pkcs1-internal.h"
44 rsa_decrypt_tr(const struct rsa_public_key
*pub
,
45 const struct rsa_private_key
*key
,
46 void *random_ctx
, nettle_random_func
*random
,
47 size_t *length
, uint8_t *message
,
48 const mpz_t gibberish
)
50 TMP_GMP_DECL (m
, mp_limb_t
);
51 TMP_GMP_DECL (em
, uint8_t);
52 mp_size_t key_limb_size
;
55 /* First check that input is in range. */
56 if (mpz_sgn (gibberish
) < 0 || mpz_cmp (gibberish
, pub
->n
) >= 0)
59 key_limb_size
= mpz_size(pub
->n
);
61 TMP_GMP_ALLOC (m
, key_limb_size
);
62 TMP_GMP_ALLOC (em
, key
->size
);
63 mpz_limbs_copy(m
, gibberish
, key_limb_size
);
65 res
= _rsa_sec_compute_root_tr (pub
, key
, random_ctx
, random
, m
, m
);
67 mpn_get_base256 (em
, key
->size
, m
, key_limb_size
);
69 res
&= _pkcs1_sec_decrypt_variable (length
, message
, key
->size
, em
);