Botan 3.4.0
Crypto and TLS for C&
ed448_internal.h
Go to the documentation of this file.
1/*
2 * Ed448 Internals
3 * (C) 2024 Jack Lloyd
4 * 2024 René Meusel, Fabian Albert - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_ED448_INTERNAL_H_
10#define BOTAN_ED448_INTERNAL_H_
11
12#include <botan/internal/curve448_gf.h>
13#include <botan/internal/curve448_scalar.h>
14
15namespace Botan {
16
17constexpr size_t ED448_LEN = 57;
18
19/**
20 * @brief Representation of a point on the Ed448 curve.
21 *
22 * The point is represented in projective coordinates (X, Y, Z).
23 * All operations are constant time.
24 */
26 public:
27 /// Decode a point from its 57-byte encoding (RFC 8032 5.2.3)
28 static Ed448Point decode(std::span<const uint8_t, ED448_LEN> enc);
29
30 /// Create the curve's base point ('B' in RFC 8032 5.2)
31 static Ed448Point base_point();
32
33 /// Create a point from its projective coordinates X, Y, Z
34 Ed448Point(const Gf448Elem& x, const Gf448Elem& y, const Gf448Elem& z) : m_x(x), m_y(y), m_z(z) {}
35
36 /// Create a point from its coordinates x, y
37 Ed448Point(const Gf448Elem& x, const Gf448Elem& y) : m_x(x), m_y(y), m_z(1) {}
38
39 /// Encode the point to its 57-byte representation (RFC 8032 5.2.2)
40 std::array<uint8_t, ED448_LEN> encode() const;
41
42 /// Add two points (RFC 8032 5.2.4)
43 Ed448Point operator+(const Ed448Point& other) const;
44
45 /// Double a point (RFC 8032 5.2.4)
46 Ed448Point double_point() const;
47
48 /// Scalar multiplication
49 Ed448Point scalar_mul(const Scalar448& scalar) const;
50
51 /// Getter for projective coordinate X
52 Gf448Elem x_proj() const { return m_x; }
53
54 /// Getter for projective coordinate Y
55 Gf448Elem y_proj() const { return m_y; }
56
57 /// Getter for projective coordinate Z
58 Gf448Elem z_proj() const { return m_z; }
59
60 /// Getter for point coordinate x
61 Gf448Elem x() const { return m_x / m_z; }
62
63 /// Getter for point coordinate y
64 Gf448Elem y() const { return m_y / m_z; }
65
66 /// Check if two points are equal (constant time)
67 bool operator==(const Ed448Point& other) const;
68
69 /// Assign other to this if cond is true (constant time)
70 void ct_conditional_assign(bool cond, const Ed448Point& other);
71
72 private:
73 Gf448Elem m_x;
74 Gf448Elem m_y;
75 Gf448Elem m_z;
76};
77
78/// Syntax sugar for scalar multiplication
79Ed448Point operator*(const Scalar448& lhs, const Ed448Point& rhs);
80
81/**
82 * @brief Create a public key point from a secret key (RFC 8032 5.2.5)
83 */
84BOTAN_TEST_API std::array<uint8_t, ED448_LEN> create_pk_from_sk(std::span<const uint8_t, ED448_LEN> sk);
85
86/**
87 * @brief Sign a message using a keypair (RFC 8032 5.2.6)
88 *
89 * @param sk the secret key
90 * @param pk the public key
91 * @param f the prehash flag (true iff using Ed448ph)
92 * @param context the context string
93 * @param msg the message to sign
94 * @return the signature
95 */
96BOTAN_TEST_API std::array<uint8_t, 114> sign_message(std::span<const uint8_t, ED448_LEN> sk,
97 std::span<const uint8_t, ED448_LEN> pk,
98 bool f,
99 std::span<const uint8_t> context,
100 std::span<const uint8_t> msg);
101
102/**
103 * @brief Verify a signature(RFC 8032 5.2.7)
104 *
105 * @param pk the public key
106 * @param phflag the prehash flag (true iff using Ed448ph)
107 * @param context the context string
108 * @param sig the signature
109 * @param msg the message to verify
110 *
111 * @throw Decoding_Error if the public key or signature is malformed
112 * @return true if the signature is valid
113 */
114BOTAN_TEST_API bool verify_signature(std::span<const uint8_t, ED448_LEN> pk,
115 bool phflag,
116 std::span<const uint8_t> context,
117 std::span<const uint8_t> sig,
118 std::span<const uint8_t> msg);
119
120} // namespace Botan
121
122#endif // BOTAN_ED448_INTERNAL_H_
Representation of a point on the Ed448 curve.
Gf448Elem z_proj() const
Getter for projective coordinate Z.
Gf448Elem y() const
Getter for point coordinate y.
Gf448Elem x_proj() const
Getter for projective coordinate X.
Ed448Point(const Gf448Elem &x, const Gf448Elem &y)
Create a point from its coordinates x, y.
Ed448Point(const Gf448Elem &x, const Gf448Elem &y, const Gf448Elem &z)
Create a point from its projective coordinates X, Y, Z.
Gf448Elem y_proj() const
Getter for projective coordinate Y.
Gf448Elem x() const
Getter for point coordinate x.
Representation of a scalar for X448.
#define BOTAN_TEST_API
Definition compiler.h:51
BigInt operator*(const BigInt &x, const BigInt &y)
Definition big_ops3.cpp:46
std::array< uint8_t, ED448_LEN > create_pk_from_sk(std::span< const uint8_t, ED448_LEN > sk)
Create a public key point from a secret key (RFC 8032 5.2.5)
bool verify_signature(std::span< const uint8_t, ED448_LEN > pk, bool phflag, std::span< const uint8_t > context, std::span< const uint8_t > sig, std::span< const uint8_t > msg)
Verify a signature(RFC 8032 5.2.7)
OctetString operator+(const OctetString &k1, const OctetString &k2)
Definition symkey.cpp:99
constexpr size_t ED448_LEN
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition alg_id.cpp:54
std::array< uint8_t, 2 *ED448_LEN > sign_message(std::span< const uint8_t, ED448_LEN > sk, std::span< const uint8_t, ED448_LEN > pk, bool pgflag, std::span< const uint8_t > context, std::span< const uint8_t > msg)
Sign a message using a keypair (RFC 8032 5.2.6)