-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsalty.h
129 lines (111 loc) · 4.42 KB
/
salty.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef salty_h
#define salty_h
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define salty_FIELD_ELEMENT_LENGTH 32
#define salty_PUBLICKEY_SERIALIZED_LENGTH 32
#define salty_SECRETKEY_SEED_LENGTH 32
#define salty_SIGNATURE_SERIALIZED_LENGTH 64
#define salty_SHA512_LENGTH 64
/**
* Size of an encoded Ed25519 signature in bytes.
*/
#define salty_Signature_BYTE_SIZE 64
/**
* Extensible error type for all `salty` operations.
*
* This enum has a hidden member, to prevent exhaustively checking for errors.
* It also has a member `NoError` with value zero, for use in the C API.
*/
typedef enum salty_Error {
/**
* Never occurs, simplifies C bindings
*/
NoError = 0,
/**
* Bytes do not correspond to a canonical base field element
*/
NonCanonicalFieldElement,
/**
* Public key bytes invalid
*/
PublicKeyBytesInvalid,
/**
* Signature verification failed
*/
SignatureInvalid,
/**
* Context for prehashed signatures too long
*/
ContextTooLong,
/**
* Point is on other twist of curve
*/
WrongTwist,
_Extensible,
} salty_Error;
/**
* Generates a public key from a secret seed. Use to verify signatures.
*/
void salty_public_key(const uint8_t (*seed)[salty_SECRETKEY_SEED_LENGTH],
uint8_t (*public_key)[salty_PUBLICKEY_SERIALIZED_LENGTH]);
/**
* Signs the data, based on the keypair generated from the secret seed.
*/
void salty_sign(const uint8_t (*seed)[salty_SECRETKEY_SEED_LENGTH],
const uint8_t *data_ptr,
uintptr_t data_len,
uint8_t (*signature)[salty_SIGNATURE_SERIALIZED_LENGTH]);
/**
* Signs the data for a given context, based on the keypair generated
* from the secret seed.
*/
enum salty_Error salty_sign_with_context(const uint8_t (*seed)[salty_SECRETKEY_SEED_LENGTH],
const uint8_t *data_ptr,
uintptr_t data_len,
const uint8_t *context_ptr,
uintptr_t context_len,
uint8_t (*signature)[salty_SIGNATURE_SERIALIZED_LENGTH]);
/**
* Signs the prehashed data, based on the keypair generated from the secret seed.
* An optional context can also be passed (this is recommended).
*/
enum salty_Error salty_sign_prehashed(const uint8_t (*seed)[salty_SECRETKEY_SEED_LENGTH],
const uint8_t (*prehashed_data)[salty_SHA512_LENGTH],
const uint8_t *context_ptr,
uintptr_t context_len,
uint8_t (*signature)[salty_SIGNATURE_SERIALIZED_LENGTH]);
/**
* Verify a presumed signature on the given data.
*/
enum salty_Error salty_verify(const uint8_t (*public_key)[salty_PUBLICKEY_SERIALIZED_LENGTH],
const uint8_t *data_ptr,
uintptr_t data_len,
const uint8_t (*signature)[salty_SIGNATURE_SERIALIZED_LENGTH]);
/**
* Verify a presumed signature on the given data.
*/
enum salty_Error salty_verify_with_context(const uint8_t (*public_key)[salty_PUBLICKEY_SERIALIZED_LENGTH],
const uint8_t *data_ptr,
uintptr_t data_len,
const uint8_t (*signature)[salty_SIGNATURE_SERIALIZED_LENGTH],
const uint8_t *context_ptr,
uintptr_t context_len);
/**
* Verify a presumed signature on the given data.
*/
enum salty_Error salty_verify_prehashed(const uint8_t (*public_key)[salty_PUBLICKEY_SERIALIZED_LENGTH],
const uint8_t (*prehashed_data)[salty_SHA512_LENGTH],
const uint8_t (*signature)[salty_SIGNATURE_SERIALIZED_LENGTH],
const uint8_t *context_ptr,
uintptr_t context_len);
/**
* Perform X25519 key agreement.
*/
void salty_agree(const uint8_t (*scalar)[salty_SECRETKEY_SEED_LENGTH],
const uint8_t (*input_u)[salty_FIELD_ELEMENT_LENGTH],
uint8_t (*output_u)[salty_FIELD_ELEMENT_LENGTH]);
#endif /* salty_h */