forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: chacha - move existing library code into lib/crypto
Currently, our generic ChaCha implementation consists of a permute function in lib/chacha.c that operates on the 64-byte ChaCha state directly [and which is always included into the core kernel since it is used by the /dev/random driver], and the crypto API plumbing to expose it as a skcipher. In order to support in-kernel users that need the ChaCha streamcipher but have no need [or tolerance] for going through the abstractions of the crypto API, let's expose the streamcipher bits via a library API as well, in a way that permits the implementation to be superseded by an architecture specific one if provided. So move the streamcipher code into a separate module in lib/crypto, and expose the init() and crypt() routines to users of the library. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
- Loading branch information
1 parent
746b2e0
commit 5fb8ef2
Showing
12 changed files
with
199 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#ifndef _CRYPTO_INTERNAL_CHACHA_H | ||
#define _CRYPTO_INTERNAL_CHACHA_H | ||
|
||
#include <crypto/chacha.h> | ||
#include <crypto/internal/skcipher.h> | ||
#include <linux/crypto.h> | ||
|
||
struct chacha_ctx { | ||
u32 key[8]; | ||
int nrounds; | ||
}; | ||
|
||
void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv); | ||
|
||
static inline int chacha_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||
unsigned int keysize, int nrounds) | ||
{ | ||
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm); | ||
int i; | ||
|
||
if (keysize != CHACHA_KEY_SIZE) | ||
return -EINVAL; | ||
|
||
for (i = 0; i < ARRAY_SIZE(ctx->key); i++) | ||
ctx->key[i] = get_unaligned_le32(key + i * sizeof(u32)); | ||
|
||
ctx->nrounds = nrounds; | ||
return 0; | ||
} | ||
|
||
static inline int chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||
unsigned int keysize) | ||
{ | ||
return chacha_setkey(tfm, key, keysize, 20); | ||
} | ||
|
||
static int inline chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||
unsigned int keysize) | ||
{ | ||
return chacha_setkey(tfm, key, keysize, 12); | ||
} | ||
|
||
int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||
unsigned int keysize); | ||
int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key, | ||
unsigned int keysize); | ||
|
||
int crypto_chacha_crypt(struct skcipher_request *req); | ||
int crypto_xchacha_crypt(struct skcipher_request *req); | ||
|
||
#endif /* _CRYPTO_CHACHA_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.