Commit 906003e1 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'libcrypto-at-least-for-linus' of...

Merge tag 'libcrypto-at-least-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux

Pull 'at_least' array size update from Eric Biggers:
 "C supports lower bounds on the sizes of array parameters, using the
  static keyword as follows: 'void f(int a[static 32]);'. This allows
  the compiler to warn about a too-small array being passed.

  As discussed, this reuse of the 'static' keyword, while standard, is a
  bit obscure. Therefore, add an alias 'at_least' to compiler_types.h.

  Then, add this 'at_least' annotation to the array parameters of
  various crypto library functions"

* tag 'libcrypto-at-least-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux:
  lib/crypto: sha2: Add at_least decoration to fixed-size array params
  lib/crypto: sha1: Add at_least decoration to fixed-size array params
  lib/crypto: poly1305: Add at_least decoration to fixed-size array params
  lib/crypto: md5: Add at_least decoration to fixed-size array params
  lib/crypto: curve25519: Add at_least decoration to fixed-size array params
  lib/crypto: chacha: Add at_least decoration to fixed-size array params
  lib/crypto: chacha20poly1305: Statically check fixed array lengths
  compiler_types: introduce at_least parameter decoration pseudo keyword
  wifi: iwlwifi: trans: rename at_least variable to min_mode
parents 8f4c9978 4f0382b0
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ static enum iwl_reset_mode
iwl_trans_determine_restart_mode(struct iwl_trans *trans)
{
	struct iwl_trans_dev_restart_data *data;
	enum iwl_reset_mode at_least = 0;
	enum iwl_reset_mode min_mode = 0;
	unsigned int index;
	static const enum iwl_reset_mode escalation_list_old[] = {
		IWL_RESET_MODE_SW_RESET,
@@ -173,11 +173,11 @@ iwl_trans_determine_restart_mode(struct iwl_trans *trans)
	}

	if (trans->restart.during_reset)
		at_least = IWL_RESET_MODE_REPROBE;
		min_mode = IWL_RESET_MODE_REPROBE;

	data = iwl_trans_get_restart_data(trans->dev);
	if (!data)
		return at_least;
		return min_mode;

	if (!data->backoff &&
	    ktime_get_boottime_seconds() - data->last_error >=
@@ -194,7 +194,7 @@ iwl_trans_determine_restart_mode(struct iwl_trans *trans)
		data->backoff = false;
	}

	return max(at_least, escalation_list[index]);
	return max(min_mode, escalation_list[index]);
}

#define IWL_TRANS_TOP_FOLLOWER_WAIT	180 /* ms */
+6 −6
Original line number Diff line number Diff line
@@ -38,18 +38,18 @@ struct chacha_state {
};

void chacha_block_generic(struct chacha_state *state,
			  u8 out[CHACHA_BLOCK_SIZE], int nrounds);
			  u8 out[at_least CHACHA_BLOCK_SIZE], int nrounds);
static inline void chacha20_block(struct chacha_state *state,
				  u8 out[CHACHA_BLOCK_SIZE])
				  u8 out[at_least CHACHA_BLOCK_SIZE])
{
	chacha_block_generic(state, out, 20);
}

void hchacha_block_generic(const struct chacha_state *state,
			   u32 out[HCHACHA_OUT_WORDS], int nrounds);
			   u32 out[at_least HCHACHA_OUT_WORDS], int nrounds);

void hchacha_block(const struct chacha_state *state,
		   u32 out[HCHACHA_OUT_WORDS], int nrounds);
		   u32 out[at_least HCHACHA_OUT_WORDS], int nrounds);

enum chacha_constants { /* expand 32-byte k */
	CHACHA_CONSTANT_EXPA = 0x61707865U,
@@ -67,8 +67,8 @@ static inline void chacha_init_consts(struct chacha_state *state)
}

static inline void chacha_init(struct chacha_state *state,
			       const u32 key[CHACHA_KEY_WORDS],
			       const u8 iv[CHACHA_IV_SIZE])
			       const u32 key[at_least CHACHA_KEY_WORDS],
			       const u8 iv[at_least CHACHA_IV_SIZE])
{
	chacha_init_consts(state);
	state->x[4]  = key[0];
+10 −9
Original line number Diff line number Diff line
@@ -18,32 +18,33 @@ enum chacha20poly1305_lengths {
void 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_KEY_SIZE]);
			      const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);

bool __must_check
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_KEY_SIZE]);
			 const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);

void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
			       const u8 *ad, const size_t ad_len,
			       const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE],
			       const u8 key[CHACHA20POLY1305_KEY_SIZE]);
			       const u8 nonce[at_least XCHACHA20POLY1305_NONCE_SIZE],
			       const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);

bool __must_check xchacha20poly1305_decrypt(
	u8 *dst, const u8 *src, const size_t src_len, const u8 *ad,
	const size_t ad_len, const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE],
	const u8 key[CHACHA20POLY1305_KEY_SIZE]);
	u8 *dst, const u8 *src, const size_t src_len,
	const u8 *ad, const size_t ad_len,
	const u8 nonce[at_least XCHACHA20POLY1305_NONCE_SIZE],
	const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);

