-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibcage.h
53 lines (47 loc) · 1.93 KB
/
libcage.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
#ifndef _LIBCAGE_H_
#define _LIBCAGE_H_
#include <stdint.h>
#include <stdio.h>
/* The implemented version of age. An arbitrary string.
*/
#define CAGE_AGE_VERSION "v1"
#define CAGE_RAW_PK_LEN 32
/* Raw bytes of an X25519 keypair.
*/
struct CageX25519Identity {
uint8_t public_key[CAGE_RAW_PK_LEN];
uint8_t secret_key[32];
};
/* An X25519 keypair in the standard human-readable age representation.
*/
struct CageHumanReadableX25519Identity {
uint8_t public_key[63];
uint8_t secret_key[75];
};
/* Returns a new X25519 age identity from a 32-byte scalar _scalar_ used as the private key. */
struct CageX25519Identity cage_new_x25519_identity_from_scalar(const uint8_t scalar[32]);
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
/* Assigns a new X25519 age identity to _kp_.
* On error, non-zero is returned, and errno is set to indiciate the error.
* This function only fails if the system's CSPRNG fails to retrieve suffient entropy.
* This function only exists on platforms with an established standard CSPRNG.
*/
int cage_generate_x25519_identity(struct CageX25519Identity *kp);
#endif
/* Parses a bech32-encoded age private key into an X25519 identity.
* On error, non-zero is returned, and errno is set to indicate the error.
* In particular, ENOTSUP is returned if the HRP is not "AGE-SECRET-KEY-"
*/
int cage_parse_x25519_identity(struct CageX25519Identity *out, const char bech32_sk[75]);
/* Returns the standard human-readable age representation of an X25519 keypair.
* _kp_ MUST be a valid keypair.
*/
struct CageHumanReadableX25519Identity cage_format_x25519_identity(
const struct CageX25519Identity *kp);
/* Decodes an X25519 public key in human-readable format into raw bytes.
* _out_ MUST be at least 32 bytes.
* On error, non-zero is returned.
*/
int cage_decode_x25519_pk(uint8_t *out, const char *pk);
int cage_encrypt_file(FILE *in, FILE *out, const int recipients_len, uint8_t *const *recipients);
#endif