aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-08 15:22:05 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-08 15:22:05 +0100
commitc271eb36656a4ff88a9c8c1d59934949260275a3 (patch)
tree3dd586e38b5b37cfebc7c12b6ff6f434904167c7 /src/libcryptobox
parentb266445f47dec06392a7e058f499325fa3c052b9 (diff)
downloadrspamd-c271eb36656a4ff88a9c8c1d59934949260275a3.tar.gz
rspamd-c271eb36656a4ff88a9c8c1d59934949260275a3.zip
[Rework] Add C++ guards to all headers
Diffstat (limited to 'src/libcryptobox')
-rw-r--r--src/libcryptobox/base64/base64.h10
-rw-r--r--src/libcryptobox/catena/catena.h24
-rw-r--r--src/libcryptobox/chacha20/chacha.h27
-rw-r--r--src/libcryptobox/cryptobox.h110
-rw-r--r--src/libcryptobox/curve25519/curve25519.h12
-rw-r--r--src/libcryptobox/curve25519/fe.h159
-rw-r--r--src/libcryptobox/ed25519/ed25519.h24
-rw-r--r--src/libcryptobox/keypair.h90
-rw-r--r--src/libcryptobox/keypair_private.h11
-rw-r--r--src/libcryptobox/keypairs_cache.h14
10 files changed, 304 insertions, 177 deletions
diff --git a/src/libcryptobox/base64/base64.h b/src/libcryptobox/base64/base64.h
index e7c639d58..e2be379b5 100644
--- a/src/libcryptobox/base64/base64.h
+++ b/src/libcryptobox/base64/base64.h
@@ -18,6 +18,14 @@
#include "config.h"
-const char* base64_load (void);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *base64_load (void);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* SRC_LIBCRYPTOBOX_BASE64_BASE64_H_ */
diff --git a/src/libcryptobox/catena/catena.h b/src/libcryptobox/catena/catena.h
index 56da560ea..bf81cc0f9 100644
--- a/src/libcryptobox/catena/catena.h
+++ b/src/libcryptobox/catena/catena.h
@@ -24,12 +24,16 @@
#define CATENA_HLEN 64
+#ifdef __cplusplus
+extern "C" {
+#endif
+
int
-catena (const uint8_t *pwd, const uint32_t pwdlen,
- const uint8_t *salt, const uint8_t saltlen,
- const uint8_t *data, const uint32_t datalen,
- const uint8_t lambda, const uint8_t min_garlic,
- const uint8_t garlic, const uint8_t hashlen, uint8_t *hash);
+catena (const uint8_t *pwd, const uint32_t pwdlen,
+ const uint8_t *salt, const uint8_t saltlen,
+ const uint8_t *data, const uint32_t datalen,
+ const uint8_t lambda, const uint8_t min_garlic,
+ const uint8_t garlic, const uint8_t hashlen, uint8_t *hash);
/**
* Simple interface for catena PBKDF
@@ -43,13 +47,17 @@ catena (const uint8_t *pwd, const uint32_t pwdlen,
* @return 0 if hash is generated, -1 in case of error
*/
int simple_catena (const uint8_t *pwd, const uint32_t pwdlen,
- const uint8_t *salt, const uint8_t saltlen,
- const uint8_t *data, const uint32_t datalen,
- uint8_t hash[CATENA_HLEN]);
+ const uint8_t *salt, const uint8_t saltlen,
+ const uint8_t *data, const uint32_t datalen,
+ uint8_t hash[CATENA_HLEN]);
/**
* Run a quick test on catena implementation
*/
int catena_test (void);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* SRC_LIBCRYPTOBOX_CATENA_CATENA_H_ */
diff --git a/src/libcryptobox/chacha20/chacha.h b/src/libcryptobox/chacha20/chacha.h
index 7f93a4517..02d6dba00 100644
--- a/src/libcryptobox/chacha20/chacha.h
+++ b/src/libcryptobox/chacha20/chacha.h
@@ -29,6 +29,10 @@
#define CHACHA_BLOCKBYTES 64
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct chacha_state_internal_t {
unsigned char s[48];
size_t rounds;
@@ -53,26 +57,31 @@ typedef struct chacha_iv24_t {
} chacha_iv24;
void hchacha (const unsigned char key[32], const unsigned char iv[16],
- unsigned char out[32], size_t rounds);
+ unsigned char out[32], size_t rounds);
void chacha_init (chacha_state *S, const chacha_key *key, const chacha_iv *iv,
- size_t rounds);
+ size_t rounds);
void xchacha_init (chacha_state *S, const chacha_key *key,
- const chacha_iv24 *iv, size_t rounds);
+ const chacha_iv24 *iv, size_t rounds);
size_t chacha_update (chacha_state *S, const unsigned char *in,
- unsigned char *out, size_t inlen);
+ unsigned char *out, size_t inlen);
size_t chacha_final (chacha_state *S, unsigned char *out);
void chacha (const chacha_key *key, const chacha_iv *iv,
- const unsigned char *in, unsigned char *out, size_t inlen,
- size_t rounds);
+ const unsigned char *in, unsigned char *out, size_t inlen,
+ size_t rounds);
+
void xchacha (const chacha_key *key, const chacha_iv24 *iv,
- const unsigned char *in, unsigned char *out, size_t inlen,
- size_t rounds);
+ const unsigned char *in, unsigned char *out, size_t inlen,
+ size_t rounds);
+
+const char *chacha_load (void);
-const char* chacha_load (void);
+#ifdef __cplusplus
+}
+#endif
#endif /* CHACHA_H_ */
diff --git a/src/libcryptobox/cryptobox.h b/src/libcryptobox/cryptobox.h
index df713d79b..d9e4f51cd 100644
--- a/src/libcryptobox/cryptobox.h
+++ b/src/libcryptobox/cryptobox.h
@@ -18,14 +18,18 @@
#include "config.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct rspamd_cryptobox_segment {
guchar *data;
gsize len;
};
#if defined(__GNUC__) && \
- ((defined(__clang__) && (__clang_major__ >= 4 || (__clang_major__ >= 3 && __clang_minor__ >= 8))) || \
- ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) || (__GNUC__ > 4)))
+ ((defined(__clang__) && (__clang_major__ >= 4 || (__clang_major__ >= 3 && __clang_minor__ >= 8))) || \
+ ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) || (__GNUC__ > 4)))
#define RSPAMD_HAS_TARGET_ATTR 1
#endif
@@ -81,7 +85,7 @@ struct rspamd_cryptobox_library_ctx {
/**
* Init cryptobox library
*/
-struct rspamd_cryptobox_library_ctx* rspamd_cryptobox_init (void);
+struct rspamd_cryptobox_library_ctx *rspamd_cryptobox_init (void);
/**
* Generate new keypair
@@ -89,7 +93,7 @@ struct rspamd_cryptobox_library_ctx* rspamd_cryptobox_init (void);
* @param sk secret key buffer
*/
void rspamd_cryptobox_keypair (rspamd_pk_t pk, rspamd_sk_t sk,
- enum rspamd_cryptobox_mode mode);
+ enum rspamd_cryptobox_mode mode);
/**
* Generate new keypair for signing
@@ -97,7 +101,7 @@ void rspamd_cryptobox_keypair (rspamd_pk_t pk, rspamd_sk_t sk,
* @param sk secret key buffer
*/
void rspamd_cryptobox_keypair_sig (rspamd_sig_pk_t pk, rspamd_sig_sk_t sk,
- enum rspamd_cryptobox_mode mode);
+ enum rspamd_cryptobox_mode mode);
/**
* Encrypt data inplace adding signature to sig afterwards
@@ -107,9 +111,9 @@ void rspamd_cryptobox_keypair_sig (rspamd_sig_pk_t pk, rspamd_sig_sk_t sk,
* @param sig output signature
*/
void rspamd_cryptobox_encrypt_inplace (guchar *data, gsize len,
- const rspamd_nonce_t nonce,
- const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig,
- enum rspamd_cryptobox_mode mode);
+ const rspamd_nonce_t nonce,
+ const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig,
+ enum rspamd_cryptobox_mode mode);
/**
* Encrypt segments of data inplace adding signature to sig afterwards
@@ -120,10 +124,10 @@ void rspamd_cryptobox_encrypt_inplace (guchar *data, gsize len,
* @param sig output signature
*/
void rspamd_cryptobox_encryptv_inplace (struct rspamd_cryptobox_segment *segments,
- gsize cnt,
- const rspamd_nonce_t nonce,
- const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig,
- enum rspamd_cryptobox_mode mode);
+ gsize cnt,
+ const rspamd_nonce_t nonce,
+ const rspamd_pk_t pk, const rspamd_sk_t sk, rspamd_mac_t sig,
+ enum rspamd_cryptobox_mode mode);
/**
@@ -136,9 +140,9 @@ void rspamd_cryptobox_encryptv_inplace (struct rspamd_cryptobox_segment *segment
* @return TRUE if input has been verified successfully
*/
gboolean rspamd_cryptobox_decrypt_inplace (guchar *data, gsize len,
- const rspamd_nonce_t nonce,
- const rspamd_pk_t pk, const rspamd_sk_t sk, const rspamd_mac_t sig,
- enum rspamd_cryptobox_mode mode);
+ const rspamd_nonce_t nonce,
+ const rspamd_pk_t pk, const rspamd_sk_t sk, const rspamd_mac_t sig,
+ enum rspamd_cryptobox_mode mode);
/**
* Encrypt segments of data inplace adding signature to sig afterwards
@@ -149,9 +153,9 @@ gboolean rspamd_cryptobox_decrypt_inplace (guchar *data, gsize len,
* @param sig output signature
*/
void rspamd_cryptobox_encrypt_nm_inplace (guchar *data, gsize len,
- const rspamd_nonce_t nonce,
- const rspamd_nm_t nm, rspamd_mac_t sig,
- enum rspamd_cryptobox_mode mode);
+ const rspamd_nonce_t nonce,
+ const rspamd_nm_t nm, rspamd_mac_t sig,
+ enum rspamd_cryptobox_mode mode);
/**
* Encrypt segments of data inplace adding signature to sig afterwards
@@ -162,10 +166,10 @@ void rspamd_cryptobox_encrypt_nm_inplace (guchar *data, gsize len,
* @param sig output signature
*/
void rspamd_cryptobox_encryptv_nm_inplace (struct rspamd_cryptobox_segment *segments,
- gsize cnt,
- const rspamd_nonce_t nonce,
- const rspamd_nm_t nm, rspamd_mac_t sig,
- enum rspamd_cryptobox_mode mode);
+ gsize cnt,
+ const rspamd_nonce_t nonce,
+ const rspamd_nm_t nm, rspamd_mac_t sig,
+ enum rspamd_cryptobox_mode mode);
/**
@@ -178,9 +182,9 @@ void rspamd_cryptobox_encryptv_nm_inplace (struct rspamd_cryptobox_segment *segm
* @return TRUE if input has been verified successfully
*/
gboolean rspamd_cryptobox_decrypt_nm_inplace (guchar *data, gsize len,
- const rspamd_nonce_t nonce,
- const rspamd_nm_t nm, const rspamd_mac_t sig,
- enum rspamd_cryptobox_mode mode);
+ const rspamd_nonce_t nonce,
+ const rspamd_nm_t nm, const rspamd_mac_t sig,
+ enum rspamd_cryptobox_mode mode);
/**
* Generate shared secret from local sk and remote pk
@@ -189,7 +193,7 @@ gboolean rspamd_cryptobox_decrypt_nm_inplace (guchar *data, gsize len,
* @param sk local privkey
*/
void rspamd_cryptobox_nm (rspamd_nm_t nm, const rspamd_pk_t pk,
- const rspamd_sk_t sk, enum rspamd_cryptobox_mode mode);
+ const rspamd_sk_t sk, enum rspamd_cryptobox_mode mode);
/**
* Create digital signature for the specified message and place result in `sig`
@@ -200,9 +204,9 @@ void rspamd_cryptobox_nm (rspamd_nm_t nm, const rspamd_pk_t pk,
* @param sk secret key
*/
void rspamd_cryptobox_sign (guchar *sig, gsize *siglen_p,
- const guchar *m, gsize mlen,
- const rspamd_sk_t sk,
- enum rspamd_cryptobox_mode mode);
+ const guchar *m, gsize mlen,
+ const rspamd_sk_t sk,
+ enum rspamd_cryptobox_mode mode);
/**
* Verifies digital signature for the specified message using the specified
@@ -214,18 +218,18 @@ void rspamd_cryptobox_sign (guchar *sig, gsize *siglen_p,
* @return true if signature is valid, false otherwise
*/
bool rspamd_cryptobox_verify (const guchar *sig,
- gsize siglen,
- const guchar *m,
- gsize mlen,
- const rspamd_pk_t pk,
- enum rspamd_cryptobox_mode mode);
+ gsize siglen,
+ const guchar *m,
+ gsize mlen,
+ const rspamd_pk_t pk,
+ enum rspamd_cryptobox_mode mode);
/**
* Securely clear the buffer specified
* @param buf buffer to zero
* @param buflen length of buffer
*/
-void rspamd_explicit_memzero (void * const buf, gsize buflen);
+void rspamd_explicit_memzero (void *const buf, gsize buflen);
/**
* Constant time memcmp
@@ -245,8 +249,8 @@ rspamd_cryptobox_memcmp (const void *const b1_, const void *const b2_, gsize len
* @param k key (must be 16 bytes)
*/
void rspamd_cryptobox_siphash (unsigned char *out, const unsigned char *in,
- unsigned long long inlen,
- const rspamd_sipkey_t k);
+ unsigned long long inlen,
+ const rspamd_sipkey_t k);
enum rspamd_cryptobox_pbkdf_type {
RSPAMD_CRYPTOBOX_PBKDF2 = 0,
@@ -266,10 +270,10 @@ enum rspamd_cryptobox_pbkdf_type {
* @return TRUE in case of success and FALSE if failed
*/
gboolean rspamd_cryptobox_pbkdf (const char *pass, gsize pass_len,
- const guint8 *salt, gsize salt_len,
- guint8 *key, gsize key_len,
- unsigned int complexity,
- enum rspamd_cryptobox_pbkdf_type type);
+ const guint8 *salt, gsize salt_len,
+ guint8 *key, gsize key_len,
+ unsigned int complexity,
+ enum rspamd_cryptobox_pbkdf_type type);
/**
@@ -313,7 +317,7 @@ guint rspamd_cryptobox_mac_bytes (enum rspamd_cryptobox_mode mode);
guint rspamd_cryptobox_signature_bytes (enum rspamd_cryptobox_mode mode);
/* Hash IUF interface */
-typedef struct rspamd_cryptobox_hash_state_s {
+typedef struct rspamd_cryptobox_hash_state_s {
unsigned char opaque[256];
} rspamd_cryptobox_hash_state_t;
@@ -338,10 +342,10 @@ void rspamd_cryptobox_hash_final (void *st, guchar *out);
* One in all function
*/
void rspamd_cryptobox_hash (guchar *out,
- const guchar *data,
- gsize len,
- const guchar *key,
- gsize keylen);
+ const guchar *data,
+ gsize len,
+ const guchar *key,
+ gsize keylen);
enum rspamd_cryptobox_fast_hash_type {
RSPAMD_CRYPTOBOX_XXHASH64 = 0,
@@ -353,7 +357,7 @@ enum rspamd_cryptobox_fast_hash_type {
};
/* Non crypto hash IUF interface */
-typedef struct rspamd_cryptobox_fast_hash_state_s {
+typedef struct rspamd_cryptobox_fast_hash_state_s {
guint64 opaque[11];
enum rspamd_cryptobox_fast_hash_type type;
} rspamd_cryptobox_fast_hash_state_t;
@@ -364,7 +368,7 @@ typedef struct rspamd_cryptobox_fast_hash_state_s {
* non-keyed hash is generated
*/
void rspamd_cryptobox_fast_hash_init (rspamd_cryptobox_fast_hash_state_t *st,
- guint64 seed);
+ guint64 seed);
/**
* Init cryptobox hash state using key if needed, `st` must point to the buffer
@@ -379,7 +383,7 @@ void rspamd_cryptobox_fast_hash_init_specific (rspamd_cryptobox_fast_hash_state_
* Update hash with data portion
*/
void rspamd_cryptobox_fast_hash_update (rspamd_cryptobox_fast_hash_state_t *st,
- const void *data, gsize len);
+ const void *data, gsize len);
/**
* Output hash to the buffer of rspamd_cryptobox_HASHBYTES length
@@ -390,7 +394,7 @@ guint64 rspamd_cryptobox_fast_hash_final (rspamd_cryptobox_fast_hash_state_t *st
* One in all function
*/
guint64 rspamd_cryptobox_fast_hash (const void *data,
- gsize len, guint64 seed);
+ gsize len, guint64 seed);
/**
* Platform independent version
@@ -409,7 +413,7 @@ guint64 rspamd_cryptobox_fast_hash_specific (
* @return
*/
gboolean rspamd_cryptobox_base64_decode (const gchar *in, gsize inlen,
- guchar *out, gsize *outlen);
+ guchar *out, gsize *outlen);
/**
* Returns TRUE if data looks like a valid base64 string
@@ -419,4 +423,8 @@ gboolean rspamd_cryptobox_base64_decode (const gchar *in, gsize inlen,
*/
gboolean rspamd_cryptobox_base64_is_valid (const gchar *in, gsize inlen);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* CRYPTOBOX_H_ */
diff --git a/src/libcryptobox/curve25519/curve25519.h b/src/libcryptobox/curve25519/curve25519.h
index 8b404f5c6..c75c355f8 100644
--- a/src/libcryptobox/curve25519/curve25519.h
+++ b/src/libcryptobox/curve25519/curve25519.h
@@ -3,11 +3,21 @@
#include "config.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
static const guchar curve25519_basepoint[32] = {9};
int curve25519 (guchar *mypublic, const guchar *secret, const guchar *basepoint);
+
/* Call for optimized implementation of scalarmult if needed */
int curve25519_base (guchar *mypublic, const guchar *secret);
-const char* curve25519_load (void);
+
+const char *curve25519_load (void);
+
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/src/libcryptobox/curve25519/fe.h b/src/libcryptobox/curve25519/fe.h
index a64206026..44e8b44a6 100644
--- a/src/libcryptobox/curve25519/fe.h
+++ b/src/libcryptobox/curve25519/fe.h
@@ -18,25 +18,44 @@
#ifndef SRC_LIBCRYPTOBOX_CURVE25519_FE_H_
#define SRC_LIBCRYPTOBOX_CURVE25519_FE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef int32_t fe[10];
-void fe_frombytes(fe,const unsigned char *);
-void fe_tobytes(unsigned char *,const fe);
-
-void fe_copy(fe,const fe);
-int fe_isnonzero(const fe);
-int fe_isnegative(const fe);
-void fe_0(fe);
-void fe_1(fe);
-void fe_cmov(fe,const fe,unsigned int);
-void fe_add(fe,const fe,const fe);
-void fe_sub(fe,const fe,const fe);
-void fe_neg(fe,const fe);
-void fe_mul(fe,const fe,const fe);
-void fe_sq(fe,const fe);
-void fe_sq2(fe,const fe);
-void fe_invert(fe,const fe);
-void fe_pow22523(fe,const fe);
+void fe_frombytes (fe, const unsigned char *);
+
+void fe_tobytes (unsigned char *, const fe);
+
+void fe_copy (fe, const fe);
+
+int fe_isnonzero (const fe);
+
+int fe_isnegative (const fe);
+
+void fe_0 (fe);
+
+void fe_1 (fe);
+
+void fe_cmov (fe, const fe, unsigned int);
+
+void fe_add (fe, const fe, const fe);
+
+void fe_sub (fe, const fe, const fe);
+
+void fe_neg (fe, const fe);
+
+void fe_mul (fe, const fe, const fe);
+
+void fe_sq (fe, const fe);
+
+void fe_sq2 (fe, const fe);
+
+void fe_invert (fe, const fe);
+
+void fe_pow22523 (fe, const fe);
/*
ge means group element.
@@ -51,68 +70,90 @@ Representations:
*/
typedef struct {
- fe X;
- fe Y;
- fe Z;
+ fe X;
+ fe Y;
+ fe Z;
} ge_p2;
typedef struct {
- fe X;
- fe Y;
- fe Z;
- fe T;
+ fe X;
+ fe Y;
+ fe Z;
+ fe T;
} ge_p3;
typedef struct {
- fe X;
- fe Y;
- fe Z;
- fe T;
+ fe X;
+ fe Y;
+ fe Z;
+ fe T;
} ge_p1p1;
typedef struct {
- fe yplusx;
- fe yminusx;
- fe xy2d;
+ fe yplusx;
+ fe yminusx;
+ fe xy2d;
} ge_precomp;
typedef struct {
- fe YplusX;
- fe YminusX;
- fe Z;
- fe T2d;
+ fe YplusX;
+ fe YminusX;
+ fe Z;
+ fe T2d;
} ge_cached;
-void ge_tobytes(unsigned char *,const ge_p2 *);
-void ge_p3_tobytes(unsigned char *,const ge_p3 *);
-int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *);
-
-void ge_p2_0(ge_p2 *);
-void ge_p3_0(ge_p3 *);
-void ge_precomp_0(ge_precomp *);
-void ge_p3_to_p2(ge_p2 *,const ge_p3 *);
-void ge_p3_to_cached(ge_cached *,const ge_p3 *);
-void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *);
-void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *);
-void ge_p2_dbl(ge_p1p1 *,const ge_p2 *);
-void ge_p3_dbl(ge_p1p1 *,const ge_p3 *);
-
-void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
-void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *);
-void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *);
-void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *);
-void ge_scalarmult_base(ge_p3 *,const unsigned char *);
-void ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *,const ge_p3 *,const unsigned char *);
-void ge_scalarmult_vartime(ge_p3 *,const unsigned char *,const ge_p3 *);
-int verify_32(const unsigned char *x, const unsigned char *y);
+void ge_tobytes (unsigned char *, const ge_p2 *);
+
+void ge_p3_tobytes (unsigned char *, const ge_p3 *);
+
+int ge_frombytes_negate_vartime (ge_p3 *, const unsigned char *);
+
+void ge_p2_0 (ge_p2 *);
+
+void ge_p3_0 (ge_p3 *);
+
+void ge_precomp_0 (ge_precomp *);
+
+void ge_p3_to_p2 (ge_p2 *, const ge_p3 *);
+
+void ge_p3_to_cached (ge_cached *, const ge_p3 *);
+
+void ge_p1p1_to_p2 (ge_p2 *, const ge_p1p1 *);
+
+void ge_p1p1_to_p3 (ge_p3 *, const ge_p1p1 *);
+
+void ge_p2_dbl (ge_p1p1 *, const ge_p2 *);
+
+void ge_p3_dbl (ge_p1p1 *, const ge_p3 *);
+
+void ge_madd (ge_p1p1 *, const ge_p3 *, const ge_precomp *);
+
+void ge_msub (ge_p1p1 *, const ge_p3 *, const ge_precomp *);
+
+void ge_add (ge_p1p1 *, const ge_p3 *, const ge_cached *);
+
+void ge_sub (ge_p1p1 *, const ge_p3 *, const ge_cached *);
+
+void ge_scalarmult_base (ge_p3 *, const unsigned char *);
+
+void ge_double_scalarmult_vartime (ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *);
+
+void ge_scalarmult_vartime (ge_p3 *, const unsigned char *, const ge_p3 *);
+
+int verify_32 (const unsigned char *x, const unsigned char *y);
/*
The set of scalars is \Z/l
where l = 2^252 + 27742317777372353535851937790883648493.
*/
-void sc_reduce(unsigned char *);
-void sc_muladd(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
+void sc_reduce (unsigned char *);
+
+void sc_muladd (unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* SRC_LIBCRYPTOBOX_CURVE25519_FE_H_ */
diff --git a/src/libcryptobox/ed25519/ed25519.h b/src/libcryptobox/ed25519/ed25519.h
index 0fbf7d6fe..a1f702c4a 100644
--- a/src/libcryptobox/ed25519/ed25519.h
+++ b/src/libcryptobox/ed25519/ed25519.h
@@ -20,15 +20,27 @@
#include <stdbool.h>
#include <stddef.h>
-const char* ed25519_load (void);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *ed25519_load (void);
+
void ed25519_keypair (unsigned char *pk, unsigned char *sk);
+
void ed25519_seed_keypair (unsigned char *pk, unsigned char *sk, unsigned char *seed);
+
void ed25519_sign (unsigned char *sig, size_t *siglen_p,
- const unsigned char *m, size_t mlen,
- const unsigned char *sk);
+ const unsigned char *m, size_t mlen,
+ const unsigned char *sk);
+
bool ed25519_verify (const unsigned char *sig,
- const unsigned char *m,
- size_t mlen,
- const unsigned char *pk);
+ const unsigned char *m,
+ size_t mlen,
+ const unsigned char *pk);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* SRC_LIBCRYPTOBOX_ED25519_ED25519_H_ */
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_ */
diff --git a/src/libcryptobox/keypair_private.h b/src/libcryptobox/keypair_private.h
index 98af52b4c..8d259faaa 100644
--- a/src/libcryptobox/keypair_private.h
+++ b/src/libcryptobox/keypair_private.h
@@ -20,6 +20,9 @@
#include "ref.h"
#include "cryptobox.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
/*
* KEX cached data
*/
@@ -32,7 +35,7 @@ struct rspamd_cryptobox_nm {
/*
* Generic keypair
*/
-struct rspamd_cryptobox_keypair {
+struct rspamd_cryptobox_keypair {
guchar id[rspamd_cryptobox_HASHBYTES];
enum rspamd_cryptobox_keypair_type type;
enum rspamd_cryptobox_mode alg;
@@ -127,7 +130,13 @@ struct rspamd_cryptobox_pubkey_sig_25519 {
};
void rspamd_cryptobox_nm_dtor (struct rspamd_cryptobox_nm *nm);
+
void rspamd_cryptobox_keypair_dtor (struct rspamd_cryptobox_keypair *kp);
+
void rspamd_cryptobox_pubkey_dtor (struct rspamd_cryptobox_pubkey *p);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* KEYPAIR_PRIVATE_H_ */
diff --git a/src/libcryptobox/keypairs_cache.h b/src/libcryptobox/keypairs_cache.h
index 3ee7c0d51..4f54b6c9d 100644
--- a/src/libcryptobox/keypairs_cache.h
+++ b/src/libcryptobox/keypairs_cache.h
@@ -19,6 +19,11 @@
#include "config.h"
#include "keypair.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct rspamd_keypair_cache;
/**
@@ -26,7 +31,7 @@ struct rspamd_keypair_cache;
* @param max_items defines maximum count of elements in the cache
* @return new cache
*/
-struct rspamd_keypair_cache * rspamd_keypair_cache_new (guint max_items);
+struct rspamd_keypair_cache *rspamd_keypair_cache_new (guint max_items);
/**
@@ -36,8 +41,8 @@ struct rspamd_keypair_cache * rspamd_keypair_cache_new (guint max_items);
* @param rk remote key
*/
void rspamd_keypair_cache_process (struct rspamd_keypair_cache *c,
- struct rspamd_cryptobox_keypair *lk,
- struct rspamd_cryptobox_pubkey *rk);
+ struct rspamd_cryptobox_keypair *lk,
+ struct rspamd_cryptobox_pubkey *rk);
/**
* Destroy old keypair cache
@@ -45,5 +50,8 @@ void rspamd_keypair_cache_process (struct rspamd_keypair_cache *c,
*/
void rspamd_keypair_cache_destroy (struct rspamd_keypair_cache *c);
+#ifdef __cplusplus
+}
+#endif
#endif /* KEYPAIRS_CACHE_H_ */