diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-27 11:30:05 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-08-02 02:55:42 +0200 |
commit | 2b8dd0d6ee4309d74efb7d4f28086e91381fd72a (patch) | |
tree | 88b4323468ad47112bdbea30532f7fe11f590d03 /src/crypto/curve25519.c | |
parent | timers: use more clear pow macro (diff) | |
download | wireguard-monolithic-historical-2b8dd0d6ee4309d74efb7d4f28086e91381fd72a.tar.xz wireguard-monolithic-historical-2b8dd0d6ee4309d74efb7d4f28086e91381fd72a.zip |
c: specify static array size in function params
The C standard states:
A declaration of a parameter as ``array of type'' shall be adjusted to ``qualified pointer to
type'', where the type qualifiers (if any) are those specified within the [ and ] of the
array type derivation. If the keyword static also appears within the [ and ] of the
array type derivation, then for each call to the function, the value of the corresponding
actual argument shall provide access to the first element of an array with at least as many
elements as specified by the size expression.
By changing void func(int array[4]) to void func(int array[static 4]),
we automatically get the compiler checking argument sizes for us, which
is quite nice.
Diffstat (limited to '')
-rw-r--r-- | src/crypto/curve25519.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/crypto/curve25519.c b/src/crypto/curve25519.c index 021bbd1..10d514c 100644 --- a/src/crypto/curve25519.c +++ b/src/crypto/curve25519.c @@ -10,7 +10,7 @@ #include <linux/random.h> #include <crypto/algapi.h> -static __always_inline void normalize_secret(uint8_t secret[CURVE25519_POINT_SIZE]) +static __always_inline void normalize_secret(uint8_t secret[static CURVE25519_POINT_SIZE]) { secret[0] &= 248; secret[31] &= 127; @@ -300,7 +300,7 @@ static void fmonty(limb *x2, limb *z2, /* output 2Q */ * This function performs the swap without leaking any side-channel * information. */ -static void swap_conditional(limb a[5], limb b[5], limb iswap) +static void swap_conditional(limb a[static 5], limb b[static 5], limb iswap) { unsigned i; const limb swap = -iswap; @@ -393,7 +393,7 @@ 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(uint8_t mypublic[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE], const uint8_t basepoint[static CURVE25519_POINT_SIZE]) { limb bp[5], x[5], z[5], zmone[5]; uint8_t e[32]; @@ -1071,7 +1071,7 @@ static void fmonty(limb *x2, limb *z2, /* output 2Q */ * reduced-degree form: the values in a[10..19] or b[10..19] aren't swapped, * and all all values in a[0..9],b[0..9] must have magnitude less than * INT32_MAX. */ -static void swap_conditional(limb a[19], limb b[19], limb iswap) +static void swap_conditional(limb a[static 19], limb b[static 19], limb iswap) { unsigned i; const int32_t swap = (int32_t) -iswap; @@ -1202,7 +1202,7 @@ static void crecip(limb *out, const limb *z) /* 2^255 - 21 */ fmul(out,t1,z11); } -void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE]) +void curve25519(uint8_t mypublic[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE], const uint8_t basepoint[static CURVE25519_POINT_SIZE]) { limb bp[10], x[10], z[11], zmone[10]; uint8_t e[32]; @@ -1225,13 +1225,13 @@ void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CU #endif -void curve25519_generate_secret(uint8_t secret[CURVE25519_POINT_SIZE]) +void curve25519_generate_secret(uint8_t secret[static 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(uint8_t pub[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE]) { static const uint8_t basepoint[CURVE25519_POINT_SIZE] = { 9 }; curve25519(pub, secret, basepoint); |