/src/nettle/curve448-mul-g.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* curve448-mul-g.c |
2 | | |
3 | | Copyright (C) 2017 Daiki Ueno |
4 | | Copyright (C) 2017 Red Hat, Inc. |
5 | | |
6 | | This file is part of GNU Nettle. |
7 | | |
8 | | GNU Nettle is free software: you can redistribute it and/or |
9 | | modify it under the terms of either: |
10 | | |
11 | | * the GNU Lesser General Public License as published by the Free |
12 | | Software Foundation; either version 3 of the License, or (at your |
13 | | option) any later version. |
14 | | |
15 | | or |
16 | | |
17 | | * the GNU General Public License as published by the Free |
18 | | Software Foundation; either version 2 of the License, or (at your |
19 | | option) any later version. |
20 | | |
21 | | or both in parallel, as here. |
22 | | |
23 | | GNU Nettle is distributed in the hope that it will be useful, |
24 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
26 | | General Public License for more details. |
27 | | |
28 | | You should have received copies of the GNU General Public License and |
29 | | the GNU Lesser General Public License along with this program. If |
30 | | not, see http://www.gnu.org/licenses/. |
31 | | */ |
32 | | |
33 | | #if HAVE_CONFIG_H |
34 | | # include "config.h" |
35 | | #endif |
36 | | |
37 | | #include <string.h> |
38 | | |
39 | | #include "curve448.h" |
40 | | |
41 | | #include "ecc.h" |
42 | | #include "ecc-internal.h" |
43 | | |
44 | | /* Intended to be compatible with NaCl's crypto_scalarmult_base. */ |
45 | | void |
46 | | curve448_mul_g (uint8_t *r, const uint8_t *n) |
47 | 0 | { |
48 | 0 | const struct ecc_curve *ecc = &_nettle_curve448; |
49 | 0 | uint8_t t[CURVE448_SIZE]; |
50 | 0 | mp_limb_t *scratch; |
51 | 0 | mp_size_t itch; |
52 | |
|
53 | 0 | #define ng scratch |
54 | 0 | #define x (scratch + 3*ecc->p.size) |
55 | 0 | #define scratch_out (scratch + 4*ecc->p.size) |
56 | |
|
57 | 0 | memcpy (t, n, sizeof(t)); |
58 | 0 | t[0] &= ~3; |
59 | 0 | t[CURVE448_SIZE-1] = (t[CURVE448_SIZE-1] & 0x7f) | 0x80; |
60 | |
|
61 | 0 | itch = 5*ecc->p.size + ecc->mul_g_itch; |
62 | 0 | scratch = gmp_alloc_limbs (itch); |
63 | |
|
64 | 0 | mpn_set_base256_le (x, ecc->p.size, t, CURVE448_SIZE); |
65 | |
|
66 | 0 | ecc_mul_g_eh (ecc, ng, x, scratch_out); |
67 | 0 | curve448_eh_to_x (x, ng, scratch_out); |
68 | |
|
69 | 0 | mpn_get_base256_le (r, CURVE448_SIZE, x, ecc->p.size); |
70 | 0 | gmp_free_limbs (scratch, itch); |
71 | 0 | #undef ng |
72 | 0 | #undef x |
73 | 0 | #undef scratch_out |
74 | 0 | } |