/src/nettle/curve448-eh-to-x.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* curve448-eh-to-x.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 | | /* Transform a point on the edwards448 Edwards curve to the curve448 |
45 | | Montgomery curve, and return the x coordinate. */ |
46 | | void |
47 | | curve448_eh_to_x (mp_limb_t *xp, const mp_limb_t *p, mp_limb_t *scratch) |
48 | 0 | { |
49 | 0 | #define up p |
50 | 0 | #define vp (p + ecc->p.size) |
51 | 0 | #define t0 scratch |
52 | 0 | #define tp (scratch + ecc->p.size) |
53 | |
|
54 | 0 | const struct ecc_curve *ecc = &_nettle_curve448; |
55 | | |
56 | | /* If u = U/W and v = V/W are the coordinates of the point on |
57 | | edwards448 we get the curve448 x coordinate as |
58 | | |
59 | | x = v^2 / u^2 = (V/W)^2 / (U/W)^2 = (V/U)^2 |
60 | | */ |
61 | | /* Needs a total of 5*size storage. */ |
62 | 0 | ecc->p.invert (&ecc->p, t0, up, tp); |
63 | 0 | ecc_mod_mul (&ecc->p, t0, t0, vp, tp); |
64 | 0 | ecc_mod_sqr_canonical (&ecc->p, xp, t0, tp); |
65 | |
|
66 | 0 | #undef up |
67 | 0 | #undef vp |
68 | 0 | #undef t0 |
69 | 0 | #undef tp |
70 | 0 | } |