Botan 3.13.0
Crypto and TLS for C&
pcurves_numsp512d1.cpp
Go to the documentation of this file.
1/*
2* (C) 2024 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/pcurves_instance.h>
8
9#include <botan/internal/pcurves_wrap.h>
10
11namespace Botan::PCurve {
12
13namespace {
14
15namespace numsp512d1 {
16
17template <typename Params>
18class Numsp512d1Rep final {
19 public:
20 static constexpr auto P = Params::P;
21 static constexpr size_t N = Params::N;
22 typedef typename Params::W W;
23
24 static constexpr W C = 569;
25
26 constexpr static std::array<W, N> one() { return std::array<W, N>{1}; }
27
28 constexpr static std::array<W, N> redc(const std::array<W, 2 * N>& z) {
29 return redc_crandall<W, N, C>(std::span{z});
30 }
31
32 constexpr static std::array<W, N> to_rep(const std::array<W, N>& x) { return x; }
33
34 constexpr static std::array<W, N> wide_to_rep(const std::array<W, 2 * N>& x) { return redc(x); }
35
36 constexpr static std::array<W, N> from_rep(const std::array<W, N>& z) { return z; }
37};
38
39// clang-format off
40
41class Params final : public EllipticCurveParameters<
42 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC7",
43 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDC4",
44 "1D99B",
45 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5B3CA4FB94E7831B4FC258ED97D0BDC63B568B36607CD243CE153F390433555D",
46 "2",
47 "1C282EB23327F9711952C250EA61AD53FCC13031CF6DD336E0B9328433AFBDD8CC5A1C1F0C716FDC724DDE537C2B0ADB00BB3D08DC83755B205CC30D7F83CF28",
48 -4> {
49};
50
51// clang-format on
52
53class Curve final : public EllipticCurve<Params, Numsp512d1Rep> {
54 public:
55 static constexpr FieldElement fe_invert2(const FieldElement& x) {
56 // Generated by https://github.com/mmcloughlin/addchain
57 auto z = x.square();
58 z *= x;
59 z = z.square();
60 z *= x;
61 auto t0 = z;
62 t0.square_n(3);
63 t0 *= z;
64 t0.square_n(3);
65 auto t1 = t0 * z;
66 t0 = t1;
67 t0.square_n(9);
68 t0 *= t1;
69 t0.square_n(3);
70 t0 *= z;
71 auto t2 = t0;
72 t2.square_n(9);
73 t1 *= t2;
74 t2 = t1;
75 t2.square_n(30);
76 t1 *= t2;
77 t2 = t1;
78 t2.square_n(60);
79 t1 *= t2;
80 t2 = t1;
81 t2.square_n(120);
82 t1 *= t2;
83 t2 = t1;
84 t2.square_n(240);
85 t1 *= t2;
86 t1.square_n(21);
87 t0 *= t1;
88 t0 = t0.square();
89 t0 *= x;
90 t0.square_n(4);
91 z *= t0;
92 z.square_n(4);
93 z *= x;
94 z.square_n(2);
95 return z;
96 }
97
98 static constexpr FieldElement fe_sqrt(const FieldElement& x) {
99 // Generated by https://github.com/mmcloughlin/addchain
100 auto z = x.square();
101 z *= x;
102 z = z.square();
103 z *= x;
104 auto t0 = z;
105 t0.square_n(3);
106 t0 *= z;
107 t0.square_n(3);
108 auto t1 = t0 * z;
109 t0 = t1;
110 t0.square_n(9);
111 t0 *= t1;
112 t0.square_n(3);
113 t0 *= z;
114 auto t2 = t0;
115 t2.square_n(9);
116 t1 *= t2;
117 t2 = t1;
118 t2.square_n(30);
119 t1 *= t2;
120 t2 = t1;
121 t2.square_n(60);
122 t1 *= t2;
123 t2 = t1;
124 t2.square_n(120);
125 t1 *= t2;
126 t2 = t1;
127 t2.square_n(240);
128 t1 *= t2;
129 t1.square_n(21);
130 t0 *= t1;
131 t0 = t0.square();
132 t0 *= x;
133 t0.square_n(4);
134 z *= t0;
135 z.square_n(3);
136 z *= x;
137 z = z.square();
138 return z;
139 }
140};
141
142} // namespace numsp512d1
143
144} // namespace
145
146std::shared_ptr<const PrimeOrderCurve> PCurveInstance::numsp512d1() {
148}
149
150} // namespace Botan::PCurve
static std::shared_ptr< const PrimeOrderCurve > instance()
constexpr std::array< W, N > redc_crandall(std::span< const W, 2 *N > z)
Definition mp_core.h:992