2018-02-03 18:22:01 -08:00
|
|
|
|
// Matrix Construct
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
|
//
|
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-10-01 03:05:09 -07:00
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#define HAVE_IRCD_ED25519_H
|
|
|
|
|
|
2018-05-21 03:01:40 -07:00
|
|
|
|
/// y^2 = x^3 + 486662x^2 + x GF(2^255 − 19)
|
2017-10-01 03:05:09 -07:00
|
|
|
|
namespace ircd::ed25519
|
|
|
|
|
{
|
2017-10-15 21:14:38 -07:00
|
|
|
|
IRCD_EXCEPTION(ircd::error, error)
|
|
|
|
|
IRCD_EXCEPTION(error, bad_sig)
|
|
|
|
|
|
2017-10-03 03:57:18 -07:00
|
|
|
|
const size_t SK_SZ { 32 + 32 };
|
2017-10-01 03:05:09 -07:00
|
|
|
|
const size_t PK_SZ { 32 };
|
|
|
|
|
const size_t SIG_SZ { 64 };
|
2017-10-03 03:57:18 -07:00
|
|
|
|
const size_t SEED_SZ { 32 };
|
2017-10-01 03:05:09 -07:00
|
|
|
|
|
|
|
|
|
struct pk;
|
|
|
|
|
struct sk;
|
|
|
|
|
struct sig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ircd::ed25519::sk
|
|
|
|
|
{
|
|
|
|
|
std::unique_ptr<uint8_t[], void (*)(void *)> key;
|
|
|
|
|
|
|
|
|
|
public:
|
2020-09-10 22:44:09 -07:00
|
|
|
|
operator bool() const { return bool(key); }
|
|
|
|
|
bool operator!() const { return !key; }
|
|
|
|
|
|
2018-02-02 23:20:26 -08:00
|
|
|
|
sig sign(const const_buffer &msg) const;
|
2017-10-01 03:05:09 -07:00
|
|
|
|
|
2020-09-15 17:40:10 -07:00
|
|
|
|
sk(const string_view &filename, pk *const & = nullptr, const bool &create = false);
|
2018-02-02 23:20:26 -08:00
|
|
|
|
sk(pk *const &, const const_buffer &seed);
|
2017-10-03 03:57:18 -07:00
|
|
|
|
sk(): key{nullptr, std::free} {}
|
2017-10-01 03:05:09 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ircd::ed25519::pk
|
2018-02-02 23:20:26 -08:00
|
|
|
|
:fixed_mutable_buffer<PK_SZ>
|
2017-10-01 03:05:09 -07:00
|
|
|
|
{
|
2018-02-02 23:20:26 -08:00
|
|
|
|
bool verify(const const_buffer &msg, const sig &) const;
|
2017-10-01 03:05:09 -07:00
|
|
|
|
|
2018-02-02 23:20:26 -08:00
|
|
|
|
using fixed_mutable_buffer<PK_SZ>::fixed_mutable_buffer;
|
2017-10-05 18:33:10 -07:00
|
|
|
|
|
|
|
|
|
pk()
|
2018-02-02 23:20:26 -08:00
|
|
|
|
:fixed_mutable_buffer<PK_SZ>{nullptr}
|
2017-10-05 18:33:10 -07:00
|
|
|
|
{}
|
2017-10-01 03:05:09 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ircd::ed25519::sig
|
2018-02-02 23:20:26 -08:00
|
|
|
|
:fixed_mutable_buffer<SIG_SZ>
|
2017-10-01 03:05:09 -07:00
|
|
|
|
{
|
2018-02-02 23:20:26 -08:00
|
|
|
|
using fixed_mutable_buffer<SIG_SZ>::fixed_mutable_buffer;
|
2017-10-05 18:33:10 -07:00
|
|
|
|
|
|
|
|
|
sig()
|
2018-02-02 23:20:26 -08:00
|
|
|
|
:fixed_mutable_buffer<SIG_SZ>{nullptr}
|
2017-10-05 18:33:10 -07:00
|
|
|
|
{}
|
2017-10-01 03:05:09 -07:00
|
|
|
|
};
|