Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 560c06ae authored by Herbert Xu's avatar Herbert Xu
Browse files

[CRYPTO] api: Get rid of flags argument to setkey



Now that the tfm is passed directly to setkey instead of the ctx, we no
longer need to pass the &tfm->crt_flags pointer.

This patch also gets rid of a few unnecessary checks on the key length
for ciphers as the cipher layer guarantees that the key length is within
the bounds specified by the algorithm.

Rather than testing dia_setkey every time, this patch does it only once
during crypto_alloc_tfm.  The redundant check from crypto_digest_setkey
is also removed.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 25cdbcd9
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -379,12 +379,13 @@ static void gen_tabs(void)
}
}


static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
		       unsigned int key_len, u32 *flags)
		       unsigned int key_len)
{
{
	int i;
	int i;
	u32 ss[8];
	u32 ss[8];
	struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
	struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
	const __le32 *key = (const __le32 *)in_key;
	const __le32 *key = (const __le32 *)in_key;
	u32 *flags = &tfm->crt_flags;


	/* encryption schedule */
	/* encryption schedule */
	
	
+2 −1
Original line number Original line Diff line number Diff line
@@ -38,9 +38,10 @@ struct s390_aes_ctx {
};
};


static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
		       unsigned int key_len, u32 *flags)
		       unsigned int key_len)
{
{
	struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
	struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
	u32 *flags = &tfm->crt_flags;


	switch (key_len) {
	switch (key_len) {
	case 16:
	case 16:
+8 −5
Original line number Original line Diff line number Diff line
@@ -45,9 +45,10 @@ struct crypt_s390_des3_192_ctx {
};
};


static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
		      unsigned int keylen, u32 *flags)
		      unsigned int keylen)
{
{
	struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
	struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
	u32 *flags = &tfm->crt_flags;
	int ret;
	int ret;


	/* test if key is valid (not a weak key) */
	/* test if key is valid (not a weak key) */
@@ -167,11 +168,12 @@ static struct crypto_alg des_alg = {
 *
 *
 */
 */
static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
			   unsigned int keylen, u32 *flags)
			   unsigned int keylen)
{
{
	int i, ret;
	int i, ret;
	struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
	struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
	const u8 *temp_key = key;
	const u8 *temp_key = key;
	u32 *flags = &tfm->crt_flags;


	if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
	if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
		*flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
		*flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
@@ -303,11 +305,12 @@ static struct crypto_alg des3_128_alg = {
 *
 *
 */
 */
static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
			   unsigned int keylen, u32 *flags)
			   unsigned int keylen)
{
{
	int i, ret;
	int i, ret;
	struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
	struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
	const u8 *temp_key = key;
	const u8 *temp_key = key;
	u32 *flags = &tfm->crt_flags;


	if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
	if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
	    memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
	    memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
+3 −2
Original line number Original line Diff line number Diff line
@@ -228,13 +228,14 @@ static void __init gen_tabs(void)
}
}


static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
		       unsigned int key_len, u32 *flags)
		       unsigned int key_len)
{
{
	struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
	struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
	const __le32 *key = (const __le32 *)in_key;
	const __le32 *key = (const __le32 *)in_key;
	u32 *flags = &tfm->crt_flags;
	u32 i, j, t, u, v, w;
	u32 i, j, t, u, v, w;


	if (key_len != 16 && key_len != 24 && key_len != 32) {
	if (key_len % 8) {
		*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
		*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
		return -EINVAL;
		return -EINVAL;
	}
	}
+3 −2
Original line number Original line Diff line number Diff line
@@ -249,13 +249,14 @@ gen_tabs (void)
}
}


static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
		       unsigned int key_len, u32 *flags)
		       unsigned int key_len)
{
{
	struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
	struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
	const __le32 *key = (const __le32 *)in_key;
	const __le32 *key = (const __le32 *)in_key;
	u32 *flags = &tfm->crt_flags;
	u32 i, t, u, v, w;
	u32 i, t, u, v, w;


	if (key_len != 16 && key_len != 24 && key_len != 32) {
	if (key_len % 8) {
		*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
		*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
		return -EINVAL;
		return -EINVAL;
	}
	}
Loading