This commit is contained in:
lw-everestlinux committed 2026-10-14 00:50:56 -04:00
1 parent ee4bcc3b77
commit ae54f74070
53 files changed
+8916 -1424

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
#ifndef GL_SIGN_H_
#define GL_SIGN_H_
/*
* gl_sign: Ed25519 signatures in OpenBSD signify's file formats
* (REPO_DESIGN.txt section 2). Private to libglacier_verify.so, like
* sha256.h: no public header is installed.
*
* Every file is two lines, "untrusted comment: ..." and base64 of:
* public key "Ed" | keynum[8] | pubkey[32]
* signature "Ed" | keynum[8] | sig[64]
* secret key "Ed" | "BK" | rounds[4, big-endian] | salt[16] |
* checksum[8] | keynum[8] | seckey[64]
* Only unencrypted secret keys (rounds == 0, `signify -G -n`) are
* read; an encrypted one is GL_SIGN_ERR_ENCRYPTED.
*
* Signatures are pure Ed25519 over the whole message, as signify's, so
* `signify -V -p KEY.pub -m FILE` checks what gl_sign_file makes and
* gl_sign_verify_file checks what signify makes.
*/
#include <stddef.h>
#include <stdint.h>
#define GL_SIGN_KEYNUM_SIZE 8
/* Largest message signed or verified: the whole file is read. */
#define GL_SIGN_MAX_MSG (64u * 1024u * 1024u)
/* Longest comment signify accepts. */
#define GL_SIGN_MAX_COMMENT 1024
typedef enum {
GL_SIGN_OK = 0,
GL_SIGN_ERR_IO = 1, /* a file can't be opened or read */
GL_SIGN_ERR_FORMAT = 2, /* not a well-formed file of the expected kind */
GL_SIGN_ERR_ENCRYPTED = 3, /* a passphrase-protected secret key */
GL_SIGN_ERR_KEYNUM = 4, /* the signature was made by another key */
GL_SIGN_ERR_BAD = 5, /* the signature does not verify */
GL_SIGN_ERR_TOOBIG = 6, /* message larger than GL_SIGN_MAX_MSG */
GL_SIGN_ERR_RANDOM = 7, /* no randomness for a new key */
GL_SIGN_ERR_EXISTS = 8, /* a key file to create already exists */
GL_SIGN_ERR_WRITE = 9, /* a file to write can't be created or written */
} gl_sign_status_t;
typedef struct {
uint8_t keynum[GL_SIGN_KEYNUM_SIZE];
uint8_t key[32];
} gl_sign_pubkey_t;
typedef struct {
uint8_t keynum[GL_SIGN_KEYNUM_SIZE];
uint8_t sig[64];
} gl_sign_sig_t;
int gl_sign_read_pubkey(const char *path, gl_sign_pubkey_t *out);
/* Reads a secret key only to check it (then wipes it). */
int gl_sign_check_seckey(const char *path);
int gl_sign_read_sig(const char *path, gl_sign_sig_t *out);
/* Checks `sig` over msg[0..len) with `pub`: GL_SIGN_ERR_KEYNUM before
* any crypto if the keynums differ, else GL_SIGN_OK or GL_SIGN_ERR_BAD. */
int gl_sign_verify(const gl_sign_pubkey_t *pub, const gl_sign_sig_t *sig,
const uint8_t *msg, size_t len);
/* Reads all three files and verifies. The status names the first
* problem found, in the order: public key, signature, message, check. */
int gl_sign_verify_file(const char *pubkey_path, const char *msg_path,
const char *sig_path);
/* Signs msg_path with the secret key, writing sig_path (replaced if it
* exists, never followed if it's a symlink). The signature's comment
* is "verify with NAME.pub", NAME being the secret key's file name
* without ".sec", as signify writes it. */
int gl_sign_file(const char *seckey_path, const char *msg_path,
const char *sig_path);
/* Makes a new keypair. Neither file may exist (GL_SIGN_ERR_EXISTS).
* The secret key is created 0600 and unencrypted; the comments are
* "COMMENT public key" / "COMMENT secret key". */
int gl_sign_generate(const char *pubkey_path, const char *seckey_path,
const char *comment);
#endif