bool chacha20poly1305_encrypt_sg_inplace(struct scatterlist *src, size_t src_len,
					 const u8 *ad, const size_t ad_len,
					 const u64 nonce,
					 const u8 key[CHACHA20POLY1305_KEY_SIZE]);
					 const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);

bool chacha20poly1305_decrypt_sg_inplace(struct scatterlist *src, size_t src_len,
					 const u8 *ad, const size_t ad_len,
					 const u64 nonce,
					 const u8 key[CHACHA20POLY1305_KEY_SIZE]);
					 const u8 key[at_least CHACHA20POLY1305_KEY_SIZE]);

bool chacha20poly1305_selftest(void);

+14 −10
Original line number Diff line number Diff line
@@ -13,24 +13,28 @@ enum curve25519_lengths {
	CURVE25519_KEY_SIZE = 32
};

void curve25519_generic(u8 out[CURVE25519_KEY_SIZE],
			const u8 scalar[CURVE25519_KEY_SIZE],
			const u8 point[CURVE25519_KEY_SIZE]);
void curve25519_generic(u8 out[at_least CURVE25519_KEY_SIZE],
			const u8 scalar[at_least CURVE25519_KEY_SIZE],
			const u8 point[at_least CURVE25519_KEY_SIZE]);

bool __must_check curve25519(u8 mypublic[CURVE25519_KEY_SIZE],
			     const u8 secret[CURVE25519_KEY_SIZE],
			     const u8 basepoint[CURVE25519_KEY_SIZE]);
bool __must_check
curve25519(u8 mypublic[at_least CURVE25519_KEY_SIZE],
	   const u8 secret[at_least CURVE25519_KEY_SIZE],
	   const u8 basepoint[at_least CURVE25519_KEY_SIZE]);

bool __must_check curve25519_generate_public(u8 pub[CURVE25519_KEY_SIZE],
					     const u8 secret[CURVE25519_KEY_SIZE]);
bool __must_check
curve25519_generate_public(u8 pub[at_least CURVE25519_KEY_SIZE],
			   const u8 secret[at_least CURVE25519_KEY_SIZE]);

static inline void curve25519_clamp_secret(u8 secret[CURVE25519_KEY_SIZE])
static inline void
curve25519_clamp_secret(u8 secret[at_least CURVE25519_KEY_SIZE])
{
	secret[0] &= 248;
	secret[31] = (secret[31] & 127) | 64;
}

static inline void curve25519_generate_secret(u8 secret[CURVE25519_KEY_SIZE])
static inline void
curve25519_generate_secret(u8 secret[at_least CURVE25519_KEY_SIZE])
{
	get_random_bytes_wait(secret, CURVE25519_KEY_SIZE);
	curve25519_clamp_secret(secret);
+6 −5
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ void md5_update(struct md5_ctx *ctx, const u8 *data, size_t len);
 *
 * Context: Any context.
 */
void md5_final(struct md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE]);
void md5_final(struct md5_ctx *ctx, u8 out[at_least MD5_DIGEST_SIZE]);

/**
 * md5() - Compute MD5 message digest in one shot
@@ -86,7 +86,7 @@ void md5_final(struct md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE]);
 *
 * Context: Any context.
 */
void md5(const u8 *data, size_t len, u8 out[MD5_DIGEST_SIZE]);
void md5(const u8 *data, size_t len, u8 out[at_least MD5_DIGEST_SIZE]);

/**
 * struct hmac_md5_key - Prepared key for HMAC-MD5
@@ -173,7 +173,7 @@ static inline void hmac_md5_update(struct hmac_md5_ctx *ctx,
 *
 * Context: Any context.
 */
void hmac_md5_final(struct hmac_md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE]);
void hmac_md5_final(struct hmac_md5_ctx *ctx, u8 out[at_least MD5_DIGEST_SIZE]);

/**
 * hmac_md5() - Compute HMAC-MD5 in one shot, using a prepared key
@@ -187,7 +187,8 @@ void hmac_md5_final(struct hmac_md5_ctx *ctx, u8 out[MD5_DIGEST_SIZE]);
 * Context: Any context.
 */
void hmac_md5(const struct hmac_md5_key *key,
	      const u8 *data, size_t data_len, u8 out[MD5_DIGEST_SIZE]);
	      const u8 *data, size_t data_len,
	      u8 out[at_least MD5_DIGEST_SIZE]);

/**
 * hmac_md5_usingrawkey() - Compute HMAC-MD5 in one shot, using a raw key
@@ -204,6 +205,6 @@ void hmac_md5(const struct hmac_md5_key *key,
 */
void hmac_md5_usingrawkey(const u8 *raw_key, size_t raw_key_len,
			  const u8 *data, size_t data_len,
			  u8 out[MD5_DIGEST_SIZE]);
			  u8 out[at_least MD5_DIGEST_SIZE]);

#endif /* _CRYPTO_MD5_H */
Loading