Botan 3.6.1
Crypto and TLS for C&
sodium_25519.cpp
Go to the documentation of this file.
1/*
2* (C) 2019 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/sodium.h>
8
9#include <botan/ed25519.h>
10#include <botan/x25519.h>
11
12namespace Botan {
13
14int Sodium::crypto_scalarmult_curve25519(uint8_t out[32], const uint8_t scalar[32], const uint8_t point[32]) {
15 curve25519_donna(out, scalar, point);
16 return 0;
17}
18
19int Sodium::crypto_scalarmult_curve25519_base(uint8_t out[32], const uint8_t scalar[32]) {
20 curve25519_basepoint(out, scalar);
21 return 0;
22}
23
25 uint8_t sig[], unsigned long long* sig_len, const uint8_t msg[], size_t msg_len, const uint8_t sk[32]) {
26 ed25519_sign(sig, msg, msg_len, sk, nullptr, 0);
27
28 if(sig_len) {
29 *sig_len = 64;
30 }
31 return 0;
32}
33
35 const uint8_t msg[],
36 size_t msg_len,
37 const uint8_t pk[32]) {
38 const bool ok = ed25519_verify(msg, msg_len, sig, pk, nullptr, 0);
39 return ok ? 0 : -1;
40}
41
42int Sodium::crypto_sign_ed25519_keypair(uint8_t pk[32], uint8_t sk[64]) {
44 randombytes_buf(seed.data(), seed.size());
45 return crypto_sign_ed25519_seed_keypair(pk, sk, seed.data());
46}
47
48int Sodium::crypto_sign_ed25519_seed_keypair(uint8_t pk[], uint8_t sk[], const uint8_t seed[]) {
49 ed25519_gen_keypair(pk, sk, seed);
50 return 0;
51}
52
53} // namespace Botan
int crypto_sign_ed25519_verify_detached(const uint8_t sig[], const uint8_t msg[], size_t msg_len, const uint8_t pk[32])
int crypto_scalarmult_curve25519(uint8_t out[32], const uint8_t scalar[32], const uint8_t basepoint[32])
int crypto_sign_ed25519_detached(uint8_t sig[], unsigned long long *sig_len, const uint8_t msg[], size_t msg_len, const uint8_t sk[32])
int crypto_scalarmult_curve25519_base(uint8_t out[32], const uint8_t scalar[32])
int crypto_sign_ed25519_keypair(uint8_t pk[32], uint8_t sk[64])
int crypto_sign_ed25519_seed_keypair(uint8_t pk[], uint8_t sk[], const uint8_t seed[])
void randombytes_buf(void *buf, size_t size)
void ed25519_sign(uint8_t sig[64], const uint8_t m[], size_t mlen, const uint8_t sk[64], const uint8_t domain_sep[], size_t domain_sep_len)
Definition ed25519.cpp:37
void ed25519_gen_keypair(uint8_t *pk, uint8_t *sk, const uint8_t seed[32])
Definition ed25519.cpp:20
void curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])
Definition donna.cpp:454
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
bool ed25519_verify(const uint8_t *m, size_t mlen, const uint8_t sig[64], const uint8_t *pk, const uint8_t domain_sep[], size_t domain_sep_len)
Definition ed25519.cpp:73
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32])
Definition x25519.cpp:19