78 lines
2.2 KiB
C
78 lines
2.2 KiB
C
#ifndef SSHCRYPT_H
|
|
#define SSHCRYPT_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#define SCR_VERSION 1
|
|
#define SCR_SUITE_X25519 1
|
|
#define SCR_SUITE_RSA 2
|
|
|
|
#define SCR_FP_LEN 32
|
|
#define SCR_NONCE_LEN 12
|
|
#define SCR_TAG_LEN 16
|
|
#define SCR_HDR_LEN 40 /* magic4 version1 suite1 reserved2 fingerprint32 */
|
|
#define SCR_PUB_MAX 4096
|
|
#define SCR_INPUT_MAX (1024u * 1024u * 1024u)
|
|
|
|
#define SCR_OK 0
|
|
#define SCR_EUSAGE 1
|
|
#define SCR_EIO 1
|
|
#define SCR_EDATA 2
|
|
#define SCR_EAUTH 3
|
|
|
|
struct buf {
|
|
unsigned char *data;
|
|
size_t len;
|
|
};
|
|
|
|
/* util.c */
|
|
void scr_die(int code, const char *fmt, ...);
|
|
void *scr_xmalloc(size_t n);
|
|
void *scr_xrealloc(void *p, size_t n);
|
|
char *scr_xstrdup(const char *s);
|
|
void scr_secure_zero(void *p, size_t n);
|
|
struct buf scr_read_fd(int fd, size_t max, const char *what);
|
|
struct buf scr_read_file(const char *path, size_t max);
|
|
void scr_write_fd(int fd, const void *p, size_t n);
|
|
int scr_b64_encode(const unsigned char *in, size_t n, char **out);
|
|
int scr_b64_decode(const char *in, size_t n, struct buf *out);
|
|
|
|
/* armor.c */
|
|
int scr_armor_wrap(const unsigned char *in, size_t n, char **out);
|
|
int scr_armor_unwrap(const unsigned char *in, size_t n, struct buf *out);
|
|
|
|
/* keys.c */
|
|
struct scr_pub {
|
|
int suite;
|
|
unsigned char blob[SCR_PUB_MAX];
|
|
size_t bloblen;
|
|
unsigned char ed[32];
|
|
void *rsa; /* EVP_PKEY * */
|
|
char fingerprint[64];
|
|
};
|
|
|
|
struct scr_priv {
|
|
int suite;
|
|
unsigned char ed_scalar[32]; /* x25519 scalar from the ed25519 seed */
|
|
unsigned char ed_pub[32];
|
|
void *rsa; /* EVP_PKEY * */
|
|
unsigned char blob[SCR_PUB_MAX];
|
|
size_t bloblen;
|
|
char fingerprint[64];
|
|
};
|
|
|
|
int scr_pub_load_any(const char *path, struct scr_pub *out);
|
|
void scr_pub_free(struct scr_pub *k);
|
|
int scr_priv_load(const char *path, struct scr_priv *out);
|
|
void scr_priv_free(struct scr_priv *k);
|
|
void scr_fingerprint(const unsigned char *blob, size_t n, char out[64]);
|
|
int scr_ed25519_pk_to_x25519(const unsigned char ed[32], unsigned char out[32]);
|
|
|
|
/* envelope.c */
|
|
int scr_encrypt(const struct scr_pub *to, const unsigned char *pt, size_t n,
|
|
struct buf *out);
|
|
int scr_decrypt(const struct scr_priv *me, const unsigned char *env, size_t n,
|
|
struct buf *out);
|
|
|
|
#endif
|