Botan 3.5.0
Crypto and TLS for C&
pcurves_secp521r1.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
15// clang-format off
16namespace secp521r1 {
17
18template <typename Params>
19class P521Rep final {
20 public:
21 static constexpr auto P = Params::P;
22 static constexpr size_t N = Params::N;
23 typedef typename Params::W W;
24
25 constexpr static std::array<W, N> one() {
26 std::array<W, N> one = {};
27 one[0] = 1;
28 return one;
29 }
30
31 constexpr static std::array<W, N> redc(const std::array<W, 2 * N>& z) {
32 constexpr W TOP_MASK = static_cast<W>(0x1FF);
33
34 std::array<W, N> hi = {};
35 copy_mem(hi, std::span{z}.template subspan<N - 1, N>());
37
38 std::array<W, N> lo = {};
39 copy_mem(lo, std::span{z}.template first<N>());
40 lo[N - 1] &= TOP_MASK;
41
42 // s = hi + lo
43 std::array<W, N> s = {};
44 // Will never carry out
45 W carry = bigint_add<W, N>(s, lo, hi);
46
47 // But might be greater than modulus:
48 std::array<W, N> r = {};
49 bigint_monty_maybe_sub<N>(r.data(), carry, s.data(), P.data());
50
51 return r;
52 }
53
54 constexpr static std::array<W, N> to_rep(const std::array<W, N>& x) { return x; }
55
56 constexpr static std::array<W, N> wide_to_rep(const std::array<W, 2 * N>& x) { return redc(x); }
57
58 constexpr static std::array<W, N> from_rep(const std::array<W, N>& z) { return z; }
59};
60
61class Params final : public EllipticCurveParameters<
62 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
63 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC",
64 "51953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00",
65 "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409",
66 "C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66",
67 "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650",
68 -4> {
69};
70
71class Curve final : public EllipticCurve<Params, P521Rep> {};
72
73}
74
75// clang-format on
76
77} // namespace
78
79std::shared_ptr<const PrimeOrderCurve> PCurveInstance::secp521r1() {
81}
82
83} // namespace Botan::PCurve
static std::shared_ptr< const PrimeOrderCurve > secp521r1()
Definition pcurves.cpp:33
static std::shared_ptr< const PrimeOrderCurve > instance()
int(* final)(unsigned char *, CTX *)
constexpr auto bigint_add(std::span< W, N > z, std::span< const W, N > x, std::span< const W, N > y) -> W
Definition mp_core.h:257
constexpr void bigint_monty_maybe_sub(size_t N, W z[], W x0, const W x[], const W p[])
Definition mp_core.h:374
void carry(int64_t &h0, int64_t &h1)
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146
constexpr W shift_right(std::array< W, N > &x)
Definition mp_core.h:875