Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
crypto_verify.h
1#ifndef SOURCEMETA_CORE_CRYPTO_VERIFY_H_
2#define SOURCEMETA_CORE_CRYPTO_VERIFY_H_
3
4#ifndef SOURCEMETA_CORE_CRYPTO_EXPORT
5#include <sourcemeta/core/crypto_export.h>
6#endif
7
8#include <cstdint> // std::uint8_t
9#include <optional> // std::optional
10#include <string> // std::string
11#include <string_view> // std::string_view
12
13namespace sourcemeta::core {
14
17enum class SignatureHashFunction : std::uint8_t {
24};
25
28enum class EllipticCurve : std::uint8_t {
35};
36
39enum class EdwardsCurve : std::uint8_t {
44};
45
62class SOURCEMETA_CORE_CRYPTO_EXPORT PublicKey {
63public:
65 enum class Type : std::uint8_t {
67 RSA,
71 Edwards
72 };
73
74 ~PublicKey();
76 PublicKey(PublicKey &&other) noexcept;
77 auto operator=(PublicKey &&other) noexcept -> PublicKey &;
78 PublicKey(const PublicKey &) = delete;
79 auto operator=(const PublicKey &) -> PublicKey & = delete;
80
82 [[nodiscard]] auto type() const noexcept -> Type;
83
85 struct Internal;
87 explicit PublicKey(Internal *internal) noexcept;
90 [[nodiscard]] auto internal() const noexcept -> const Internal * {
91 return this->internal_;
92 }
93
94private:
95 Internal *internal_;
96};
97
101auto SOURCEMETA_CORE_CRYPTO_EXPORT make_rsa_public_key(
102 const std::string_view modulus, const std::string_view exponent)
103 -> std::optional<PublicKey>;
104
108auto SOURCEMETA_CORE_CRYPTO_EXPORT make_ec_public_key(
109 const EllipticCurve curve, const std::string_view coordinate_x,
110 const std::string_view coordinate_y) -> std::optional<PublicKey>;
111
115auto SOURCEMETA_CORE_CRYPTO_EXPORT make_eddsa_public_key(
116 const EdwardsCurve curve, const std::string_view public_key)
117 -> std::optional<PublicKey>;
118
124 std::string modulus;
126 std::string exponent;
127};
128
136 std::string x;
138 std::string y;
139};
140
150
164auto SOURCEMETA_CORE_CRYPTO_EXPORT rsa_public_components(const PublicKey &key)
165 -> std::optional<RSAPublicComponents>;
166
181auto SOURCEMETA_CORE_CRYPTO_EXPORT ec_public_components(const PublicKey &key)
182 -> std::optional<ECPublicComponents>;
183
199auto SOURCEMETA_CORE_CRYPTO_EXPORT edwards_public_components(
200 const PublicKey &key) -> std::optional<EdwardsPublicComponents>;
201
217auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pkcs1_v15_verify(
218 const PublicKey &key, const SignatureHashFunction hash,
219 const std::string_view message, const std::string_view signature) -> bool;
220
237auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pss_verify(
238 const PublicKey &key, const SignatureHashFunction hash,
239 const std::string_view message, const std::string_view signature) -> bool;
240
259auto SOURCEMETA_CORE_CRYPTO_EXPORT ecdsa_verify(
260 const PublicKey &key, const SignatureHashFunction hash,
261 const std::string_view message, const std::string_view signature) -> bool;
262
279auto SOURCEMETA_CORE_CRYPTO_EXPORT
280eddsa_verify(const PublicKey &key, const std::string_view message,
281 const std::string_view signature) -> bool;
282
283} // namespace sourcemeta::core
284
285#endif
EdwardsCurve curve
The curve the point belongs to.
Definition crypto_verify.h:146
std::string exponent
The RSA public exponent.
Definition crypto_verify.h:126
auto type() const noexcept -> Type
The kind of key this is.
std::string y
The y coordinate.
Definition crypto_verify.h:138
Type
The kind of key, which fixes the signature schemes it can verify.
Definition crypto_verify.h:65
std::string x
The x coordinate.
Definition crypto_verify.h:136
std::string modulus
The RSA modulus.
Definition crypto_verify.h:124
auto internal() const noexcept -> const Internal *
Definition crypto_verify.h:90
std::string point
The encoded public point.
Definition crypto_verify.h:148
EllipticCurve curve
The curve the coordinates belong to.
Definition crypto_verify.h:134
PublicKey(PublicKey &&other) noexcept
Move constructor.
Definition crypto_verify.h:62
auto SOURCEMETA_CORE_CRYPTO_EXPORT edwards_public_components(const PublicKey &key) -> std::optional< EdwardsPublicComponents >
auto SOURCEMETA_CORE_CRYPTO_EXPORT rsa_public_components(const PublicKey &key) -> std::optional< RSAPublicComponents >
auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pss_verify(const PublicKey &key, const SignatureHashFunction hash, const std::string_view message, const std::string_view signature) -> bool
auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pkcs1_v15_verify(const PublicKey &key, const SignatureHashFunction hash, const std::string_view message, const std::string_view signature) -> bool
auto SOURCEMETA_CORE_CRYPTO_EXPORT ec_public_components(const PublicKey &key) -> std::optional< ECPublicComponents >
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_ec_public_key(const EllipticCurve curve, const std::string_view coordinate_x, const std::string_view coordinate_y) -> std::optional< PublicKey >
EllipticCurve
Definition crypto_verify.h:28
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_eddsa_public_key(const EdwardsCurve curve, const std::string_view public_key) -> std::optional< PublicKey >
SignatureHashFunction
Definition crypto_verify.h:17
EdwardsCurve
Definition crypto_verify.h:39
auto SOURCEMETA_CORE_CRYPTO_EXPORT ecdsa_verify(const PublicKey &key, const SignatureHashFunction hash, const std::string_view message, const std::string_view signature) -> bool
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_rsa_public_key(const std::string_view modulus, const std::string_view exponent) -> std::optional< PublicKey >
auto SOURCEMETA_CORE_CRYPTO_EXPORT eddsa_verify(const PublicKey &key, const std::string_view message, const std::string_view signature) -> bool
@ SHA256
The SHA-256 hash function, selecting RSA-OAEP-256.
Definition crypto_rsa_oaep.h:25
@ P384
The NIST P-384 elliptic curve.
Definition crypto_verify.h:32
@ P256
The NIST P-256 elliptic curve.
Definition crypto_verify.h:30
@ P521
The NIST P-521 elliptic curve.
Definition crypto_verify.h:34
@ SHA512
The SHA-512 hash function.
Definition crypto_verify.h:23
@ SHA384
The SHA-384 hash function.
Definition crypto_verify.h:21
@ Ed25519
The Ed25519 Edwards curve.
Definition crypto_verify.h:41
@ Ed448
The Ed448 Edwards curve.
Definition crypto_verify.h:43
Definition crypto_verify.h:132
Definition crypto_verify.h:144
Definition crypto_verify.h:122