aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-12-11 14:25:28 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-12-11 14:25:28 +0100
commit915507020046c9488f277d523c22bb12995e14ea (patch)
tree0bcde034f2f71ef6091a3cdb3793c09d43ce0f89 /src
parentreceive: simplify ip header checking logic (diff)
downloadwireguard-monolithic-historical-915507020046c9488f277d523c22bb12995e14ea.tar.xz
wireguard-monolithic-historical-915507020046c9488f277d523c22bb12995e14ea.zip
global: move to consistent use of uN instead of uintN_t for kernel code
Diffstat (limited to 'src')
-rw-r--r--src/config.c10
-rw-r--r--src/cookie.h4
-rw-r--r--src/crypto/blake2s.c76
-rw-r--r--src/crypto/blake2s.h22
-rw-r--r--src/crypto/chacha20poly1305.c60
-rw-r--r--src/crypto/chacha20poly1305.h20
-rw-r--r--src/crypto/curve25519.c424
-rw-r--r--src/crypto/curve25519.h6
-rw-r--r--src/crypto/siphash24.c44
-rw-r--r--src/crypto/siphash24.h2
-rw-r--r--src/data.c16
-rw-r--r--src/hashtables.c8
-rw-r--r--src/hashtables.h6
-rw-r--r--src/noise.h6
-rw-r--r--src/peer.h6
-rw-r--r--src/routingtable.c68
-rw-r--r--src/routingtable.h14
-rw-r--r--src/selftest/chacha20poly1305.h4
-rw-r--r--src/selftest/curve25519.h8
-rw-r--r--src/selftest/routing-table.h8
-rw-r--r--src/selftest/siphash24.h10
-rw-r--r--src/socket.c12
-rw-r--r--src/socket.h4
23 files changed, 419 insertions, 419 deletions
diff --git a/src/config.c b/src/config.c
index d9b70df..b65e498 100644
--- a/src/config.c
+++ b/src/config.c
@@ -47,7 +47,7 @@ static int set_ipmask(struct wireguard_peer *peer, void __user *user_ipmask)
return ret;
}
-static const uint8_t zeros[WG_KEY_LEN] = { 0 };
+static const u8 zeros[WG_KEY_LEN] = { 0 };
static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t *len)
{
@@ -97,7 +97,7 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t
break;
}
- if (in_peer.persistent_keepalive_interval != (uint16_t)-1) {
+ if (in_peer.persistent_keepalive_interval != (u16)-1) {
const bool send_keepalive = !peer->persistent_keepalive_interval && in_peer.persistent_keepalive_interval && netdev_pub(wg)->flags & IFF_UP;
peer->persistent_keepalive_interval = (unsigned long)in_peer.persistent_keepalive_interval * HZ;
if (send_keepalive)
@@ -180,7 +180,7 @@ static inline int use_data(struct data_remaining *data, size_t size)
return 0;
}
-static int calculate_ipmasks_size(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, uint8_t cidr, int family)
+static int calculate_ipmasks_size(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, u8 cidr, int family)
{
size_t *count = ctx;
*count += sizeof(struct wgipmask);
@@ -194,7 +194,7 @@ static size_t calculate_peers_size(struct wireguard_device *wg)
return len;
}
-static int populate_ipmask(void *ctx, union nf_inet_addr ip, uint8_t cidr, int family)
+static int populate_ipmask(void *ctx, union nf_inet_addr ip, u8 cidr, int family)
{
int ret;
struct data_remaining *data = ctx;
@@ -242,7 +242,7 @@ static int populate_peer(struct wireguard_peer *peer, void *ctx)
out_peer.last_handshake_time = peer->walltime_last_handshake;
out_peer.tx_bytes = peer->tx_bytes;
out_peer.rx_bytes = peer->rx_bytes;
- out_peer.persistent_keepalive_interval = (uint16_t)(peer->persistent_keepalive_interval / HZ);
+ out_peer.persistent_keepalive_interval = (u16)(peer->persistent_keepalive_interval / HZ);
ipmasks_data.out_len = data->out_len;
ipmasks_data.data = data->data;
diff --git a/src/cookie.h b/src/cookie.h
index 2417cc0..4ea20e1 100644
--- a/src/cookie.h
+++ b/src/cookie.h
@@ -13,14 +13,14 @@ struct sk_buff;
struct cookie_checker {
u8 secret[NOISE_HASH_LEN];
- uint64_t secret_birthdate;
+ u64 secret_birthdate;
struct rw_semaphore secret_lock;
struct ratelimiter ratelimiter;
struct wireguard_device *device;
};
struct cookie {
- uint64_t birthdate;
+ u64 birthdate;
bool is_valid;
u8 cookie[COOKIE_LEN];
bool have_sent_mac1;
diff --git a/src/crypto/blake2s.c b/src/crypto/blake2s.c
index b8a7535..cd9691a 100644
--- a/src/crypto/blake2s.c
+++ b/src/crypto/blake2s.c
@@ -10,24 +10,24 @@
#include <linux/kernel.h>
typedef struct {
- uint8_t digest_length;
- uint8_t key_length;
- uint8_t fanout;
- uint8_t depth;
- uint32_t leaf_length;
- uint8_t node_offset[6];
- uint8_t node_depth;
- uint8_t inner_length;
- uint8_t salt[8];
- uint8_t personal[8];
+ u8 digest_length;
+ u8 key_length;
+ u8 fanout;
+ u8 depth;
+ u32 leaf_length;
+ u8 node_offset[6];
+ u8 node_depth;
+ u8 inner_length;
+ u8 salt[8];
+ u8 personal[8];
} __packed blake2s_param;
-static const uint32_t blake2s_iv[8] = {
+static const u32 blake2s_iv[8] = {
0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
};
-static const uint8_t blake2s_sigma[10][16] = {
+static const u8 blake2s_sigma[10][16] = {
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
@@ -40,7 +40,7 @@ static const uint8_t blake2s_sigma[10][16] = {
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
};
-static inline uint32_t rotr32(const uint32_t w, const uint8_t c)
+static inline u32 rotr32(const u32 w, const u8 c)
{
return (w >> c) | (w << (32 - c));
}
@@ -57,7 +57,7 @@ static inline void blake2s_set_lastblock(struct blake2s_state *state)
state->f[0] = -1;
}
-static inline void blake2s_increment_counter(struct blake2s_state *state, const uint32_t inc)
+static inline void blake2s_increment_counter(struct blake2s_state *state, const u32 inc)
{
state->t[0] += inc;
state->t[1] += (state->t[0] < inc);
@@ -67,18 +67,18 @@ static inline void blake2s_increment_counter(struct blake2s_state *state, const
__attribute__((optimize("unroll-loops")))
static inline void blake2s_init_param(struct blake2s_state *state, const blake2s_param *param)
{
- const uint32_t *p;
+ const u32 *p;
int i;
memset(state, 0, sizeof(struct blake2s_state));
for (i = 0; i < 8; ++i)
state->h[i] = blake2s_iv[i];
- p = (const uint32_t *)param;
+ p = (const u32 *)param;
/* IV XOR ParamBlock */
for (i = 0; i < 8; ++i)
state->h[i] ^= le32_to_cpuvp(&p[i]);
}
-void blake2s_init(struct blake2s_state *state, const uint8_t outlen)
+void blake2s_init(struct blake2s_state *state, const u8 outlen)
{
blake2s_param param = {
.digest_length = outlen,
@@ -92,7 +92,7 @@ void blake2s_init(struct blake2s_state *state, const uint8_t outlen)
blake2s_init_param(state, &param);
}
-void blake2s_init_key(struct blake2s_state *state, const uint8_t outlen, const void *key, const uint8_t keylen)
+void blake2s_init_key(struct blake2s_state *state, const u8 outlen, const void *key, const u8 keylen)
{
blake2s_param param = {
.digest_length = outlen,
@@ -100,7 +100,7 @@ void blake2s_init_key(struct blake2s_state *state, const uint8_t outlen, const v
.fanout = 1,
.depth = 1
};
- uint8_t block[BLAKE2S_BLOCKBYTES] = { 0 };
+ u8 block[BLAKE2S_BLOCKBYTES] = { 0 };
#ifdef DEBUG
BUG_ON(!outlen || outlen > BLAKE2S_OUTBYTES || !key || !keylen || keylen > BLAKE2S_KEYBYTES);
@@ -112,10 +112,10 @@ void blake2s_init_key(struct blake2s_state *state, const uint8_t outlen, const v
}
__attribute__((optimize("unroll-loops")))
-static inline void blake2s_compress(struct blake2s_state *state, const uint8_t block[BLAKE2S_BLOCKBYTES])
+static inline void blake2s_compress(struct blake2s_state *state, const u8 block[BLAKE2S_BLOCKBYTES])
{
- uint32_t m[16];
- uint32_t v[16];
+ u32 m[16];
+ u32 v[16];
int i;
for (i = 0; i < 16; ++i)
@@ -171,7 +171,7 @@ static inline void blake2s_compress(struct blake2s_state *state, const uint8_t b
#undef ROUND
}
-void blake2s_update(struct blake2s_state *state, const uint8_t *in, uint64_t inlen)
+void blake2s_update(struct blake2s_state *state, const u8 *in, u64 inlen)
{
size_t left, fill;
while (inlen > 0) {
@@ -197,9 +197,9 @@ void blake2s_update(struct blake2s_state *state, const uint8_t *in, uint64_t inl
}
__attribute__((optimize("unroll-loops")))
-void blake2s_final(struct blake2s_state *state, uint8_t *out, uint8_t outlen)
+void blake2s_final(struct blake2s_state *state, u8 *out, u8 outlen)
{
- uint8_t buffer[BLAKE2S_OUTBYTES] = { 0 };
+ u8 buffer[BLAKE2S_OUTBYTES] = { 0 };
int i;
#ifdef DEBUG
@@ -213,7 +213,7 @@ void blake2s_final(struct blake2s_state *state, uint8_t *out, uint8_t outlen)
memcpy(state->buf, state->buf + BLAKE2S_BLOCKBYTES, state->buflen);
}
- blake2s_increment_counter(state, (uint32_t) state->buflen);
+ blake2s_increment_counter(state, (u32) state->buflen);
blake2s_set_lastblock(state);
memset(state->buf + state->buflen, 0, 2 * BLAKE2S_BLOCKBYTES - state->buflen); /* Padding */
blake2s_compress(state, state->buf);
@@ -228,7 +228,7 @@ void blake2s_final(struct blake2s_state *state, uint8_t *out, uint8_t outlen)
memzero_explicit(state, sizeof(struct blake2s_state));
}
-void blake2s(uint8_t *out, const uint8_t *in, const uint8_t *key, const uint8_t outlen, uint64_t inlen, const uint8_t keylen)
+void blake2s(u8 *out, const u8 *in, const u8 *key, const u8 outlen, u64 inlen, const u8 keylen)
{
struct blake2s_state state;
@@ -246,12 +246,12 @@ void blake2s(uint8_t *out, const uint8_t *in, const uint8_t *key, const uint8_t
}
__attribute__((optimize("unroll-loops")))
-void blake2s_hmac(uint8_t *out, const uint8_t *in, const uint8_t *key, const uint8_t outlen, const uint64_t inlen, const uint64_t keylen)
+void blake2s_hmac(u8 *out, const u8 *in, const u8 *key, const u8 outlen, const u64 inlen, const u64 keylen)
{
struct blake2s_state state;
- uint8_t o_key[BLAKE2S_BLOCKBYTES] = { 0 };
- uint8_t i_key[BLAKE2S_BLOCKBYTES] = { 0 };
- uint8_t i_hash[BLAKE2S_OUTBYTES];
+ u8 o_key[BLAKE2S_BLOCKBYTES] = { 0 };
+ u8 i_key[BLAKE2S_BLOCKBYTES] = { 0 };
+ u8 i_hash[BLAKE2S_OUTBYTES];
int i;
if (keylen > BLAKE2S_BLOCKBYTES) {
@@ -286,7 +286,7 @@ void blake2s_hmac(uint8_t *out, const uint8_t *in, const uint8_t *key, const uin
}
#ifdef DEBUG
-static const uint8_t blake2s_testvecs[][BLAKE2S_OUTBYTES] = {
+static const u8 blake2s_testvecs[][BLAKE2S_OUTBYTES] = {
{ 0x69, 0x21, 0x7A, 0x30, 0x79, 0x90, 0x80, 0x94, 0xE1, 0x11, 0x21, 0xD0, 0x42, 0x35, 0x4A, 0x7C, 0x1F, 0x55, 0xB6, 0x48, 0x2C, 0xA1, 0xA5, 0x1E, 0x1B, 0x25, 0x0D, 0xFD, 0x1E, 0xD0, 0xEE, 0xF9 },
{ 0xE3, 0x4D, 0x74, 0xDB, 0xAF, 0x4F, 0xF4, 0xC6, 0xAB, 0xD8, 0x71, 0xCC, 0x22, 0x04, 0x51, 0xD2, 0xEA, 0x26, 0x48, 0x84, 0x6C, 0x77, 0x57, 0xFB, 0xAA, 0xC8, 0x2F, 0xE5, 0x1A, 0xD6, 0x4B, 0xEA },
{ 0xDD, 0xAD, 0x9A, 0xB1, 0x5D, 0xAC, 0x45, 0x49, 0xBA, 0x42, 0xF4, 0x9D, 0x26, 0x24, 0x96, 0xBE, 0xF6, 0xC0, 0xBA, 0xE1, 0xDD, 0x34, 0x2A, 0x88, 0x08, 0xF8, 0xEA, 0x26, 0x7C, 0x6E, 0x21, 0x0C },
@@ -545,7 +545,7 @@ static const uint8_t blake2s_testvecs[][BLAKE2S_OUTBYTES] = {
{ 0xF0, 0x3F, 0x57, 0x89, 0xD3, 0x33, 0x6B, 0x80, 0xD0, 0x02, 0xD5, 0x9F, 0xDF, 0x91, 0x8B, 0xDB, 0x77, 0x5B, 0x00, 0x95, 0x6E, 0xD5, 0x52, 0x8E, 0x86, 0xAA, 0x99, 0x4A, 0xCB, 0x38, 0xFE, 0x2D }
};
-static const uint8_t blake2s_keyed_testvecs[][BLAKE2S_OUTBYTES] = {
+static const u8 blake2s_keyed_testvecs[][BLAKE2S_OUTBYTES] = {
{ 0x48, 0xA8, 0x99, 0x7D, 0xA4, 0x07, 0x87, 0x6B, 0x3D, 0x79, 0xC0, 0xD9, 0x23, 0x25, 0xAD, 0x3B, 0x89, 0xCB, 0xB7, 0x54, 0xD8, 0x6A, 0xB7, 0x1A, 0xEE, 0x04, 0x7A, 0xD3, 0x45, 0xFD, 0x2C, 0x49 },
{ 0x40, 0xD1, 0x5F, 0xEE, 0x7C, 0x32, 0x88, 0x30, 0x16, 0x6A, 0xC3, 0xF9, 0x18, 0x65, 0x0F, 0x80, 0x7E, 0x7E, 0x01, 0xE1, 0x77, 0x25, 0x8C, 0xDC, 0x0A, 0x39, 0xB1, 0x1F, 0x59, 0x80, 0x66, 0xF1 },
{ 0x6B, 0xB7, 0x13, 0x00, 0x64, 0x4C, 0xD3, 0x99, 0x1B, 0x26, 0xCC, 0xD4, 0xD2, 0x74, 0xAC, 0xD1, 0xAD, 0xEA, 0xB8, 0xB1, 0xD7, 0x91, 0x45, 0x46, 0xC1, 0x19, 0x8B, 0xBE, 0x9F, 0xC9, 0xD8, 0x03 },
@@ -806,17 +806,17 @@ static const uint8_t blake2s_keyed_testvecs[][BLAKE2S_OUTBYTES] = {
bool blake2s_selftest(void)
{
- uint8_t key[BLAKE2S_KEYBYTES];
- uint8_t buf[ARRAY_SIZE(blake2s_testvecs)];
- uint8_t hash[BLAKE2S_OUTBYTES];
+ u8 key[BLAKE2S_KEYBYTES];
+ u8 buf[ARRAY_SIZE(blake2s_testvecs)];
+ u8 hash[BLAKE2S_OUTBYTES];
size_t i;
bool success = true;
for (i = 0; i < BLAKE2S_KEYBYTES; ++i)
- key[i] = (uint8_t)i;
+ key[i] = (u8)i;
for (i = 0; i < ARRAY_SIZE(blake2s_testvecs); ++i)
- buf[i] = (uint8_t)i;
+ buf[i] = (u8)i;
for (i = 0; i < ARRAY_SIZE(blake2s_keyed_testvecs); ++i) {
blake2s(hash, buf, key, BLAKE2S_OUTBYTES, i, BLAKE2S_KEYBYTES);
diff --git a/src/crypto/blake2s.h b/src/crypto/blake2s.h
index ed7ea50..21ba298 100644
--- a/src/crypto/blake2s.h
+++ b/src/crypto/blake2s.h
@@ -12,22 +12,22 @@ enum blake2s_lengths {
};
struct blake2s_state {
- uint32_t h[8];
- uint32_t t[2];
- uint32_t f[2];
- uint8_t buf[2 * BLAKE2S_BLOCKBYTES];
+ u32 h[8];
+ u32 t[2];
+ u32 f[2];
+ u8 buf[2 * BLAKE2S_BLOCKBYTES];
size_t buflen;
- uint8_t last_node;
+ u8 last_node;
};
-void blake2s(uint8_t *out, const uint8_t *in, const uint8_t *key, const uint8_t outlen, const uint64_t inlen, const uint8_t keylen);
+void blake2s(u8 *out, const u8 *in, const u8 *key, const u8 outlen, const u64 inlen, const u8 keylen);
-void blake2s_init(struct blake2s_state *state, const uint8_t outlen);
-void blake2s_init_key(struct blake2s_state *state, const uint8_t outlen, const void *key, const uint8_t keylen);
-void blake2s_update(struct blake2s_state *state, const uint8_t *in, uint64_t inlen);
-void blake2s_final(struct blake2s_state *state, uint8_t *out, uint8_t outlen);
+void blake2s_init(struct blake2s_state *state, const u8 outlen);
+void blake2s_init_key(struct blake2s_state *state, const u8 outlen, const void *key, const u8 keylen);
+void blake2s_update(struct blake2s_state *state, const u8 *in, u64 inlen);
+void blake2s_final(struct blake2s_state *state, u8 *out, u8 outlen);
-void blake2s_hmac(uint8_t *out, const uint8_t *in, const uint8_t *key, const uint8_t outlen, const uint64_t inlen, const uint64_t keylen);
+void blake2s_hmac(u8 *out, const u8 *in, const u8 *key, const u8 outlen, const u64 inlen, const u64 keylen);
#ifdef DEBUG
bool blake2s_selftest(void);
diff --git a/src/crypto/chacha20poly1305.c b/src/crypto/chacha20poly1305.c
index 96e39bf..a7421d6 100644
--- a/src/crypto/chacha20poly1305.c
+++ b/src/crypto/chacha20poly1305.c
@@ -472,7 +472,7 @@ static void poly1305_finish(struct poly1305_ctx *ctx, u8 *dst)
f = (f >> 32) + h3 + ctx->s[3]; mac[3] = cpu_to_le32(f);
}
-static const uint8_t pad0[16] = { 0 };
+static const u8 pad0[16] = { 0 };
static struct crypto_alg chacha20_alg = {
.cra_blocksize = 1,
@@ -487,18 +487,18 @@ static struct blkcipher_desc chacha20_desc = {
.tfm = &chacha20_cipher
};
-bool chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN])
+bool chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN])
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
- uint8_t block0[CHACHA20_BLOCK_SIZE] = { 0 };
+ u8 block0[CHACHA20_BLOCK_SIZE] = { 0 };
__le64 len;
__le64 le_nonce = cpu_to_le64(nonce);
bool have_simd = chacha20poly1305_init_simd();
- chacha20_keysetup(&chacha20_state, key, (uint8_t *)&le_nonce);
+ chacha20_keysetup(&chacha20_state, key, (u8 *)&le_nonce);
chacha20_crypt(&chacha20_state, block0, block0, sizeof(block0), have_simd);
poly1305_init(&poly1305_state, block0);
@@ -513,10 +513,10 @@ bool chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src
poly1305_update(&poly1305_state, pad0, (0x10 - src_len) & 0xf, have_simd);
len = cpu_to_le64(ad_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
len = cpu_to_le64(src_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
poly1305_finish(&poly1305_state, dst + src_len);
@@ -529,19 +529,19 @@ bool chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src
}
bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN],
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN],
bool have_simd)
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
struct blkcipher_walk walk;
- uint8_t block0[CHACHA20_BLOCK_SIZE] = { 0 };
- uint8_t mac[POLY1305_MAC_SIZE];
+ u8 block0[CHACHA20_BLOCK_SIZE] = { 0 };
+ u8 mac[POLY1305_MAC_SIZE];
__le64 len;
__le64 le_nonce = cpu_to_le64(nonce);
- chacha20_keysetup(&chacha20_state, key, (uint8_t *)&le_nonce);
+ chacha20_keysetup(&chacha20_state, key, (u8 *)&le_nonce);
chacha20_crypt(&chacha20_state, block0, block0, sizeof(block0), have_simd);
poly1305_init(&poly1305_state, block0);
@@ -569,10 +569,10 @@ bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *sr
poly1305_update(&poly1305_state, pad0, (0x10 - src_len) & 0xf, have_simd);
len = cpu_to_le64(ad_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
len = cpu_to_le64(src_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
poly1305_finish(&poly1305_state, mac);
scatterwalk_map_and_copy(mac, dst, src_len, sizeof(mac), 1);
@@ -582,15 +582,15 @@ bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *sr
return true;
}
-bool chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN])
+bool chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN])
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
int ret;
- uint8_t block0[CHACHA20_BLOCK_SIZE] = { 0 };
- uint8_t mac[POLY1305_MAC_SIZE];
+ u8 block0[CHACHA20_BLOCK_SIZE] = { 0 };
+ u8 mac[POLY1305_MAC_SIZE];
size_t dst_len;
__le64 len;
__le64 le_nonce = cpu_to_le64(nonce);
@@ -601,7 +601,7 @@ bool chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src
have_simd = chacha20poly1305_init_simd();
- chacha20_keysetup(&chacha20_state, key, (uint8_t *)&le_nonce);
+ chacha20_keysetup(&chacha20_state, key, (u8 *)&le_nonce);
chacha20_crypt(&chacha20_state, block0, block0, sizeof(block0), have_simd);
poly1305_init(&poly1305_state, block0);
@@ -615,10 +615,10 @@ bool chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src
poly1305_update(&poly1305_state, pad0, (0x10 - dst_len) & 0xf, have_simd);
len = cpu_to_le64(ad_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
len = cpu_to_le64(dst_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
poly1305_finish(&poly1305_state, mac);
memzero_explicit(&poly1305_state, sizeof(poly1305_state));
@@ -635,15 +635,15 @@ bool chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src
}
bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN])
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN])
{
struct poly1305_ctx poly1305_state;
struct chacha20_ctx chacha20_state;
struct blkcipher_walk walk;
int ret;
- uint8_t block0[CHACHA20_BLOCK_SIZE] = { 0 };
- uint8_t read_mac[POLY1305_MAC_SIZE], computed_mac[POLY1305_MAC_SIZE];
+ u8 block0[CHACHA20_BLOCK_SIZE] = { 0 };
+ u8 read_mac[POLY1305_MAC_SIZE], computed_mac[POLY1305_MAC_SIZE];
size_t dst_len;
__le64 len;
__le64 le_nonce = cpu_to_le64(nonce);
@@ -654,7 +654,7 @@ bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *sr
have_simd = chacha20poly1305_init_simd();
- chacha20_keysetup(&chacha20_state, key, (uint8_t *)&le_nonce);
+ chacha20_keysetup(&chacha20_state, key, (u8 *)&le_nonce);
chacha20_crypt(&chacha20_state, block0, block0, sizeof(block0), have_simd);
poly1305_init(&poly1305_state, block0);
@@ -683,10 +683,10 @@ bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *sr
poly1305_update(&poly1305_state, pad0, (0x10 - dst_len) & 0xf, have_simd);
len = cpu_to_le64(ad_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
len = cpu_to_le64(dst_len);
- poly1305_update(&poly1305_state, (uint8_t *)&len, sizeof(len), have_simd);
+ poly1305_update(&poly1305_state, (u8 *)&len, sizeof(len), have_simd);
poly1305_finish(&poly1305_state, computed_mac);
memzero_explicit(&poly1305_state, sizeof(poly1305_state));
diff --git a/src/crypto/chacha20poly1305.h b/src/crypto/chacha20poly1305.h
index 4ffcd1e..2ae9ff5 100644
--- a/src/crypto/chacha20poly1305.h
+++ b/src/crypto/chacha20poly1305.h
@@ -14,22 +14,22 @@ enum chacha20poly1305_lengths {
void chacha20poly1305_init(void);
-bool chacha20poly1305_encrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN]);
+bool chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN]);
bool chacha20poly1305_encrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN],
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN],
bool have_simd);
-bool chacha20poly1305_decrypt(uint8_t *dst, const uint8_t *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN]);
+bool chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len,
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN]);
bool chacha20poly1305_decrypt_sg(struct scatterlist *dst, struct scatterlist *src, const size_t src_len,
- const uint8_t *ad, const size_t ad_len,
- const uint64_t nonce, const uint8_t key[CHACHA20POLY1305_KEYLEN]);
+ const u8 *ad, const size_t ad_len,
+ const u64 nonce, const u8 key[CHACHA20POLY1305_KEYLEN]);
#ifdef CONFIG_X86_64
#include <linux/version.h>
diff --git a/src/crypto/curve25519.c b/src/crypto/curve25519.c
index 41eeea8..ede5f10 100644
--- a/src/crypto/curve25519.c
+++ b/src/crypto/curve25519.c
@@ -16,7 +16,7 @@
#undef ARCH_HAS_SEPARATE_IRQ_STACK
#endif
-static __always_inline void normalize_secret(uint8_t secret[CURVE25519_POINT_SIZE])
+static __always_inline void normalize_secret(u8 secret[CURVE25519_POINT_SIZE])
{
secret[0] &= 248;
secret[31] &= 127;
@@ -24,7 +24,7 @@ static __always_inline void normalize_secret(uint8_t secret[CURVE25519_POINT_SIZ
}
#ifdef __SIZEOF_INT128__
-typedef uint64_t limb;
+typedef u64 limb;
typedef limb felem[5];
typedef __uint128_t uint128_t;
@@ -180,18 +180,18 @@ static __always_inline void fsquare_times(felem output, const felem in, limb cou
}
/* Load a little-endian 64-bit number */
-static inline limb load_limb(const uint8_t *in)
+static inline limb load_limb(const u8 *in)
{
- return le64_to_cpu(*(uint64_t *)in);
+ return le64_to_cpu(*(u64 *)in);
}
-static inline void store_limb(uint8_t *out, limb in)
+static inline void store_limb(u8 *out, limb in)
{
- *(uint64_t *)out = cpu_to_le64(in);
+ *(u64 *)out = cpu_to_le64(in);
}
/* Take a little-endian, 32-byte number and expand it into polynomial form */
-static inline void fexpand(limb *output, const uint8_t *in)
+static inline void fexpand(limb *output, const u8 *in)
{
output[0] = load_limb(in) & 0x7ffffffffffffUL;
output[1] = (load_limb(in + 6) >> 3) & 0x7ffffffffffffUL;
@@ -203,7 +203,7 @@ static inline void fexpand(limb *output, const uint8_t *in)
/* Take a fully reduced polynomial form number and contract it into a
* little-endian, 32-byte array
*/
-static void fcontract(uint8_t *output, const felem input)
+static void fcontract(u8 *output, const felem input)
{
uint128_t t[5];
@@ -324,7 +324,7 @@ static void swap_conditional(limb a[5], limb b[5], limb iswap)
* n: a little endian, 32-byte number
* q: a point of the curve (short form)
*/
-static void cmult(limb *resultx, limb *resultz, const uint8_t *n, const limb *q)
+static void cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q)
{
limb a[5] = {0}, b[5] = {1}, c[5] = {1}, d[5] = {0};
limb *nqpqx = a, *nqpqz = b, *nqx = c, *nqz = d, *t;
@@ -336,7 +336,7 @@ static void cmult(limb *resultx, limb *resultz, const uint8_t *n, const limb *q)
memcpy(nqpqx, q, sizeof(limb) * 5);
for (i = 0; i < 32; ++i) {
- uint8_t byte = n[31 - i];
+ u8 byte = n[31 - i];
for (j = 0; j < 8; ++j) {
const limb bit = byte >> 7;
@@ -399,10 +399,10 @@ static void crecip(felem out, const felem z)
/* 2^255 - 21 */ fmul(out, t0, a);
}
-void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE])
+void curve25519(u8 mypublic[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE], const u8 basepoint[CURVE25519_POINT_SIZE])
{
limb bp[5], x[5], z[5], zmone[5];
- uint8_t e[32];
+ u8 e[32];
memcpy(e, secret, 32);
normalize_secret(e);
@@ -421,7 +421,7 @@ void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CU
}
#else
-typedef int64_t limb;
+typedef s64 limb;
/* Field element representation:
*
@@ -466,106 +466,106 @@ static void fscalar_product(limb *output, const limb *in, const limb scalar)
* output[x] <= 14 * the largest product of the input limbs. */
static void fproduct(limb *output, const limb *in2, const limb *in)
{
- output[0] = ((limb) ((int32_t) in2[0])) * ((int32_t) in[0]);
- output[1] = ((limb) ((int32_t) in2[0])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[0]);
- output[2] = 2 * ((limb) ((int32_t) in2[1])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[0]);
- output[3] = ((limb) ((int32_t) in2[1])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[0]);
- output[4] = ((limb) ((int32_t) in2[2])) * ((int32_t) in[2]) +
- 2 * (((limb) ((int32_t) in2[1])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[1])) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[0]);
- output[5] = ((limb) ((int32_t) in2[2])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[0]);
- output[6] = 2 * (((limb) ((int32_t) in2[3])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[1])) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[0]);
- output[7] = ((limb) ((int32_t) in2[3])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[0]);
- output[8] = ((limb) ((int32_t) in2[4])) * ((int32_t) in[4]) +
- 2 * (((limb) ((int32_t) in2[3])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[1])) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[0]);
- output[9] = ((limb) ((int32_t) in2[4])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in2[0])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[0]);
- output[10] = 2 * (((limb) ((int32_t) in2[5])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[1])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[1])) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[2]);
- output[11] = ((limb) ((int32_t) in2[5])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in2[2])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[2]);
- output[12] = ((limb) ((int32_t) in2[6])) * ((int32_t) in[6]) +
- 2 * (((limb) ((int32_t) in2[5])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[3])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[3])) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[4]);
- output[13] = ((limb) ((int32_t) in2[6])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[7])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in2[4])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[4]);
- output[14] = 2 * (((limb) ((int32_t) in2[7])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[5])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[5])) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[6]);
- output[15] = ((limb) ((int32_t) in2[7])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in2[8])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in2[6])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[6]);
- output[16] = ((limb) ((int32_t) in2[8])) * ((int32_t) in[8]) +
- 2 * (((limb) ((int32_t) in2[7])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[7]));
- output[17] = ((limb) ((int32_t) in2[8])) * ((int32_t) in[9]) +
- ((limb) ((int32_t) in2[9])) * ((int32_t) in[8]);
- output[18] = 2 * ((limb) ((int32_t) in2[9])) * ((int32_t) in[9]);
+ output[0] = ((limb) ((s32) in2[0])) * ((s32) in[0]);
+ output[1] = ((limb) ((s32) in2[0])) * ((s32) in[1]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[0]);
+ output[2] = 2 * ((limb) ((s32) in2[1])) * ((s32) in[1]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[2])) * ((s32) in[0]);
+ output[3] = ((limb) ((s32) in2[1])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[2])) * ((s32) in[1]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[0]);
+ output[4] = ((limb) ((s32) in2[2])) * ((s32) in[2]) +
+ 2 * (((limb) ((s32) in2[1])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[1])) +
+ ((limb) ((s32) in2[0])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[4])) * ((s32) in[0]);
+ output[5] = ((limb) ((s32) in2[2])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[4])) * ((s32) in[1]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[0]);
+ output[6] = 2 * (((limb) ((s32) in2[3])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[1])) +
+ ((limb) ((s32) in2[2])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[4])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[0]);
+ output[7] = ((limb) ((s32) in2[3])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[4])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[2])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[1]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[0]);
+ output[8] = ((limb) ((s32) in2[4])) * ((s32) in[4]) +
+ 2 * (((limb) ((s32) in2[3])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[1])) +
+ ((limb) ((s32) in2[2])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[0]);
+ output[9] = ((limb) ((s32) in2[4])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[2])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[2]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[1]) +
+ ((limb) ((s32) in2[0])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[0]);
+ output[10] = 2 * (((limb) ((s32) in2[5])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[1])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[1])) +
+ ((limb) ((s32) in2[4])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[2])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[2]);
+ output[11] = ((limb) ((s32) in2[5])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[4])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[4]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[3]) +
+ ((limb) ((s32) in2[2])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[2]);
+ output[12] = ((limb) ((s32) in2[6])) * ((s32) in[6]) +
+ 2 * (((limb) ((s32) in2[5])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[3])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[3])) +
+ ((limb) ((s32) in2[4])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[4]);
+ output[13] = ((limb) ((s32) in2[6])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[7])) * ((s32) in[6]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[5]) +
+ ((limb) ((s32) in2[4])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[4]);
+ output[14] = 2 * (((limb) ((s32) in2[7])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[5])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[5])) +
+ ((limb) ((s32) in2[6])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[6]);
+ output[15] = ((limb) ((s32) in2[7])) * ((s32) in[8]) +
+ ((limb) ((s32) in2[8])) * ((s32) in[7]) +
+ ((limb) ((s32) in2[6])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[6]);
+ output[16] = ((limb) ((s32) in2[8])) * ((s32) in[8]) +
+ 2 * (((limb) ((s32) in2[7])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[7]));
+ output[17] = ((limb) ((s32) in2[8])) * ((s32) in[9]) +
+ ((limb) ((s32) in2[9])) * ((s32) in[8]);
+ output[18] = 2 * ((limb) ((s32) in2[9])) * ((s32) in[9]);
}
/* Reduce a long form to a short form by taking the input mod 2^255 - 19.
@@ -617,11 +617,11 @@ static void freduce_degree(limb *output)
static inline limb div_by_2_26(const limb v)
{
/* High word of v; no shift needed. */
- const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
+ const u32 highword = (u32) (((u64) v) >> 32);
/* Set to all 1s if v was negative; else set to 0s. */
- const int32_t sign = ((int32_t) highword) >> 31;
+ const s32 sign = ((s32) highword) >> 31;
/* Set to 0x3ffffff if v was negative; else set to 0. */
- const int32_t roundoff = ((uint32_t) sign) >> 6;
+ const s32 roundoff = ((u32) sign) >> 6;
/* Should return v / (1<<26) */
return (v + roundoff) >> 26;
}
@@ -632,11 +632,11 @@ static inline limb div_by_2_26(const limb v)
static inline limb div_by_2_25(const limb v)
{
/* High word of v; no shift needed*/
- const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
+ const u32 highword = (u32) (((u64) v) >> 32);
/* Set to all 1s if v was negative; else set to 0s. */
- const int32_t sign = ((int32_t) highword) >> 31;
+ const s32 sign = ((s32) highword) >> 31;
/* Set to 0x1ffffff if v was negative; else set to 0. */
- const int32_t roundoff = ((uint32_t) sign) >> 7;
+ const s32 roundoff = ((u32) sign) >> 7;
/* Should return v / (1<<25) */
return (v + roundoff) >> 25;
}
@@ -713,61 +713,61 @@ static void fmul(limb *output, const limb *in, const limb *in2)
* output[x] <= 14 * the largest product of the input limbs. */
static void fsquare_inner(limb *output, const limb *in)
{
- output[0] = ((limb) ((int32_t) in[0])) * ((int32_t) in[0]);
- output[1] = 2 * ((limb) ((int32_t) in[0])) * ((int32_t) in[1]);
- output[2] = 2 * (((limb) ((int32_t) in[1])) * ((int32_t) in[1]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[2]));
- output[3] = 2 * (((limb) ((int32_t) in[1])) * ((int32_t) in[2]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[3]));
- output[4] = ((limb) ((int32_t) in[2])) * ((int32_t) in[2]) +
- 4 * ((limb) ((int32_t) in[1])) * ((int32_t) in[3]) +
- 2 * ((limb) ((int32_t) in[0])) * ((int32_t) in[4]);
- output[5] = 2 * (((limb) ((int32_t) in[2])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in[1])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[5]));
- output[6] = 2 * (((limb) ((int32_t) in[3])) * ((int32_t) in[3]) +
- ((limb) ((int32_t) in[2])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[6]) +
- 2 * ((limb) ((int32_t) in[1])) * ((int32_t) in[5]));
- output[7] = 2 * (((limb) ((int32_t) in[3])) * ((int32_t) in[4]) +
- ((limb) ((int32_t) in[2])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in[1])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[7]));
- output[8] = ((limb) ((int32_t) in[4])) * ((int32_t) in[4]) +
- 2 * (((limb) ((int32_t) in[2])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[8]) +
- 2 * (((limb) ((int32_t) in[1])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[3])) * ((int32_t) in[5])));
- output[9] = 2 * (((limb) ((int32_t) in[4])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in[3])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in[2])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[1])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in[0])) * ((int32_t) in[9]));
- output[10] = 2 * (((limb) ((int32_t) in[5])) * ((int32_t) in[5]) +
- ((limb) ((int32_t) in[4])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in[2])) * ((int32_t) in[8]) +
- 2 * (((limb) ((int32_t) in[3])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[1])) * ((int32_t) in[9])));
- output[11] = 2 * (((limb) ((int32_t) in[5])) * ((int32_t) in[6]) +
- ((limb) ((int32_t) in[4])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[3])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in[2])) * ((int32_t) in[9]));
- output[12] = ((limb) ((int32_t) in[6])) * ((int32_t) in[6]) +
- 2 * (((limb) ((int32_t) in[4])) * ((int32_t) in[8]) +
- 2 * (((limb) ((int32_t) in[5])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[3])) * ((int32_t) in[9])));
- output[13] = 2 * (((limb) ((int32_t) in[6])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[5])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in[4])) * ((int32_t) in[9]));
- output[14] = 2 * (((limb) ((int32_t) in[7])) * ((int32_t) in[7]) +
- ((limb) ((int32_t) in[6])) * ((int32_t) in[8]) +
- 2 * ((limb) ((int32_t) in[5])) * ((int32_t) in[9]));
- output[15] = 2 * (((limb) ((int32_t) in[7])) * ((int32_t) in[8]) +
- ((limb) ((int32_t) in[6])) * ((int32_t) in[9]));
- output[16] = ((limb) ((int32_t) in[8])) * ((int32_t) in[8]) +
- 4 * ((limb) ((int32_t) in[7])) * ((int32_t) in[9]);
- output[17] = 2 * ((limb) ((int32_t) in[8])) * ((int32_t) in[9]);
- output[18] = 2 * ((limb) ((int32_t) in[9])) * ((int32_t) in[9]);
+ output[0] = ((limb) ((s32) in[0])) * ((s32) in[0]);
+ output[1] = 2 * ((limb) ((s32) in[0])) * ((s32) in[1]);
+ output[2] = 2 * (((limb) ((s32) in[1])) * ((s32) in[1]) +
+ ((limb) ((s32) in[0])) * ((s32) in[2]));
+ output[3] = 2 * (((limb) ((s32) in[1])) * ((s32) in[2]) +
+ ((limb) ((s32) in[0])) * ((s32) in[3]));
+ output[4] = ((limb) ((s32) in[2])) * ((s32) in[2]) +
+ 4 * ((limb) ((s32) in[1])) * ((s32) in[3]) +
+ 2 * ((limb) ((s32) in[0])) * ((s32) in[4]);
+ output[5] = 2 * (((limb) ((s32) in[2])) * ((s32) in[3]) +
+ ((limb) ((s32) in[1])) * ((s32) in[4]) +
+ ((limb) ((s32) in[0])) * ((s32) in[5]));
+ output[6] = 2 * (((limb) ((s32) in[3])) * ((s32) in[3]) +
+ ((limb) ((s32) in[2])) * ((s32) in[4]) +
+ ((limb) ((s32) in[0])) * ((s32) in[6]) +
+ 2 * ((limb) ((s32) in[1])) * ((s32) in[5]));
+ output[7] = 2 * (((limb) ((s32) in[3])) * ((s32) in[4]) +
+ ((limb) ((s32) in[2])) * ((s32) in[5]) +
+ ((limb) ((s32) in[1])) * ((s32) in[6]) +
+ ((limb) ((s32) in[0])) * ((s32) in[7]));
+ output[8] = ((limb) ((s32) in[4])) * ((s32) in[4]) +
+ 2 * (((limb) ((s32) in[2])) * ((s32) in[6]) +
+ ((limb) ((s32) in[0])) * ((s32) in[8]) +
+ 2 * (((limb) ((s32) in[1])) * ((s32) in[7]) +
+ ((limb) ((s32) in[3])) * ((s32) in[5])));
+ output[9] = 2 * (((limb) ((s32) in[4])) * ((s32) in[5]) +
+ ((limb) ((s32) in[3])) * ((s32) in[6]) +
+ ((limb) ((s32) in[2])) * ((s32) in[7]) +
+ ((limb) ((s32) in[1])) * ((s32) in[8]) +
+ ((limb) ((s32) in[0])) * ((s32) in[9]));
+ output[10] = 2 * (((limb) ((s32) in[5])) * ((s32) in[5]) +
+ ((limb) ((s32) in[4])) * ((s32) in[6]) +
+ ((limb) ((s32) in[2])) * ((s32) in[8]) +
+ 2 * (((limb) ((s32) in[3])) * ((s32) in[7]) +
+ ((limb) ((s32) in[1])) * ((s32) in[9])));
+ output[11] = 2 * (((limb) ((s32) in[5])) * ((s32) in[6]) +
+ ((limb) ((s32) in[4])) * ((s32) in[7]) +
+ ((limb) ((s32) in[3])) * ((s32) in[8]) +
+ ((limb) ((s32) in[2])) * ((s32) in[9]));
+ output[12] = ((limb) ((s32) in[6])) * ((s32) in[6]) +
+ 2 * (((limb) ((s32) in[4])) * ((s32) in[8]) +
+ 2 * (((limb) ((s32) in[5])) * ((s32) in[7]) +
+ ((limb) ((s32) in[3])) * ((s32) in[9])));
+ output[13] = 2 * (((limb) ((s32) in[6])) * ((s32) in[7]) +
+ ((limb) ((s32) in[5])) * ((s32) in[8]) +
+ ((limb) ((s32) in[4])) * ((s32) in[9]));
+ output[14] = 2 * (((limb) ((s32) in[7])) * ((s32) in[7]) +
+ ((limb) ((s32) in[6])) * ((s32) in[8]) +
+ 2 * ((limb) ((s32) in[5])) * ((s32) in[9]));
+ output[15] = 2 * (((limb) ((s32) in[7])) * ((s32) in[8]) +
+ ((limb) ((s32) in[6])) * ((s32) in[9]));
+ output[16] = ((limb) ((s32) in[8])) * ((s32) in[8]) +
+ 4 * ((limb) ((s32) in[7])) * ((s32) in[9]);
+ output[17] = 2 * ((limb) ((s32) in[8])) * ((s32) in[9]);
+ output[18] = 2 * ((limb) ((s32) in[9])) * ((s32) in[9]);
}
/* fsquare sets output = in^2.
@@ -791,7 +791,7 @@ static void fsquare(limb *output, const limb *in)
}
/* Take a little-endian, 32-byte number and expand it into polynomial form */
-static inline void fexpand(limb *output, const uint8_t *input)
+static inline void fexpand(limb *output, const u8 *input)
{
#define F(n,start,shift,mask) \
output[n] = ((((limb) input[start + 0]) | \
@@ -815,8 +815,8 @@ static inline void fexpand(limb *output, const uint8_t *input)
#error "This code only works when >> does sign-extension on negative numbers"
#endif
-/* int32_t_eq returns 0xffffffff iff a == b and zero otherwise. */
-static int32_t int32_t_eq(int32_t a, int32_t b)
+/* s32_eq returns 0xffffffff iff a == b and zero otherwise. */
+static s32 s32_eq(s32 a, s32 b)
{
a = ~(a ^ b);
a &= a << 16;
@@ -827,9 +827,9 @@ static int32_t int32_t_eq(int32_t a, int32_t b)
return a >> 31;
}
-/* int32_t_gte returns 0xffffffff if a >= b and zero otherwise, where a and b are
+/* s32_gte returns 0xffffffff if a >= b and zero otherwise, where a and b are
* both non-negative. */
-static int32_t int32_t_gte(int32_t a, int32_t b)
+static s32 s32_gte(s32 a, s32 b)
{
a -= b;
/* a >= 0 iff a >= b. */
@@ -840,14 +840,14 @@ static int32_t int32_t_gte(int32_t a, int32_t b)
* little-endian, 32-byte array.
*
* On entry: |input_limbs[i]| < 2^26 */
-static void fcontract(uint8_t *output, limb *input_limbs)
+static void fcontract(u8 *output, limb *input_limbs)
{
int i;
int j;
- int32_t input[10];
- int32_t mask;
+ s32 input[10];
+ s32 mask;
- /* |input_limbs[i]| < 2^26, so it's valid to convert to an int32_t. */
+ /* |input_limbs[i]| < 2^26, so it's valid to convert to an s32. */
for (i = 0; i < 10; i++) {
input[i] = input_limbs[i];
}
@@ -857,13 +857,13 @@ static void fcontract(uint8_t *output, limb *input_limbs)
if ((i & 1) == 1) {
/* This calculation is a time-invariant way to make input[i]
* non-negative by borrowing from the next-larger limb. */
- const int32_t mask = input[i] >> 31;
- const int32_t carry = -((input[i] & mask) >> 25);
+ const s32 mask = input[i] >> 31;
+ const s32 carry = -((input[i] & mask) >> 25);
input[i] = input[i] + (carry << 25);
input[i+1] = input[i+1] - carry;
} else {
- const int32_t mask = input[i] >> 31;
- const int32_t carry = -((input[i] & mask) >> 26);
+ const s32 mask = input[i] >> 31;
+ const s32 carry = -((input[i] & mask) >> 26);
input[i] = input[i] + (carry << 26);
input[i+1] = input[i+1] - carry;
}
@@ -872,8 +872,8 @@ static void fcontract(uint8_t *output, limb *input_limbs)
/* There's no greater limb for input[9] to borrow from, but we can multiply
* by 19 and borrow from input[0], which is valid mod 2^255-19. */
{
- const int32_t mask = input[9] >> 31;
- const int32_t carry = -((input[9] & mask) >> 25);
+ const s32 mask = input[9] >> 31;
+ const s32 carry = -((input[9] & mask) >> 25);
input[9] = input[9] + (carry << 25);
input[0] = input[0] - (carry * 19);
}
@@ -894,8 +894,8 @@ static void fcontract(uint8_t *output, limb *input_limbs)
through input[9] were all zero. In that case, input[1] is now 2^25 - 1,
and this last borrow-propagation step will leave input[1] non-negative. */
{
- const int32_t mask = input[0] >> 31;
- const int32_t carry = -((input[0] & mask) >> 26);
+ const s32 mask = input[0] >> 31;
+ const s32 carry = -((input[0] & mask) >> 26);
input[0] = input[0] + (carry << 26);
input[1] = input[1] - carry;
}
@@ -905,18 +905,18 @@ static void fcontract(uint8_t *output, limb *input_limbs)
for (j = 0; j < 2; j++) {
for (i = 0; i < 9; i++) {
if ((i & 1) == 1) {
- const int32_t carry = input[i] >> 25;
+ const s32 carry = input[i] >> 25;
input[i] &= 0x1ffffff;
input[i+1] += carry;
} else {
- const int32_t carry = input[i] >> 26;
+ const s32 carry = input[i] >> 26;
input[i] &= 0x3ffffff;
input[i+1] += carry;
}
}
{
- const int32_t carry = input[9] >> 25;
+ const s32 carry = input[9] >> 25;
input[9] &= 0x1ffffff;
input[0] += 19*carry;
}
@@ -932,12 +932,12 @@ static void fcontract(uint8_t *output, limb *input_limbs)
/* It still remains the case that input might be between 2^255-19 and 2^255.
* In this case, input[1..9] must take their maximum value and input[0] must
* be >= (2^255-19) & 0x3ffffff, which is 0x3ffffed. */
- mask = int32_t_gte(input[0], 0x3ffffed);
+ mask = s32_gte(input[0], 0x3ffffed);
for (i = 1; i < 10; i++) {
if ((i & 1) == 1) {
- mask &= int32_t_eq(input[i], 0x1ffffff);
+ mask &= s32_eq(input[i], 0x1ffffff);
} else {
- mask &= int32_t_eq(input[i], 0x3ffffff);
+ mask &= s32_eq(input[i], 0x3ffffff);
}
}
@@ -993,12 +993,12 @@ static void fcontract(uint8_t *output, limb *input_limbs)
static void swap_conditional(limb a[19], limb b[19], limb iswap)
{
unsigned i;
- const int32_t swap = (int32_t) -iswap;
+ const s32 swap = (s32) -iswap;
for (i = 0; i < 10; ++i) {
- const int32_t x = swap & ( ((int32_t)a[i]) ^ ((int32_t)b[i]) );
- a[i] = ((int32_t)a[i]) ^ x;
- b[i] = ((int32_t)b[i]) ^ x;
+ const s32 x = swap & ( ((s32)a[i]) ^ ((s32)b[i]) );
+ a[i] = ((s32)a[i]) ^ x;
+ b[i] = ((s32)b[i]) ^ x;
}
}
@@ -1163,7 +1163,7 @@ static void fmonty(limb *x2, limb *z2, /* output 2Q */
* resultx/resultz: the x coordinate of the resulting curve point (short form)
* n: a little endian, 32-byte number
* q: a point of the curve (short form) */
-static void cmult(limb *resultx, limb *resultz, const uint8_t *n, const limb *q)
+static void cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q)
{
limb a[19] = {0}, b[19] = {1}, c[19] = {1}, d[19] = {0};
limb *nqpqx = a, *nqpqz = b, *nqx = c, *nqz = d, *t;
@@ -1175,7 +1175,7 @@ static void cmult(limb *resultx, limb *resultz, const uint8_t *n, const limb *q)
memcpy(nqpqx, q, sizeof(limb) * 10);
for (i = 0; i < 32; ++i) {
- uint8_t byte = n[31 - i];
+ u8 byte = n[31 - i];
for (j = 0; j < 8; ++j) {
const limb bit = byte >> 7;
@@ -1210,10 +1210,10 @@ static void cmult(limb *resultx, limb *resultz, const uint8_t *n, const limb *q)
memcpy(resultz, nqz, sizeof(limb) * 10);
}
-void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE])
+void curve25519(u8 mypublic[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE], const u8 basepoint[CURVE25519_POINT_SIZE])
{
limb bp[10], x[10], z[11], zmone[10];
- uint8_t e[32];
+ u8 e[32];
memcpy(e, secret, 32);
normalize_secret(e);
@@ -1235,7 +1235,7 @@ struct other_stack {
limb origx[10], origxprime[10], zzz[19], xx[19], zz[19], xxprime[19], zzprime[19], zzzprime[19], xxxprime[19];
limb a[19], b[19], c[19], d[19], e[19], f[19], g[19], h[19];
limb bp[10], x[10], z[11], zmone[10];
- uint8_t ee[32];
+ u8 ee[32];
};
/* Input: Q, Q', Q-Q'
@@ -1328,7 +1328,7 @@ static void fmonty(struct other_stack *s,
* resultx/resultz: the x coordinate of the resulting curve point (short form)
* n: a little endian, 32-byte number
* q: a point of the curve (short form) */
-static void cmult(struct other_stack *s, limb *resultx, limb *resultz, const uint8_t *n, const limb *q)
+static void cmult(struct other_stack *s, limb *resultx, limb *resultz, const u8 *n, const limb *q)
{
unsigned i, j;
limb *nqpqx = s->a, *nqpqz = s->b, *nqx = s->c, *nqz = s->d, *t;
@@ -1338,7 +1338,7 @@ static void cmult(struct other_stack *s, limb *resultx, limb *resultz, const uin
memcpy(nqpqx, q, sizeof(limb) * 10);
for (i = 0; i < 32; ++i) {
- uint8_t byte = n[31 - i];
+ u8 byte = n[31 - i];
for (j = 0; j < 8; ++j) {
const limb bit = byte >> 7;
@@ -1374,7 +1374,7 @@ static void cmult(struct other_stack *s, limb *resultx, limb *resultz, const uin
memcpy(resultz, nqz, sizeof(limb) * 10);
}
-void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE])
+void curve25519(u8 mypublic[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE], const u8 basepoint[CURVE25519_POINT_SIZE])
{
struct other_stack *s = kzalloc(sizeof(struct other_stack), GFP_KERNEL);
if (unlikely(!s)) {
@@ -1396,15 +1396,15 @@ void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CU
#endif
#endif
-void curve25519_generate_secret(uint8_t secret[CURVE25519_POINT_SIZE])
+void curve25519_generate_secret(u8 secret[CURVE25519_POINT_SIZE])
{
get_random_bytes(secret, CURVE25519_POINT_SIZE);
normalize_secret(secret);
}
-void curve25519_generate_public(uint8_t pub[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE])
+void curve25519_generate_public(u8 pub[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE])
{
- static const uint8_t basepoint[CURVE25519_POINT_SIZE] = { 9 };
+ static const u8 basepoint[CURVE25519_POINT_SIZE] = { 9 };
curve25519(pub, secret, basepoint);
}
diff --git a/src/crypto/curve25519.h b/src/crypto/curve25519.h
index 361b858..bd89e31 100644
--- a/src/crypto/curve25519.h
+++ b/src/crypto/curve25519.h
@@ -9,9 +9,9 @@ enum curve25519_lengths {
CURVE25519_POINT_SIZE = 32
};
-void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE]);
-void curve25519_generate_secret(uint8_t secret[CURVE25519_POINT_SIZE]);
-void curve25519_generate_public(uint8_t pub[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE]);
+void curve25519(u8 mypublic[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE], const u8 basepoint[CURVE25519_POINT_SIZE]);
+void curve25519_generate_secret(u8 secret[CURVE25519_POINT_SIZE]);
+void curve25519_generate_public(u8 pub[CURVE25519_POINT_SIZE], const u8 secret[CURVE25519_POINT_SIZE]);
#ifdef DEBUG
bool curve25519_selftest(void);
diff --git a/src/crypto/siphash24.c b/src/crypto/siphash24.c
index 1d3865a..d841894 100644
--- a/src/crypto/siphash24.c
+++ b/src/crypto/siphash24.c
@@ -4,7 +4,7 @@
#include <linux/kernel.h>
-#define ROTL(x,b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
+#define ROTL(x,b) (u64)(((x) << (b)) | ((x) >> (64 - (b))))
#define U8TO64(p) le64_to_cpu(*(__le64 *)(p))
#define SIPROUND \
@@ -16,24 +16,24 @@
} while(0)
__attribute__((optimize("unroll-loops")))
-uint64_t siphash24(const uint8_t *data, size_t len, const uint8_t key[SIPHASH24_KEY_LEN])
+u64 siphash24(const u8 *data, size_t len, const u8 key[SIPHASH24_KEY_LEN])
{
- uint64_t v0 = 0x736f6d6570736575ULL;
- uint64_t v1 = 0x646f72616e646f6dULL;
- uint64_t v2 = 0x6c7967656e657261ULL;
- uint64_t v3 = 0x7465646279746573ULL;
- uint64_t b;
- uint64_t k0 = U8TO64(key);
- uint64_t k1 = U8TO64(key + sizeof(uint64_t));
- uint64_t m;
- const uint8_t *end = data + len - (len % sizeof(uint64_t));
- const uint8_t left = len & (sizeof(uint64_t) - 1);
- b = ((uint64_t)len) << 56;
+ u64 v0 = 0x736f6d6570736575ULL;
+ u64 v1 = 0x646f72616e646f6dULL;
+ u64 v2 = 0x6c7967656e657261ULL;
+ u64 v3 = 0x7465646279746573ULL;
+ u64 b;
+ u64 k0 = U8TO64(key);
+ u64 k1 = U8TO64(key + sizeof(u64));
+ u64 m;
+ const u8 *end = data + len - (len % sizeof(u64));
+ const u8 left = len & (sizeof(u64) - 1);
+ b = ((u64)len) << 56;
v3 ^= k1;
v2 ^= k0;
v1 ^= k1;
v0 ^= k0;
- for (; data != end; data += sizeof(uint64_t)) {
+ for (; data != end; data += sizeof(u64)) {
m = U8TO64(data);
v3 ^= m;
SIPROUND;
@@ -41,13 +41,13 @@ uint64_t siphash24(const uint8_t *data, size_t len, const uint8_t key[SIPHASH24_
v0 ^= m;
}
switch (left) {
- case 7: b |= ((uint64_t)data[6]) << 48;
- case 6: b |= ((uint64_t)data[5]) << 40;
- case 5: b |= ((uint64_t)data[4]) << 32;
- case 4: b |= ((uint64_t)data[3]) << 24;
- case 3: b |= ((uint64_t)data[2]) << 16;
- case 2: b |= ((uint64_t)data[1]) << 8;
- case 1: b |= ((uint64_t)data[0]); break;
+ case 7: b |= ((u64)data[6]) << 48;
+ case 6: b |= ((u64)data[5]) << 40;
+ case 5: b |= ((u64)data[4]) << 32;
+ case 4: b |= ((u64)data[3]) << 24;
+ case 3: b |= ((u64)data[2]) << 16;
+ case 2: b |= ((u64)data[1]) << 8;
+ case 1: b |= ((u64)data[0]); break;
case 0: break;
}
v3 ^= b;
@@ -60,7 +60,7 @@ uint64_t siphash24(const uint8_t *data, size_t len, const uint8_t key[SIPHASH24_
SIPROUND;
SIPROUND;
b = (v0 ^ v1) ^ (v2 ^ v3);
- return (__force uint64_t)cpu_to_le64(b);
+ return (__force u64)cpu_to_le64(b);
}
#include "../selftest/siphash24.h"
diff --git a/src/crypto/siphash24.h b/src/crypto/siphash24.h
index 5d99cb3..2ac9649 100644
--- a/src/crypto/siphash24.h
+++ b/src/crypto/siphash24.h
@@ -9,7 +9,7 @@ enum siphash24_lengths {
SIPHASH24_KEY_LEN = 16
};
-uint64_t siphash24(const uint8_t *data, size_t len, const uint8_t key[SIPHASH24_KEY_LEN]);
+u64 siphash24(const u8 *data, size_t len, const u8 key[SIPHASH24_KEY_LEN]);
#ifdef DEBUG
bool siphash24_selftest(void);
diff --git a/src/data.c b/src/data.c
index 628a3ce..ae2515b 100644
--- a/src/data.c
+++ b/src/data.c
@@ -16,11 +16,11 @@
#include <crypto/algapi.h>
struct encryption_skb_cb {
- uint8_t ds;
- uint8_t num_frags;
+ u8 ds;
+ u8 num_frags;
unsigned int plaintext_len, trailer_len;
struct sk_buff *trailer;
- uint64_t nonce;
+ u64 nonce;
};
struct encryption_ctx {
@@ -37,8 +37,8 @@ struct decryption_ctx {
void (*callback)(struct sk_buff *skb, struct wireguard_peer *, struct endpoint *, bool used_new_key, int err);
struct noise_keypair *keypair;
struct endpoint endpoint;
- uint64_t nonce;
- uint8_t num_frags;
+ u64 nonce;
+ u8 num_frags;
int ret;
};
@@ -157,7 +157,7 @@ static inline void skb_encrypt(struct sk_buff *skb, struct noise_keypair *keypai
chacha20poly1305_encrypt_sg(sg, sg, cb->plaintext_len, NULL, 0, cb->nonce, keypair->sending.key, have_simd);
}
-static inline bool skb_decrypt(struct sk_buff *skb, uint8_t num_frags, uint64_t nonce, struct noise_symmetric_key *key)
+static inline bool skb_decrypt(struct sk_buff *skb, u8 num_frags, u64 nonce, struct noise_symmetric_key *key)
{
struct scatterlist sg[num_frags]; /* This should be bound to at most 128 by the caller. */
@@ -178,7 +178,7 @@ static inline bool skb_decrypt(struct sk_buff *skb, uint8_t num_frags, uint64_t
return pskb_trim(skb, skb->len - noise_encrypted_len(0)) == 0;
}
-static inline bool get_encryption_nonce(uint64_t *nonce, struct noise_symmetric_key *key)
+static inline bool get_encryption_nonce(u64 *nonce, struct noise_symmetric_key *key)
{
if (unlikely(!key))
return false;
@@ -417,7 +417,7 @@ void packet_consume_data(struct sk_buff *skb, size_t offset, struct wireguard_de
struct sk_buff *trailer;
struct message_data *header;
struct noise_keypair *keypair;
- uint64_t nonce;
+ u64 nonce;
__le32 idx;
ret = socket_endpoint_from_skb(&endpoint, skb);
diff --git a/src/hashtables.c b/src/hashtables.c
index f30f6cf..7b9fb7b 100644
--- a/src/hashtables.c
+++ b/src/hashtables.c
@@ -7,7 +7,7 @@
#include <linux/hashtable.h>
-static inline struct hlist_head *pubkey_bucket(struct pubkey_hashtable *table, const uint8_t pubkey[NOISE_PUBLIC_KEY_LEN])
+static inline struct hlist_head *pubkey_bucket(struct pubkey_hashtable *table, const u8 pubkey[NOISE_PUBLIC_KEY_LEN])
{
/* siphash24 gives us a secure 64bit number based on a random key. Since the bits are
* uniformly distributed, we can then mask off to get the bits we need. */
@@ -36,7 +36,7 @@ void pubkey_hashtable_remove(struct pubkey_hashtable *table, struct wireguard_pe
}
/* Returns a strong reference to a peer */
-struct wireguard_peer *pubkey_hashtable_lookup(struct pubkey_hashtable *table, const uint8_t pubkey[NOISE_PUBLIC_KEY_LEN])
+struct wireguard_peer *pubkey_hashtable_lookup(struct pubkey_hashtable *table, const u8 pubkey[NOISE_PUBLIC_KEY_LEN])
{
struct wireguard_peer *iter_peer, *peer = NULL;
rcu_read_lock();
@@ -68,7 +68,7 @@ void index_hashtable_init(struct index_hashtable *table)
__le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashtable_entry *entry)
{
struct index_hashtable_entry *existing_entry;
- uint64_t rand;
+ u64 rand;
spin_lock(&table->lock);
hlist_del_init_rcu(&entry->index_hash);
@@ -79,7 +79,7 @@ __le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashta
search_unused_slot:
/* First we try to find an unused slot, randomly, while unlocked. */
rand = get_random_long();
- entry->index = (__force __le32)siphash24((uint8_t *)&rand, sizeof(rand), table->key);
+ entry->index = (__force __le32)siphash24((u8 *)&rand, sizeof(rand), table->key);
hlist_for_each_entry_rcu(existing_entry, index_bucket(table, entry->index), index_hash) {
if (existing_entry->index == entry->index)
goto search_unused_slot; /* If it's already in use, we continue searching. */
diff --git a/src/hashtables.h b/src/hashtables.h
index 5a87a72..fd3ff8b 100644
--- a/src/hashtables.h
+++ b/src/hashtables.h
@@ -13,18 +13,18 @@ struct wireguard_peer;
struct pubkey_hashtable {
DECLARE_HASHTABLE(hashtable, 8);
- uint8_t key[SIPHASH24_KEY_LEN];
+ u8 key[SIPHASH24_KEY_LEN];
struct mutex lock;
};
void pubkey_hashtable_init(struct pubkey_hashtable *table);
void pubkey_hashtable_add(struct pubkey_hashtable *table, struct wireguard_peer *peer);
void pubkey_hashtable_remove(struct pubkey_hashtable *table, struct wireguard_peer *peer);
-struct wireguard_peer *pubkey_hashtable_lookup(struct pubkey_hashtable *table, const uint8_t pubkey[NOISE_PUBLIC_KEY_LEN]);
+struct wireguard_peer *pubkey_hashtable_lookup(struct pubkey_hashtable *table, const u8 pubkey[NOISE_PUBLIC_KEY_LEN]);
struct index_hashtable {
DECLARE_HASHTABLE(hashtable, 10);
- uint8_t key[SIPHASH24_KEY_LEN];
+ u8 key[SIPHASH24_KEY_LEN];
spinlock_t lock;
};
diff --git a/src/noise.h b/src/noise.h
index f166cdc..724b0d0 100644
--- a/src/noise.h
+++ b/src/noise.h
@@ -30,7 +30,7 @@ union noise_counter {
struct noise_symmetric_key {
u8 key[NOISE_SYMMETRIC_KEY_LEN];
union noise_counter counter;
- uint64_t birthdate;
+ u64 birthdate;
bool is_valid;
};
@@ -42,7 +42,7 @@ struct noise_keypair {
bool i_am_the_initiator;
struct kref refcount;
struct rcu_head rcu;
- uint64_t internal_id;
+ u64 internal_id;
};
struct noise_keypairs {
@@ -72,7 +72,7 @@ struct noise_handshake {
struct index_hashtable_entry entry;
enum noise_handshake_state state;
- uint64_t last_initiation_consumption;
+ u64 last_initiation_consumption;
struct noise_static_identity *static_identity;
diff --git a/src/peer.h b/src/peer.h
index 17e166f..9e22168 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -35,11 +35,11 @@ struct wireguard_peer {
rwlock_t endpoint_lock;
struct noise_handshake handshake;
struct noise_keypairs keypairs;
- uint64_t last_sent_handshake;
+ u64 last_sent_handshake;
struct work_struct transmit_handshake_work, clear_peer_work;
struct cookie latest_cookie;
struct hlist_node pubkey_hash;
- uint64_t rx_bytes, tx_bytes;
+ u64 rx_bytes, tx_bytes;
struct timer_list timer_retransmit_handshake, timer_send_keepalive, timer_new_handshake, timer_kill_ephemerals, timer_persistent_keepalive;
unsigned int timer_handshake_attempts;
unsigned long persistent_keepalive_interval;
@@ -51,7 +51,7 @@ struct wireguard_peer {
struct kref refcount;
struct rcu_head rcu;
struct list_head peer_list;
- uint64_t internal_id;
+ u64 internal_id;
#ifdef CONFIG_WIREGUARD_PARALLEL
atomic_t parallel_encryption_inflight;
#endif
diff --git a/src/routingtable.c b/src/routingtable.c
index 6f56cd6..dee5e89 100644
--- a/src/routingtable.c
+++ b/src/routingtable.c
@@ -7,17 +7,17 @@ struct routing_table_node {
struct routing_table_node __rcu *bit[2];
struct rcu_head rcu;
struct wireguard_peer *peer;
- uint8_t cidr;
- uint8_t bit_at_a, bit_at_b;
+ u8 cidr;
+ u8 bit_at_a, bit_at_b;
bool incidental;
- uint8_t bits[];
+ u8 bits[];
};
-static inline uint8_t bit_at(const uint8_t *key, uint8_t a, uint8_t b)
+static inline u8 bit_at(const u8 *key, u8 a, u8 b)
{
return (key[a] >> b) & 1;
}
-static inline void assign_cidr(struct routing_table_node *node, uint8_t cidr)
+static inline void assign_cidr(struct routing_table_node *node, u8 cidr)
{
node->cidr = cidr;
node->bit_at_a = cidr / 8;
@@ -115,12 +115,12 @@ static bool walk_remove_by_peer(struct routing_table_node __rcu **top, struct wi
#undef ref
#undef push
-static inline bool match(const struct routing_table_node *node, const uint8_t *key, uint8_t match_len)
+static inline bool match(const struct routing_table_node *node, const u8 *key, u8 match_len)
{
- uint8_t full_blocks_to_match = match_len / 8;
- uint8_t bits_leftover = match_len % 8;
- uint8_t mask;
- const uint8_t *a = node->bits, *b = key;
+ u8 full_blocks_to_match = match_len / 8;
+ u8 bits_leftover = match_len % 8;
+ u8 mask;
+ const u8 *a = node->bits, *b = key;
if (memcmp(a, b, full_blocks_to_match))
return false;
if (!bits_leftover)
@@ -129,12 +129,12 @@ static inline bool match(const struct routing_table_node *node, const uint8_t *k
return (a[full_blocks_to_match] & mask) == (b[full_blocks_to_match] & mask);
}
-static inline uint8_t common_bits(const struct routing_table_node *node, const uint8_t *key, uint8_t match_len)
+static inline u8 common_bits(const struct routing_table_node *node, const u8 *key, u8 match_len)
{
- uint8_t max = (((match_len > node->cidr) ? match_len : node->cidr) + 7) / 8;
- uint8_t bits = 0;
- uint8_t i, mask;
- const uint8_t *a = node->bits, *b = key;
+ u8 max = (((match_len > node->cidr) ? match_len : node->cidr) + 7) / 8;
+ u8 bits = 0;
+ u8 i, mask;
+ const u8 *a = node->bits, *b = key;
for (i = 0; i < max; ++i, bits += 8) {
if (a[i] != b[i])
break;
@@ -149,7 +149,7 @@ static inline uint8_t common_bits(const struct routing_table_node *node, const u
return bits;
}
-static int remove(struct routing_table_node __rcu **trie, const uint8_t *key, uint8_t cidr, struct mutex *lock)
+static int remove(struct routing_table_node __rcu **trie, const u8 *key, u8 cidr, struct mutex *lock)
{
struct routing_table_node *parent = NULL, *node;
node = rcu_dereference_protected(*trie, lockdep_is_held(lock));
@@ -175,7 +175,7 @@ static int remove(struct routing_table_node __rcu **trie, const uint8_t *key, ui
return -ENOENT;
}
-static inline struct routing_table_node *find_node(struct routing_table_node *trie, uint8_t bits, const uint8_t *key)
+static inline struct routing_table_node *find_node(struct routing_table_node *trie, u8 bits, const u8 *key)
{
struct routing_table_node *node = trie, *found = NULL;
while (node && match(node, key, node->cidr)) {
@@ -188,7 +188,7 @@ static inline struct routing_table_node *find_node(struct routing_table_node *tr
return found;
}
-static inline bool node_placement(struct routing_table_node __rcu *trie, const uint8_t *key, uint8_t cidr, struct routing_table_node **rnode, struct mutex *lock)
+static inline bool node_placement(struct routing_table_node __rcu *trie, const u8 *key, u8 cidr, struct routing_table_node **rnode, struct mutex *lock)
{
bool exact = false;
struct routing_table_node *parent = NULL, *node = rcu_dereference_protected(trie, lockdep_is_held(lock));
@@ -205,7 +205,7 @@ static inline bool node_placement(struct routing_table_node __rcu *trie, const u
return exact;
}
-static int add(struct routing_table_node __rcu **trie, uint8_t bits, const uint8_t *key, uint8_t cidr, struct wireguard_peer *peer, struct mutex *lock)
+static int add(struct routing_table_node __rcu **trie, u8 bits, const u8 *key, u8 cidr, struct wireguard_peer *peer, struct mutex *lock)
{
struct routing_table_node *node, *parent, *down, *newnode;
int bits_in_common;
@@ -289,7 +289,7 @@ static int add(struct routing_table_node __rcu **trie, uint8_t bits, const uint8
stack[len++] = next; \
} \
} while (0)
-static int walk_ips(struct routing_table_node *top, int family, void *ctx, int (*func)(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, uint8_t cidr, int family), struct mutex *maybe_lock)
+static int walk_ips(struct routing_table_node *top, int family, void *ctx, int (*func)(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, u8 cidr, int family), struct mutex *maybe_lock)
{
int ret;
union nf_inet_addr ip = { .all = { 0 } };
@@ -319,7 +319,7 @@ static int walk_ips(struct routing_table_node *top, int family, void *ctx, int (
}
return 0;
}
-static int walk_ips_by_peer(struct routing_table_node *top, int family, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, uint8_t cidr, int family), struct mutex *maybe_lock)
+static int walk_ips_by_peer(struct routing_table_node *top, int family, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, u8 cidr, int family), struct mutex *maybe_lock)
{
int ret;
union nf_inet_addr ip = { .all = { 0 } };
@@ -364,24 +364,24 @@ void routing_table_free(struct routing_table *table)
mutex_unlock(&table->table_update_lock);
}
-int routing_table_insert_v4(struct routing_table *table, const struct in_addr *ip, uint8_t cidr, struct wireguard_peer *peer)
+int routing_table_insert_v4(struct routing_table *table, const struct in_addr *ip, u8 cidr, struct wireguard_peer *peer)
{
int ret;
if (cidr > 32)
return -EINVAL;
mutex_lock(&table->table_update_lock);
- ret = add(&table->root4, 32, (const uint8_t *)ip, cidr, peer, &table->table_update_lock);
+ ret = add(&table->root4, 32, (const u8 *)ip, cidr, peer, &table->table_update_lock);
mutex_unlock(&table->table_update_lock);
return ret;
}
-int routing_table_insert_v6(struct routing_table *table, const struct in6_addr *ip, uint8_t cidr, struct wireguard_peer *peer)
+int routing_table_insert_v6(struct routing_table *table, const struct in6_addr *ip, u8 cidr, struct wireguard_peer *peer)
{
int ret;
if (cidr > 128)
return -EINVAL;
mutex_lock(&table->table_update_lock);
- ret = add(&table->root6, 128, (const uint8_t *)ip, cidr, peer, &table->table_update_lock);
+ ret = add(&table->root6, 128, (const u8 *)ip, cidr, peer, &table->table_update_lock);
mutex_unlock(&table->table_update_lock);
return ret;
}
@@ -393,7 +393,7 @@ inline struct wireguard_peer *routing_table_lookup_v4(struct routing_table *tabl
struct routing_table_node *node;
rcu_read_lock();
- node = find_node(rcu_dereference(table->root4), 32, (const uint8_t *)ip);
+ node = find_node(rcu_dereference(table->root4), 32, (const u8 *)ip);
if (node)
peer = peer_get(node->peer);
rcu_read_unlock();
@@ -407,27 +407,27 @@ inline struct wireguard_peer *routing_table_lookup_v6(struct routing_table *tabl
struct routing_table_node *node;
rcu_read_lock();
- node = find_node(rcu_dereference(table->root6), 128, (const uint8_t *)ip);
+ node = find_node(rcu_dereference(table->root6), 128, (const u8 *)ip);
if (node)
peer = peer_get(node->peer);
rcu_read_unlock();
return peer;
}
-int routing_table_remove_v4(struct routing_table *table, const struct in_addr *ip, uint8_t cidr)
+int routing_table_remove_v4(struct routing_table *table, const struct in_addr *ip, u8 cidr)
{
int ret;
mutex_lock(&table->table_update_lock);
- ret = remove(&table->root4, (const uint8_t *)ip, cidr, &table->table_update_lock);
+ ret = remove(&table->root4, (const u8 *)ip, cidr, &table->table_update_lock);
mutex_unlock(&table->table_update_lock);
return ret;
}
-int routing_table_remove_v6(struct routing_table *table, const struct in6_addr *ip, uint8_t cidr)
+int routing_table_remove_v6(struct routing_table *table, const struct in6_addr *ip, u8 cidr)
{
int ret;
mutex_lock(&table->table_update_lock);
- ret = remove(&table->root6, (const uint8_t *)ip, cidr, &table->table_update_lock);
+ ret = remove(&table->root6, (const u8 *)ip, cidr, &table->table_update_lock);
mutex_unlock(&table->table_update_lock);
return ret;
}
@@ -443,7 +443,7 @@ int routing_table_remove_by_peer(struct routing_table *table, struct wireguard_p
/* Calls func with a strong reference to each peer, before putting it when the function has completed.
* It's thus up to the caller to call peer_put on it if it's going to be used elsewhere after or stored. */
-int routing_table_walk_ips(struct routing_table *table, void *ctx, int (*func)(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, uint8_t cidr, int family))
+int routing_table_walk_ips(struct routing_table *table, void *ctx, int (*func)(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, u8 cidr, int family))
{
int ret;
rcu_read_lock();
@@ -457,7 +457,7 @@ int routing_table_walk_ips(struct routing_table *table, void *ctx, int (*func)(v
return ret;
}
-int routing_table_walk_ips_by_peer(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, uint8_t cidr, int family))
+int routing_table_walk_ips_by_peer(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, u8 cidr, int family))
{
int ret;
rcu_read_lock();
@@ -471,7 +471,7 @@ int routing_table_walk_ips_by_peer(struct routing_table *table, void *ctx, struc
return ret;
}
-int routing_table_walk_ips_by_peer_sleepable(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, uint8_t cidr, int family))
+int routing_table_walk_ips_by_peer_sleepable(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, u8 cidr, int family))
{
int ret;
mutex_lock(&table->table_update_lock);
diff --git a/src/routingtable.h b/src/routingtable.h
index 644f806..3a71dab 100644
--- a/src/routingtable.h
+++ b/src/routingtable.h
@@ -18,14 +18,14 @@ struct routing_table {
void routing_table_init(struct routing_table *table);
void routing_table_free(struct routing_table *table);
-int routing_table_insert_v4(struct routing_table *table, const struct in_addr *ip, uint8_t cidr, struct wireguard_peer *peer);
-int routing_table_insert_v6(struct routing_table *table, const struct in6_addr *ip, uint8_t cidr, struct wireguard_peer *peer);
-int routing_table_remove_v4(struct routing_table *table, const struct in_addr *ip, uint8_t cidr);
-int routing_table_remove_v6(struct routing_table *table, const struct in6_addr *ip, uint8_t cidr);
+int routing_table_insert_v4(struct routing_table *table, const struct in_addr *ip, u8 cidr, struct wireguard_peer *peer);
+int routing_table_insert_v6(struct routing_table *table, const struct in6_addr *ip, u8 cidr, struct wireguard_peer *peer);
+int routing_table_remove_v4(struct routing_table *table, const struct in_addr *ip, u8 cidr);
+int routing_table_remove_v6(struct routing_table *table, const struct in6_addr *ip, u8 cidr);
int routing_table_remove_by_peer(struct routing_table *table, struct wireguard_peer *peer);
-int routing_table_walk_ips(struct routing_table *table, void *ctx, int (*func)(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, uint8_t cidr, int family));
-int routing_table_walk_ips_by_peer(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, uint8_t cidr, int family));
-int routing_table_walk_ips_by_peer_sleepable(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, uint8_t cidr, int family));
+int routing_table_walk_ips(struct routing_table *table, void *ctx, int (*func)(void *ctx, struct wireguard_peer *peer, union nf_inet_addr ip, u8 cidr, int family));
+int routing_table_walk_ips_by_peer(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, u8 cidr, int family));
+int routing_table_walk_ips_by_peer_sleepable(struct routing_table *table, void *ctx, struct wireguard_peer *peer, int (*func)(void *ctx, union nf_inet_addr ip, u8 cidr, int family));
/* These return a strong reference to a peer: */
struct wireguard_peer *routing_table_lookup_v4(struct routing_table *table, const struct in_addr *ip);
diff --git a/src/selftest/chacha20poly1305.h b/src/selftest/chacha20poly1305.h
index 6b4893f..7f21ec6 100644
--- a/src/selftest/chacha20poly1305.h
+++ b/src/selftest/chacha20poly1305.h
@@ -1,7 +1,7 @@
#ifdef DEBUG
/* ChaCha20-Poly1305 AEAD test vectors from RFC7539 2.8.2 */
struct chacha20poly1305_testvec {
- uint8_t *key, *nonce, *assoc, *input, *result;
+ u8 *key, *nonce, *assoc, *input, *result;
size_t alen, ilen;
};
static const struct chacha20poly1305_testvec chacha20poly1305_enc_vectors[] = { {
@@ -26,7 +26,7 @@ static const struct chacha20poly1305_testvec chacha20poly1305_dec_vectors[] = {
bool chacha20poly1305_selftest(void)
{
size_t i;
- uint8_t computed_result[512];
+ u8 computed_result[512];
bool success = true;
for (i = 0; i < ARRAY_SIZE(chacha20poly1305_enc_vectors); ++i) {
diff --git a/src/selftest/curve25519.h b/src/selftest/curve25519.h
index 1ba1dde..490b1e9 100644
--- a/src/selftest/curve25519.h
+++ b/src/selftest/curve25519.h
@@ -1,8 +1,8 @@
#ifdef DEBUG
struct curve25519_test_vector {
- uint8_t private[CURVE25519_POINT_SIZE];
- uint8_t public[CURVE25519_POINT_SIZE];
- uint8_t result[CURVE25519_POINT_SIZE];
+ u8 private[CURVE25519_POINT_SIZE];
+ u8 public[CURVE25519_POINT_SIZE];
+ u8 result[CURVE25519_POINT_SIZE];
};
static const struct curve25519_test_vector curve25519_test_vectors[] = {
{
@@ -45,7 +45,7 @@ bool curve25519_selftest(void)
{
bool success = true;
size_t i = 0;
- uint8_t out[CURVE25519_POINT_SIZE];
+ u8 out[CURVE25519_POINT_SIZE];
for (i = 0; i < ARRAY_SIZE(curve25519_test_vectors); ++i) {
memset(out, 0, CURVE25519_POINT_SIZE);
diff --git a/src/selftest/routing-table.h b/src/selftest/routing-table.h
index fe7a0bc..d395a7f 100644
--- a/src/selftest/routing-table.h
+++ b/src/selftest/routing-table.h
@@ -1,15 +1,15 @@
#ifdef DEBUG
-static inline struct in_addr *ip4(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
+static inline struct in_addr *ip4(u8 a, u8 b, u8 c, u8 d)
{
static struct in_addr ip;
- uint8_t *split = (uint8_t *)&ip;
+ u8 *split = (u8 *)&ip;
split[0] = a;
split[1] = b;
split[2] = c;
split[3] = d;
return &ip;
}
-static inline struct in6_addr *ip6(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
+static inline struct in6_addr *ip6(u32 a, u32 b, u32 c, u32 d)
{
static struct in6_addr ip;
__be32 *split = (__be32 *)&ip;
@@ -108,7 +108,7 @@ bool routing_table_selftest(void)
for (i = 0; i < 128; ++i) {
part = cpu_to_be64(~(1LLU << (i % 64)));
memset(&ip, 0xff, 16);
- memcpy((uint8_t *)&ip + (i < 64) * 8, &part, 8);
+ memcpy((u8 *)&ip + (i < 64) * 8, &part, 8);
routing_table_insert_v6(&t, &ip, 128, a);
}
diff --git a/src/selftest/siphash24.h b/src/selftest/siphash24.h
index 98db647..62efe08 100644
--- a/src/selftest/siphash24.h
+++ b/src/selftest/siphash24.h
@@ -1,5 +1,5 @@
#ifdef DEBUG
-static const uint8_t test_vectors[64][8] = {
+static const u8 test_vectors[64][8] = {
{ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72 },
{ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74 },
{ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d },
@@ -68,16 +68,16 @@ static const uint8_t test_vectors[64][8] = {
bool siphash24_selftest(void)
{
- uint8_t in[64], k[16];
- uint64_t out;
+ u8 in[64], k[16];
+ u64 out;
bool success = true;
size_t i;
for (i = 0; i < 16; ++i)
- k[i] = (uint8_t)i;
+ k[i] = (u8)i;
for (i = 0; i < 64; ++i) {
- in[i] = (uint8_t)i;
+ in[i] = (u8)i;
out = siphash24(in, i, k);
if (memcmp(&out, test_vectors[i], 8)) {
pr_info("siphash24 self-test %zu: FAIL\n", i + 1);
diff --git a/src/socket.c b/src/socket.c
index 8506075..01df365 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -13,7 +13,7 @@
#include <net/udp_tunnel.h>
#include <net/ipv6.h>
-static inline int send4(struct wireguard_device *wg, struct sk_buff *skb, struct endpoint *endpoint, uint8_t ds, struct dst_cache *cache)
+static inline int send4(struct wireguard_device *wg, struct sk_buff *skb, struct endpoint *endpoint, u8 ds, struct dst_cache *cache)
{
struct flowi4 fl = {
.saddr = endpoint->src4.s_addr,
@@ -77,7 +77,7 @@ out:
return ret;
}
-static inline int send6(struct wireguard_device *wg, struct sk_buff *skb, struct endpoint *endpoint, uint8_t ds, struct dst_cache *cache)
+static inline int send6(struct wireguard_device *wg, struct sk_buff *skb, struct endpoint *endpoint, u8 ds, struct dst_cache *cache)
{
#if IS_ENABLED(CONFIG_IPV6)
struct flowi6 fl = {
@@ -145,7 +145,7 @@ out:
#endif
}
-int socket_send_skb_to_peer(struct wireguard_peer *peer, struct sk_buff *skb, uint8_t ds)
+int socket_send_skb_to_peer(struct wireguard_peer *peer, struct sk_buff *skb, u8 ds)
{
size_t skb_len = skb->len;
int ret = -EAFNOSUPPORT;
@@ -162,7 +162,7 @@ int socket_send_skb_to_peer(struct wireguard_peer *peer, struct sk_buff *skb, ui
return ret;
}
-int socket_send_buffer_to_peer(struct wireguard_peer *peer, void *buffer, size_t len, uint8_t ds)
+int socket_send_buffer_to_peer(struct wireguard_peer *peer, void *buffer, size_t len, u8 ds)
{
struct sk_buff *skb = alloc_skb(len + SKB_HEADER_LEN, GFP_ATOMIC);
if (unlikely(!skb))
@@ -289,9 +289,9 @@ err:
* blahbla --> 51820
* 50 --> 51870
*/
-static uint16_t generate_default_incoming_port(struct wireguard_device *wg)
+static u16 generate_default_incoming_port(struct wireguard_device *wg)
{
- uint16_t port = 51820;
+ u16 port = 51820;
unsigned long parsed;
char *name, *digit_begin;
size_t len;
diff --git a/src/socket.h b/src/socket.h
index f0d4277..fb4c578 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -13,8 +13,8 @@ struct endpoint;
int socket_init(struct wireguard_device *wg);
void socket_uninit(struct wireguard_device *wg);
-int socket_send_buffer_to_peer(struct wireguard_peer *peer, void *data, size_t len, uint8_t ds);
-int socket_send_skb_to_peer(struct wireguard_peer *peer, struct sk_buff *skb, uint8_t ds);
+int socket_send_buffer_to_peer(struct wireguard_peer *peer, void *data, size_t len, u8 ds);
+int socket_send_skb_to_peer(struct wireguard_peer *peer, struct sk_buff *skb, u8 ds);
int socket_send_buffer_as_reply_to_skb(struct wireguard_device *wg, struct sk_buff *in_skb, void *out_buffer, size_t len);
int socket_endpoint_from_skb(struct endpoint *endpoint, struct sk_buff *skb);