Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
crypto_sign.h
1#ifndef SOURCEMETA_CORE_CRYPTO_SIGN_H_
2#define SOURCEMETA_CORE_CRYPTO_SIGN_H_
3
4#ifndef SOURCEMETA_CORE_CRYPTO_EXPORT
5#include <sourcemeta/core/crypto_export.h>
6#endif
7
8#include <sourcemeta/core/crypto_verify.h>
9
10#include <cstdint> // std::uint8_t
11#include <optional> // std::optional
12#include <string> // std::string
13#include <string_view> // std::string_view
14
15namespace sourcemeta::core {
16
33class SOURCEMETA_CORE_CRYPTO_EXPORT PrivateKey {
34public:
36 enum class Type : std::uint8_t {
38 RSA,
42 Edwards
43 };
44
47 PrivateKey(PrivateKey &&other) noexcept;
48 auto operator=(PrivateKey &&other) noexcept -> PrivateKey &;
49 PrivateKey(const PrivateKey &) = delete;
50 auto operator=(const PrivateKey &) -> PrivateKey & = delete;
51
53 [[nodiscard]] auto type() const noexcept -> Type;
54
56 struct Internal;
58 explicit PrivateKey(Internal *internal) noexcept;
61 [[nodiscard]] auto internal() const noexcept -> const Internal * {
62 return this->internal_;
63 }
64
65private:
66 Internal *internal_;
67};
68
75auto SOURCEMETA_CORE_CRYPTO_EXPORT make_private_key(const std::string_view pem)
76 -> std::optional<PrivateKey>;
77
83auto SOURCEMETA_CORE_CRYPTO_EXPORT make_ec_private_key(
84 const EllipticCurve curve, const std::string_view scalar,
85 const std::string_view coordinate_x, const std::string_view coordinate_y)
86 -> std::optional<PrivateKey>;
87
100auto SOURCEMETA_CORE_CRYPTO_EXPORT
101generate_ec_private_key(const EllipticCurve curve) -> std::optional<PrivateKey>;
102
106auto SOURCEMETA_CORE_CRYPTO_EXPORT
107make_edwards_private_key(const EdwardsCurve curve, const std::string_view seed)
108 -> std::optional<PrivateKey>;
109
117auto SOURCEMETA_CORE_CRYPTO_EXPORT make_rsa_private_key(
118 const std::string_view modulus, const std::string_view public_exponent,
119 const std::string_view private_exponent, const std::string_view prime1,
120 const std::string_view prime2, const std::string_view exponent1,
121 const std::string_view exponent2, const std::string_view coefficient)
122 -> std::optional<PrivateKey>;
123
139auto SOURCEMETA_CORE_CRYPTO_EXPORT derive_public_key(const PrivateKey &key)
140 -> std::optional<PublicKey>;
141
156auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pkcs1_v15_sign(
157 const PrivateKey &key, const SignatureHashFunction hash,
158 const std::string_view message) -> std::optional<std::string>;
159
175auto SOURCEMETA_CORE_CRYPTO_EXPORT
177 const std::string_view message) -> std::optional<std::string>;
178
196auto SOURCEMETA_CORE_CRYPTO_EXPORT ecdsa_sign(const PrivateKey &key,
197 const SignatureHashFunction hash,
198 const std::string_view message)
199 -> std::optional<std::string>;
200
215auto SOURCEMETA_CORE_CRYPTO_EXPORT eddsa_sign(const PrivateKey &key,
216 const std::string_view message)
217 -> std::optional<std::string>;
218
219} // namespace sourcemeta::core
220
221#endif
PrivateKey(PrivateKey &&other) noexcept
Move constructor.
auto type() const noexcept -> Type
The kind of key this is.
auto internal() const noexcept -> const Internal *
Definition crypto_sign.h:61
Type
The kind of key, which fixes the signature schemes it can produce.
Definition crypto_sign.h:36
Definition crypto_sign.h:33
auto SOURCEMETA_CORE_CRYPTO_EXPORT derive_public_key(const PrivateKey &key) -> std::optional< PublicKey >
auto SOURCEMETA_CORE_CRYPTO_EXPORT eddsa_sign(const PrivateKey &key, const std::string_view message) -> std::optional< std::string >
auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pkcs1_v15_sign(const PrivateKey &key, const SignatureHashFunction hash, const std::string_view message) -> std::optional< std::string >
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_edwards_private_key(const EdwardsCurve curve, const std::string_view seed) -> std::optional< PrivateKey >
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_private_key(const std::string_view pem) -> std::optional< PrivateKey >
EllipticCurve
Definition crypto_verify.h:28
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_rsa_private_key(const std::string_view modulus, const std::string_view public_exponent, const std::string_view private_exponent, const std::string_view prime1, const std::string_view prime2, const std::string_view exponent1, const std::string_view exponent2, const std::string_view coefficient) -> std::optional< PrivateKey >
auto SOURCEMETA_CORE_CRYPTO_EXPORT ecdsa_sign(const PrivateKey &key, const SignatureHashFunction hash, const std::string_view message) -> std::optional< std::string >
SignatureHashFunction
Definition crypto_verify.h:17
EdwardsCurve
Definition crypto_verify.h:39
auto SOURCEMETA_CORE_CRYPTO_EXPORT generate_ec_private_key(const EllipticCurve curve) -> std::optional< PrivateKey >
auto SOURCEMETA_CORE_CRYPTO_EXPORT rsassa_pss_sign(const PrivateKey &key, const SignatureHashFunction hash, const std::string_view message) -> std::optional< std::string >
auto SOURCEMETA_CORE_CRYPTO_EXPORT make_ec_private_key(const EllipticCurve curve, const std::string_view scalar, const std::string_view coordinate_x, const std::string_view coordinate_y) -> std::optional< PrivateKey >