17template <
typename Params>
20 static constexpr auto P = Params::P;
21 static constexpr size_t N = Params::N;
22 typedef typename Params::W W;
24 constexpr static std::array<W, N> one() {
return std::array<W, N>{1}; }
26 constexpr static std::array<W, N> redc(
const std::array<W, 2 * N>& z) {
27 constexpr W TOP_MASK =
static_cast<W
>(0x1FF);
34 for(
size_t i = 0; i != N; ++i) {
35 t[i] = z[(N - 1) + i] >> 9;
38 for(
size_t i = 0; i != N - 1; ++i) {
46 constexpr size_t HN = N / 2;
52 t[N - 1] += (z[N - 1] & TOP_MASK) +
carry;
61 constexpr static std::array<W, N> to_rep(
const std::array<W, N>& x) {
return x; }
63 constexpr static std::array<W, N> wide_to_rep(
const std::array<W, 2 * N>& x) {
return redc(x); }
65 constexpr static std::array<W, N> from_rep(
const std::array<W, N>& z) {
return z; }
69class Params
final :
public EllipticCurveParameters<
70 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
71 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC",
72 "51953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00",
73 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409",
74 "C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66",
75 "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650",
81class Curve
final :
public EllipticCurve<Params, P521Rep> {
84 static FieldElement fe_invert2(
const FieldElement& x) {
87 FieldElement r = x.square();
124 static Scalar scalar_invert(
const Scalar& x) {
127 auto t2 = x.square();