/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * CTR: Counter mode * * Copyright (c) 2007 Herbert Xu */ #ifndef _CRYPTO_CTR_H #define _CRYPTO_CTR_H #include #include #include #include #define CTR_RFC3686_NONCE_SIZE 4 #define CTR_RFC3686_IV_SIZE 8 #define CTR_RFC3686_BLOCK_SIZE 16 static inline int crypto_ctr_encrypt_walk(struct skcipher_request *req, void (*fn)(struct crypto_skcipher *, const u8 *, u8 *)) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); int blocksize = crypto_skcipher_chunksize(tfm); u8 buf[MAX_CIPHER_BLOCKSIZE]; struct skcipher_walk walk; int err; /* avoid integer division due to variable blocksize parameter */ if (WARN_ON_ONCE(!is_power_of_2(blocksize))) return -EINVAL; err = skcipher_walk_virt(&walk, req, false); while (walk.nbytes > 0) { u8 *dst = walk.dst.virt.addr; u8 *src = walk.src.virt.addr; int nbytes = walk.nbytes; int tail = 0; if (nbytes < walk.total) { tail = walk.nbytes & (blocksize - 1); nbytes -= tail; } do { int bsize = min(nbytes, blocksize); fn(tfm, walk.iv, buf); crypto_xor_cpy(dst, src, buf, bsize); crypto_inc(walk.iv, blocksize); dst += bsize; src += bsize; nbytes -= bsize; } while (nbytes > 0); err = skcipher_walk_done(&walk, tail); } return err; } #endif /* _CRYPTO_CTR_H */ rmlinux.org.uk/linux-net-next.git/log/'>logtreecommitdiff
diff options
context:
space:
mode:
authorEdward Cree <ecree@solarflare.com>2020-02-17 13:43:10 +0000
committerDavid S. Miller <davem@davemloft.net>2020-02-17 14:35:23 -0800
commitb7683155517c09c7e0f9d791eaab6dab3b4b2477 (patch)
treecea3ca29b8db6619ce2b9f90695c919f0f3d1fd1
parentbd706ff8ea2b6e2d3f21f0863b2fc42f860f8ba2 (diff)
sfc: only schedule asynchronous filter work if needed
Prevent excessive CPU time spent running a workitem with nothing to do. We avoid any races by keeping the same check in efx_filter_rfs_expire(). Suggested-by: Martin Habets <mhabets@solarflare.com> Signed-off-by: Edward Cree <ecree@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>