diff options
Diffstat (limited to 'src/libcryptobox/keypair.h')
-rw-r--r-- | src/libcryptobox/keypair.h | 90 |
1 files changed, 52 insertions, 38 deletions
diff --git a/src/libcryptobox/keypair.h b/src/libcryptobox/keypair.h index 92af13b68..e2b20dc55 100644 --- a/src/libcryptobox/keypair.h +++ b/src/libcryptobox/keypair.h @@ -20,6 +20,10 @@ #include "cryptobox.h" #include "ucl.h" +#ifdef __cplusplus +extern "C" { +#endif + /** * Keypair type */ @@ -45,7 +49,7 @@ struct rspamd_cryptobox_pubkey; * @param alg algorithm for the keypair * @return fresh keypair generated */ -struct rspamd_cryptobox_keypair* rspamd_keypair_new ( +struct rspamd_cryptobox_keypair *rspamd_keypair_new ( enum rspamd_cryptobox_keypair_type type, enum rspamd_cryptobox_mode alg); @@ -54,7 +58,7 @@ struct rspamd_cryptobox_keypair* rspamd_keypair_new ( * @param kp * @return */ -struct rspamd_cryptobox_keypair* rspamd_keypair_ref ( +struct rspamd_cryptobox_keypair *rspamd_keypair_ref ( struct rspamd_cryptobox_keypair *kp); /** @@ -68,7 +72,7 @@ void rspamd_keypair_unref (struct rspamd_cryptobox_keypair *kp); * @param kp * @return */ -struct rspamd_cryptobox_pubkey* rspamd_pubkey_ref ( +struct rspamd_cryptobox_pubkey *rspamd_pubkey_ref ( struct rspamd_cryptobox_pubkey *kp); /** @@ -78,10 +82,10 @@ struct rspamd_cryptobox_pubkey* rspamd_pubkey_ref ( * @param alg algorithm of the key (nist or curve25519) * @return new pubkey or NULL in case of error */ -struct rspamd_cryptobox_pubkey* rspamd_pubkey_from_base32 (const gchar *b32, - gsize len, - enum rspamd_cryptobox_keypair_type type, - enum rspamd_cryptobox_mode alg); +struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_base32 (const gchar *b32, + gsize len, + enum rspamd_cryptobox_keypair_type type, + enum rspamd_cryptobox_mode alg); /** * Load pubkey from hex string @@ -90,10 +94,10 @@ struct rspamd_cryptobox_pubkey* rspamd_pubkey_from_base32 (const gchar *b32, * @param alg algorithm of the key (nist or curve25519) * @return new pubkey or NULL in case of error */ -struct rspamd_cryptobox_pubkey* rspamd_pubkey_from_hex (const gchar *hex, - gsize len, - enum rspamd_cryptobox_keypair_type type, - enum rspamd_cryptobox_mode alg); +struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_hex (const gchar *hex, + gsize len, + enum rspamd_cryptobox_keypair_type type, + enum rspamd_cryptobox_mode alg); /** * Load pubkey from raw chunk string @@ -102,10 +106,10 @@ struct rspamd_cryptobox_pubkey* rspamd_pubkey_from_hex (const gchar *hex, * @param alg algorithm of the key (nist or curve25519) * @return new pubkey or NULL in case of error */ -struct rspamd_cryptobox_pubkey* rspamd_pubkey_from_bin (const guchar *raw, - gsize len, - enum rspamd_cryptobox_keypair_type type, - enum rspamd_cryptobox_mode alg); +struct rspamd_cryptobox_pubkey *rspamd_pubkey_from_bin (const guchar *raw, + gsize len, + enum rspamd_cryptobox_keypair_type type, + enum rspamd_cryptobox_mode alg); /** @@ -119,6 +123,7 @@ void rspamd_pubkey_unref (struct rspamd_cryptobox_pubkey *kp); */ enum rspamd_cryptobox_keypair_type rspamd_keypair_type ( struct rspamd_cryptobox_keypair *kp); + /** * Get type of pubkey */ @@ -129,6 +134,7 @@ enum rspamd_cryptobox_keypair_type rspamd_pubkey_type ( * Get algorithm of keypair */ enum rspamd_cryptobox_mode rspamd_keypair_alg (struct rspamd_cryptobox_keypair *kp); + /** * Get algorithm of pubkey */ @@ -139,29 +145,30 @@ enum rspamd_cryptobox_mode rspamd_pubkey_alg (struct rspamd_cryptobox_pubkey *p) * @param p * @return */ -const guchar * rspamd_pubkey_get_nm (struct rspamd_cryptobox_pubkey *p, - struct rspamd_cryptobox_keypair *kp); +const guchar *rspamd_pubkey_get_nm (struct rspamd_cryptobox_pubkey *p, + struct rspamd_cryptobox_keypair *kp); /** * Calculate and store nm value for the specified local key (performs ECDH) * @param p * @return */ -const guchar * rspamd_pubkey_calculate_nm (struct rspamd_cryptobox_pubkey *p, - struct rspamd_cryptobox_keypair *kp); +const guchar *rspamd_pubkey_calculate_nm (struct rspamd_cryptobox_pubkey *p, + struct rspamd_cryptobox_keypair *kp); /** * Get raw public key id for a specified keypair (rspamd_cryptobox_HASHBYTES) * @param kp * @return */ -const guchar * rspamd_keypair_get_id (struct rspamd_cryptobox_keypair *kp); +const guchar *rspamd_keypair_get_id (struct rspamd_cryptobox_keypair *kp); + /** * Get raw public key id for a specified key (rspamd_cryptobox_HASHBYTES) * @param kp * @return */ -const guchar * rspamd_pubkey_get_id (struct rspamd_cryptobox_pubkey *pk); +const guchar *rspamd_pubkey_get_id (struct rspamd_cryptobox_pubkey *pk); /** * Get raw public key from pubkey opaque structure @@ -169,8 +176,8 @@ const guchar * rspamd_pubkey_get_id (struct rspamd_cryptobox_pubkey *pk); * @param len * @return */ -const guchar * rspamd_pubkey_get_pk (struct rspamd_cryptobox_pubkey *pk, - guint *len); +const guchar *rspamd_pubkey_get_pk (struct rspamd_cryptobox_pubkey *pk, + guint *len); /** Short ID characters count */ #define RSPAMD_KEYPAIR_SHORT_ID_LEN 5 @@ -187,6 +194,7 @@ const guchar * rspamd_pubkey_get_pk (struct rspamd_cryptobox_pubkey *pk, /** Human readable output */ #define RSPAMD_KEYPAIR_HUMAN 0x20 #define RSPAMD_KEYPAIR_HEX 0x40 + /** * Print keypair encoding it if needed * @param key key to print @@ -194,7 +202,7 @@ const guchar * rspamd_pubkey_get_pk (struct rspamd_cryptobox_pubkey *pk, * @return newly allocated string with keypair */ GString *rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, - guint how); + guint how); /** * Print pubkey encoding it if needed @@ -203,7 +211,7 @@ GString *rspamd_keypair_print (struct rspamd_cryptobox_keypair *kp, * @return newly allocated string with keypair */ GString *rspamd_pubkey_print (struct rspamd_cryptobox_pubkey *pk, - guint how); + guint how); /** Get keypair pubkey ID */ #define RSPAMD_KEYPAIR_COMPONENT_ID 0 @@ -211,6 +219,7 @@ GString *rspamd_pubkey_print (struct rspamd_cryptobox_pubkey *pk, #define RSPAMD_KEYPAIR_COMPONENT_PK 1 /** Get keypair private key */ #define RSPAMD_KEYPAIR_COMPONENT_SK 2 + /** * Get specific component of a keypair * @param kp keypair @@ -218,23 +227,23 @@ GString *rspamd_pubkey_print (struct rspamd_cryptobox_pubkey *pk, * @param len length of input * @return raw content of the component */ -const guchar * rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp, - guint ncomp, guint *len); +const guchar *rspamd_keypair_component (struct rspamd_cryptobox_keypair *kp, + guint ncomp, guint *len); /** * Create a new keypair from ucl object * @param obj object to load * @return new structure or NULL if an object is invalid */ -struct rspamd_cryptobox_keypair * rspamd_keypair_from_ucl (const ucl_object_t *obj); +struct rspamd_cryptobox_keypair *rspamd_keypair_from_ucl (const ucl_object_t *obj); /** * Converts keypair to ucl object * @param kp * @return */ -ucl_object_t * rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, - gboolean is_hex); +ucl_object_t *rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, + gboolean is_hex); /** * Signs memory using the specified keypair @@ -247,8 +256,8 @@ ucl_object_t * rspamd_keypair_to_ucl (struct rspamd_cryptobox_keypair *kp, * @return TRUE if signature operation succeeded */ gboolean rspamd_keypair_sign (struct rspamd_cryptobox_keypair *kp, - const void *data, gsize len, guchar **sig, gsize *outlen, - GError **err); + const void *data, gsize len, guchar **sig, gsize *outlen, + GError **err); /*** * Verifies data using public key @@ -261,8 +270,8 @@ gboolean rspamd_keypair_sign (struct rspamd_cryptobox_keypair *kp, * @return TRUE if signature is valid */ gboolean rspamd_keypair_verify (struct rspamd_cryptobox_pubkey *pk, - const void *data, gsize len, const guchar *sig, gsize siglen, - GError **err); + const void *data, gsize len, const guchar *sig, gsize siglen, + GError **err); /** * Compares two public keys @@ -271,7 +280,7 @@ gboolean rspamd_keypair_verify (struct rspamd_cryptobox_pubkey *pk, * @return TRUE if two keys are equal */ gboolean rspamd_pubkey_equal (const struct rspamd_cryptobox_pubkey *k1, - const struct rspamd_cryptobox_pubkey *k2); + const struct rspamd_cryptobox_pubkey *k2); /** * Decrypts data using keypair and a pubkey stored in in, in must start from @@ -304,6 +313,7 @@ gboolean rspamd_keypair_encrypt (struct rspamd_cryptobox_keypair *kp, const guchar *in, gsize inlen, guchar **out, gsize *outlen, GError **err); + /** * Encrypts data usign specific pubkey (must have KEX type). * This method actually generates ephemeral local keypair, use public key from @@ -317,8 +327,12 @@ gboolean rspamd_keypair_encrypt (struct rspamd_cryptobox_keypair *kp, * @return TRUE if encryption has been completed, out must be freed in this case */ gboolean rspamd_pubkey_encrypt (struct rspamd_cryptobox_pubkey *pk, - const guchar *in, gsize inlen, - guchar **out, gsize *outlen, - GError **err); + const guchar *in, gsize inlen, + guchar **out, gsize *outlen, + GError **err); + +#ifdef __cplusplus +} +#endif #endif /* SRC_LIBCRYPTOBOX_KEYPAIR_H_ */ |