1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
* (C) 2019 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/sodium.h>
#include <botan/ed25519.h>
#include <botan/curve25519.h>
namespace Botan {
int Sodium::crypto_scalarmult_curve25519(uint8_t out[32], const uint8_t scalar[32], const uint8_t point[32])
{
curve25519_donna(out, scalar, point);
return 0;
}
int Sodium::crypto_scalarmult_curve25519_base(uint8_t out[32], const uint8_t scalar[32])
{
curve25519_basepoint(out, scalar);
return 0;
}
int Sodium::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])
{
ed25519_sign(sig, msg, msg_len, sk, nullptr, 0);
if(sig_len)
*sig_len = 64;
return 0;
}
int Sodium::crypto_sign_ed25519_verify_detached(const uint8_t sig[],
const uint8_t msg[],
size_t msg_len,
const uint8_t pk[32])
{
const bool ok = ed25519_verify(msg, msg_len, sig, pk, nullptr, 0);
return ok ? 0 : -1;
}
int Sodium::crypto_sign_ed25519_keypair(uint8_t pk[32], uint8_t sk[64])
{
secure_vector<uint8_t> seed(32);
randombytes_buf(seed.data(), seed.size());
return crypto_sign_ed25519_seed_keypair(pk, sk, seed.data());
}
int Sodium::crypto_sign_ed25519_seed_keypair(uint8_t pk[], uint8_t sk[],
const uint8_t seed[])
{
ed25519_gen_keypair(pk, sk, seed);
return 0;
}
}
|