ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
keys.c File Reference

Go to the source code of this file.

Macros

#define CRYPTO_KEYS_HEADER_BUFFER_SIZE   50

Functions

asciichat_error_t parse_public_key (const char *input, public_key_t *key_out)
 Parse SSH/GPG public key from any format (returns first key only).
asciichat_error_t parse_private_key (const char *key_path, private_key_t *key_out)
 Parse SSH private key from file.
asciichat_error_t parse_public_keys (const char *input, public_key_t *keys_out, size_t *num_keys, size_t max_keys)
 Parse all SSH/GPG public keys from any format (returns all keys).
asciichat_error_t public_key_to_x25519 (const public_key_t *key, uint8_t x25519_pk[X25519_KEY_SIZE])
asciichat_error_t private_key_to_x25519 (const private_key_t *key, uint8_t x25519_sk[X25519_KEY_SIZE])
asciichat_error_t fetch_github_keys (const char *username, char ***keys_out, size_t *num_keys, bool use_gpg)
 Fetch SSH/GPG keys from GitHub using BearSSL.
asciichat_error_t fetch_gitlab_keys (const char *username, char ***keys_out, size_t *num_keys, bool use_gpg)
 Fetch SSH/GPG keys from GitLab using BearSSL.
asciichat_error_t parse_keys_from_file (const char *path, public_key_t *keys, size_t *num_keys, size_t max_keys)
 Parse SSH keys from file (supports authorized_keys and known_hosts formats).
void format_public_key (const public_key_t *key, char *output, size_t output_size)
 Convert public key to display format (ssh-ed25519 or x25519 hex).
asciichat_error_t hex_decode (const char *hex, uint8_t *output, size_t output_len)
 Decode hex string to binary (utility function for testing).

Macro Definition Documentation

◆ CRYPTO_KEYS_HEADER_BUFFER_SIZE

#define CRYPTO_KEYS_HEADER_BUFFER_SIZE   50

Definition at line 8 of file keys.c.

Referenced by parse_private_key().

Function Documentation

◆ private_key_to_x25519()

asciichat_error_t private_key_to_x25519 ( const private_key_t * key,
uint8_t x25519_sk[X25519_KEY_SIZE] )

Definition at line 548 of file keys.c.

548 {
549 if (!key || !x25519_sk) {
550 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters");
551 }
552
553 if (key->type == KEY_TYPE_X25519) {
554 // Passthrough for X25519 keys
555 memcpy(x25519_sk, key->key.x25519, X25519_KEY_SIZE);
556 return ASCIICHAT_OK;
557 }
558
559 if (key->type == KEY_TYPE_ED25519) {
560 // Convert Ed25519 to X25519 (Ed25519 private key is 64 bytes: seed + public)
561 return ed25519_to_x25519_private(key->key.ed25519, x25519_sk);
562 }
563
564 return SET_ERRNO(ERROR_CRYPTO_KEY, "Unsupported key type for X25519 conversion: %d", key->type);
565}
#define SET_ERRNO(code,...)
@ ERROR_CRYPTO_KEY
Definition error_codes.h:98
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
uint8_t ed25519[ED25519_PRIVATE_KEY_SIZE]
Definition key_types.h:104
key_type_t type
Definition key_types.h:102
uint8_t x25519[X25519_KEY_SIZE]
Definition key_types.h:105
union private_key_t::@040247167361101132173265304166142033301213115260 key
@ KEY_TYPE_ED25519
Definition key_types.h:58
@ KEY_TYPE_X25519
Definition key_types.h:59
#define X25519_KEY_SIZE
X25519 key size in bytes.
Definition sizes.h:35
asciichat_error_t ed25519_to_x25519_private(const uint8_t ed25519_sk[ED25519_PRIVATE_KEY_SIZE], uint8_t x25519_sk[X25519_KEY_SIZE])
Definition ssh_keys.c:1092

References ASCIICHAT_OK, private_key_t::ed25519, ed25519_to_x25519_private(), ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, private_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_X25519, SET_ERRNO, private_key_t::type, private_key_t::x25519, and X25519_KEY_SIZE.

◆ public_key_to_x25519()

asciichat_error_t public_key_to_x25519 ( const public_key_t * key,
uint8_t x25519_pk[X25519_KEY_SIZE] )

Definition at line 529 of file keys.c.

529 {
530 if (!key || !x25519_pk) {
531 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters");
532 }
533
534 if (key->type == KEY_TYPE_X25519) {
535 // Passthrough for X25519 keys
536 memcpy(x25519_pk, key->key, X25519_KEY_SIZE);
537 return ASCIICHAT_OK;
538 }
539
540 if (key->type == KEY_TYPE_ED25519) {
541 // Convert Ed25519 to X25519
542 return ed25519_to_x25519_public(key->key, x25519_pk);
543 }
544
545 return SET_ERRNO(ERROR_CRYPTO_KEY, "Unsupported key type for X25519 conversion: %d", key->type);
546}
uint8_t key[CRYPTO_PUBLIC_KEY_SIZE]
Definition key_types.h:78
key_type_t type
Definition key_types.h:77
asciichat_error_t ed25519_to_x25519_public(const uint8_t ed25519_pk[ED25519_PUBLIC_KEY_SIZE], uint8_t x25519_pk[X25519_KEY_SIZE])
Definition ssh_keys.c:1079

References ASCIICHAT_OK, ed25519_to_x25519_public(), ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, public_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_X25519, SET_ERRNO, public_key_t::type, and X25519_KEY_SIZE.