15 #ifndef __DECAF_ED448_HXX__
16 #define __DECAF_ED448_HXX__ 1
33 #if __cplusplus >= 201103L
34 #define DECAF_NOEXCEPT noexcept
36 #define DECAF_NOEXCEPT throw()
44 template <
typename Group>
struct EdDSA;
50 template<
class CRTP, Prehashed>
class Signing;
51 template<
class CRTP, Prehashed>
class Verification;
54 typedef class PrivateKeyBase PrivateKey, PrivateKeyPure, PrivateKeyPh;
55 typedef class PublicKeyBase PublicKey, PublicKeyPure, PublicKeyPh;
66 #if DECAF_EDDSA_448_SUPPORTS_CONTEXTLESS_SIGS
67 static inline const Block NO_CONTEXT() {
return Block(DECAF_ED448_NO_CONTEXT,0); }
73 class Prehash :
public SHAKE<256> {
78 template<
class T, Prehashed Ph>
friend class Signing;
79 template<
class T, Prehashed Ph>
friend class Verification;
84 if (context_.size() > 255) {
94 static const size_t OUTPUT_BYTES = Super::DEFAULT_OUTPUT_BYTES;
103 void reset() DECAF_NOEXCEPT { init(); }
121 template<
class CRTP, Prehashed ph>
class Signing;
124 template<
class CRTP>
class Signing<CRTP,
PURE> {
134 const Block &message,
135 const Block &context = NO_CONTEXT()
137 if (context.size() > 255) {
144 ((
const CRTP*)
this)->keypair_,
149 static_cast<uint8_t
>(context.size())
163 ((
const CRTP*)
this)->keypair_,
166 static_cast<uint8_t
>(ph.context_.size())
173 const Block &message,
174 const Block &context = NO_CONTEXT()
178 return sign_prehashed(ph);
185 ,
public Signing<PrivateKeyBase,PURE>
186 ,
public Signing<PrivateKeyBase,PREHASHED> {
192 friend class PublicKeyBase;
193 friend class Signing<PrivateKey,
PURE>;
194 friend class Signing<PrivateKey,
PREHASHED>;
198 decaf_eddsa_448_keypair_t keypair_;
227 inline PrivateKeyBase &
operator=(
const PrivateKey &k) DECAF_NOEXCEPT {
228 memcpy(keypair_,k.keypair_,
sizeof(keypair_));
242 inline size_t ser_size() const DECAF_NOEXCEPT {
return SER_BYTES; }
253 serialize_into(priv.
data());
266 template<
class CRTP>
class Verification<CRTP,
PURE> {
271 const Block &message,
272 const Block &context = NO_CONTEXT()
274 if (context.size() > 255) {
280 ((
const CRTP*)
this)->pub_.data(),
285 static_cast<uint8_t
>(context.size())
298 const Block &message,
299 const Block &context = NO_CONTEXT()
301 if (context.size() > 255) {
305 if (
DECAF_SUCCESS != verify_noexcept( sig, message, context )) {
312 template<
class CRTP>
class Verification<CRTP,
PREHASHED> {
321 ((
const CRTP*)
this)->pub_.data(),
335 ((
const CRTP*)
this)->pub_.data(),
338 static_cast<uint8_t
>(ph.context_.size())
345 inline void verify_with_prehash (
347 const Block &message,
348 const Block &context = NO_CONTEXT()
352 verify_prehashed(sig,ph);
359 ,
public Verification<PublicKeyBase,PURE>
360 ,
public Verification<PublicKeyBase,PREHASHED> {
367 friend class PrivateKeyBase;
368 friend class Verification<PublicKey,
PURE>;
369 friend class Verification<PublicKey,
PREHASHED>;
402 memcpy(pub_.
data(),b.data(),b.size());
407 inline PublicKey &
operator=(
const PublicKey &p) DECAF_NOEXCEPT {
408 return *
this = p.pub_;
418 inline size_t ser_size() const DECAF_NOEXCEPT {
return SER_BYTES; }
435 #undef DECAF_NOEXCEPT
A reference to a block of data, which (when accessed through this base class) is const.
Definition: secure_buffer.hxx:159
size_t size() const DECAF_NOEXCEPT
Get the size.
Definition: secure_buffer.hxx:208
const unsigned char * data() const DECAF_NOEXCEPT
Get const data.
Definition: secure_buffer.hxx:199
A reference to a writable block of data.
Definition: secure_buffer.hxx:270
const unsigned char * data() const DECAF_NOEXCEPT
Get const data.
Definition: secure_buffer.hxx:282
An exception for when crypto (ie point decode) has failed.
Definition: secure_buffer.hxx:119
void reset() DECAF_NOEXCEPT
Reset this hash.
Definition: ed448.hxx:103
Prehash(const Block &context=NO_CONTEXT())
Create the prehash.
Definition: ed448.hxx:97
void serialize_into(unsigned char *x) const DECAF_NOEXCEPT
Serialize into a buffer.
Definition: ed448.hxx:245
PrivateKeyBase & operator=(const PrivateKey &k) DECAF_NOEXCEPT
Copy assignment.
Definition: ed448.hxx:227
~PrivateKeyBase()
Create at random.
Definition: ed448.hxx:233
PrivateKeyBase & operator=(const FixedBlock< SER_BYTES > &b) DECAF_NOEXCEPT
Assignment from string.
Definition: ed448.hxx:236
PrivateKeyBase(const FixedBlock< SER_BYTES > &b) DECAF_NOEXCEPT
Read a private key from a string.
Definition: ed448.hxx:215
PrivateKeyBase(const PrivateKeyBase &k) DECAF_NOEXCEPT
Copy constructor.
Definition: ed448.hxx:218
size_t ser_size() const DECAF_NOEXCEPT
Serialization size.
Definition: ed448.hxx:242
class PublicKeyBase PublicKey
Type of public key corresponding to this private key.
Definition: ed448.hxx:189
PrivateKeyBase(Rng &r) DECAF_NOEXCEPT
Create at random.
Definition: ed448.hxx:221
PublicKey pub() const DECAF_NOEXCEPT
Return the corresponding public key.
Definition: ed448.hxx:259
PrivateKeyBase(const NOINIT &) DECAF_NOEXCEPT
Create but don't initialize.
Definition: ed448.hxx:212
Ed448Goldilocks Group
Underlying group.
Definition: ed448.hxx:202
SecureBuffer convert_to_x() const
Convert to X format (to be used for key exchange)
Definition: ed448.hxx:250
PublicKey & operator=(const PrivateKey &p) DECAF_NOEXCEPT
Assignment from private key.
Definition: ed448.hxx:412
PublicKeyBase(const NOINIT &) DECAF_NOEXCEPT
Create but don't initialize.
Definition: ed448.hxx:389
SecureBuffer convert_to_x() const
Convert to X format (to be used for key exchange)
Definition: ed448.hxx:426
PublicKeyBase(const PublicKeyBase &k) DECAF_NOEXCEPT
Copy constructor.
Definition: ed448.hxx:395
class PrivateKeyBase PrivateKey
Private key corresponding to this type of public key.
Definition: ed448.hxx:363
PublicKeyBase(const FixedBlock< SER_BYTES > &b) DECAF_NOEXCEPT
Read a private key from a string.
Definition: ed448.hxx:392
PublicKey & operator=(const PublicKey &p) DECAF_NOEXCEPT
Assignment from public key.
Definition: ed448.hxx:407
PublicKeyBase(const PrivateKey &k) DECAF_NOEXCEPT
Copy constructor.
Definition: ed448.hxx:398
Ed448Goldilocks Group
Underlying group.
Definition: ed448.hxx:380
void serialize_into(unsigned char *x) const DECAF_NOEXCEPT
Serialize into a buffer.
Definition: ed448.hxx:421
PublicKey & operator=(const FixedBlock< SER_BYTES > &b) DECAF_NOEXCEPT
Assignment from string.
Definition: ed448.hxx:401
size_t ser_size() const DECAF_NOEXCEPT
Serialization size.
Definition: ed448.hxx:418
SecureBuffer sign_prehashed(const Prehash &ph) const
Sign a prehash context, and reset the context.
Definition: ed448.hxx:159
SecureBuffer sign(const Block &message, const Block &context=NO_CONTEXT()) const
Sign a message.
Definition: ed448.hxx:133
decaf_error_t DECAF_WARN_UNUSED verify_prehashed_noexcept(const FixedBlock< DECAF_EDDSA_448_SIGNATURE_BYTES > &sig, const Prehash &ph) const
Verify that a signature is valid for a given prehashed message, given the context.
Definition: ed448.hxx:315
void verify_prehashed(const FixedBlock< DECAF_EDDSA_448_SIGNATURE_BYTES > &sig, const Prehash &ph) const
Verify that a signature is valid for a given prehashed message, given the context.
Definition: ed448.hxx:329
decaf_error_t DECAF_WARN_UNUSED verify_noexcept(const FixedBlock< DECAF_EDDSA_448_SIGNATURE_BYTES > &sig, const Block &message, const Block &context=NO_CONTEXT()) const
Verify a signature, returning DECAF_FAILURE if verification fails.
Definition: ed448.hxx:269
void verify(const FixedBlock< DECAF_EDDSA_448_SIGNATURE_BYTES > &sig, const Block &message, const Block &context=NO_CONTEXT()) const
Verify a signature, throwing an exception if verification fails.
Definition: ed448.hxx:296
A fixed-size stack-allocated buffer (for DECAF_NOEXCEPT semantics)
Definition: secure_buffer.hxx:337
A fixed-size block.
Definition: secure_buffer.hxx:253
An exception for when crypto (ie point decode) has failed.
Definition: secure_buffer.hxx:126
Prototype of a random number generator.
Definition: secure_buffer.hxx:138
Variable-output-length SHAKE.
Definition: shake.hxx:151
Base class of objects which support serialization.
Definition: secure_buffer.hxx:89
decaf_error_t
Another boolean type used to indicate success or failure.
Definition: common.h:120
@ DECAF_FAILURE
The operation failed.
Definition: common.h:122
@ DECAF_SUCCESS
The operation succeeded.
Definition: common.h:121
A group of prime order p, based on Ed448-Goldilocks.
void DECAF_API_VIS decaf_ed448_keypair_extract_public_key(uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES], const decaf_eddsa_448_keypair_t keypair) DECAF_NONNULL DECAF_NOINLINE
Extract the public key from an EdDSA keypair.
decaf_error_t DECAF_API_VIS decaf_ed448_verify_prehash(const uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES], const uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES], const decaf_ed448_prehash_ctx_t hash, const uint8_t *context, uint8_t context_len) DECAF_NOINLINE
EdDSA signature verification.
void DECAF_API_VIS decaf_ed448_keypair_sign(uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES], const decaf_eddsa_448_keypair_t keypair, const uint8_t *message, size_t message_len, uint8_t prehashed, const uint8_t *context, uint8_t context_len) DECAF_NOINLINE
EdDSA signing.
#define decaf_ed448_prehash_ctx_s
Prehash context (raw), because each EdDSA instance has a different prehash.
Definition: ed448.h:45
#define DECAF_EDDSA_448_SIGNATURE_BYTES
Number of bytes in an EdDSA private key.
Definition: ed448.h:33
#define DECAF_EDDSA_448_PRIVATE_BYTES
Number of bytes in an EdDSA private key.
Definition: ed448.h:30
void DECAF_API_VIS decaf_ed448_keypair_extract_private_key(uint8_t privkey[DECAF_EDDSA_448_PRIVATE_BYTES], const decaf_eddsa_448_keypair_t keypair) DECAF_NONNULL DECAF_NOINLINE
Extract the private key from an EdDSA keypair.
void DECAF_API_VIS decaf_ed448_keypair_destroy(decaf_eddsa_448_keypair_t keypair) DECAF_NONNULL DECAF_NOINLINE
EdDSA keypair destructor.
decaf_error_t DECAF_API_VIS decaf_ed448_verify(const uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES], const uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES], const uint8_t *message, size_t message_len, uint8_t prehashed, const uint8_t *context, uint8_t context_len) DECAF_NOINLINE
EdDSA signature verification.
void DECAF_API_VIS decaf_ed448_derive_keypair(decaf_eddsa_448_keypair_t keypair, const uint8_t privkey[DECAF_EDDSA_448_PRIVATE_BYTES]) DECAF_NONNULL DECAF_NOINLINE
EdDSA keypair scheduling.
void DECAF_API_VIS decaf_ed448_convert_private_key_to_x448(uint8_t x[DECAF_X448_PRIVATE_BYTES], const uint8_t ed[DECAF_EDDSA_448_PRIVATE_BYTES]) DECAF_NONNULL DECAF_NOINLINE
EdDSA to ECDH private key conversion Using the appropriate hash function, hash the EdDSA private key ...
void DECAF_API_VIS decaf_ed448_prehash_init(decaf_ed448_prehash_ctx_t hash) DECAF_NOINLINE
Prehash initialization, with contexts if supported.
void DECAF_API_VIS decaf_ed448_keypair_sign_prehash(uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES], const decaf_eddsa_448_keypair_t keypair, const decaf_ed448_prehash_ctx_t hash, const uint8_t *context, uint8_t context_len) DECAF_NOINLINE
EdDSA signing with prehash.
void decaf_ed448_convert_public_key_to_x448(uint8_t x[DECAF_X448_PUBLIC_BYTES], const uint8_t ed[DECAF_EDDSA_448_PUBLIC_BYTES])
EdDSA to ECDH public key conversion Deserialize the point to get y on Edwards curve,...
Definition: decaf.c:1335
Namespace for all libdecaf C++ objects.
Definition: ed255.hxx:41
std::vector< unsigned char, SanitizingAllocator< unsigned char, 0 > > SecureBuffer
A variant of std::vector which securely zerozes its state when destructed.
Definition: secure_buffer.hxx:79
@ PURE
Sign the message itself.
Definition: eddsa.hxx:22
@ PREHASHED
Sign the hash of the message.
Definition: eddsa.hxx:23
#define DECAF_X448_PRIVATE_BYTES
Number of bytes in an x448 private key.
Definition: point_448.h:65
SHA512 instance, C++ wrapper.
SHA-3-n and SHAKE-n instances, C++ wrapper.
Ed448-Goldilocks/Decaf instantiation of group.
Definition: point_448.hxx:55
static const Block NO_CONTEXT()
Signatures support a "context" block, which allows you to domain separate them if (for some reason) i...
Definition: ed448.hxx:69
A public key for crypto over some Group.
Definition: ed255.hxx:44
Passed to constructors to avoid (conservative) initialization.
Definition: secure_buffer.hxx:133