Skip to content

Commit b9eb3fc

Browse files
Eric Biggersgregkh
authored andcommitted
crypto: crypto4xx - Remove insecure and unused rng_alg
commit 7811ec9 upstream. Remove crypto4xx_rng, as it is insecure and unused: - It has only a 64-bit security strength, which is highly inadequate. This can be seen by the fact that crypto4xx_hw_init() seeds it with only 64 bits of entropy, and the fact that the original commit mentions that it implements ANSI X9.17 Annex C. Another issue was that this driver didn't implement the crypto_rng API correctly, as crypto4xx_prng_generate() didn't return 0 on success. - No user of this code is known. It's usable only theoretically via the "rng" algorithm type of AF_ALG. But userspace actually just uses the actual Linux RNG (/dev/random etc) instead. And rng_algs don't contribute entropy to the actual Linux RNG either. (This may have been confused with hwrng, which does contribute entropy.) Fixes: d072bfa ("crypto: crypto4xx - add prng crypto support") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Acked-by: Christian Lamparter <chunkeey@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent aaf6589 commit b9eb3fc

3 files changed

Lines changed: 0 additions & 102 deletions

File tree

drivers/crypto/amcc/crypto4xx_core.c

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@
3131
#include <crypto/ctr.h>
3232
#include <crypto/gcm.h>
3333
#include <crypto/sha1.h>
34-
#include <crypto/rng.h>
3534
#include <crypto/scatterwalk.h>
3635
#include <crypto/skcipher.h>
3736
#include <crypto/internal/aead.h>
38-
#include <crypto/internal/rng.h>
3937
#include <crypto/internal/skcipher.h>
4038
#include "crypto4xx_reg_def.h"
4139
#include "crypto4xx_core.h"
@@ -989,10 +987,6 @@ static int crypto4xx_register_alg(struct crypto4xx_device *sec_dev,
989987
rc = crypto_register_aead(&alg->alg.u.aead);
990988
break;
991989

992-
case CRYPTO_ALG_TYPE_RNG:
993-
rc = crypto_register_rng(&alg->alg.u.rng);
994-
break;
995-
996990
default:
997991
rc = crypto_register_skcipher(&alg->alg.u.cipher);
998992
break;
@@ -1018,10 +1012,6 @@ static void crypto4xx_unregister_alg(struct crypto4xx_device *sec_dev)
10181012
crypto_unregister_aead(&alg->alg.u.aead);
10191013
break;
10201014

1021-
case CRYPTO_ALG_TYPE_RNG:
1022-
crypto_unregister_rng(&alg->alg.u.rng);
1023-
break;
1024-
10251015
default:
10261016
crypto_unregister_skcipher(&alg->alg.u.cipher);
10271017
}
@@ -1080,69 +1070,6 @@ static irqreturn_t crypto4xx_ce_interrupt_handler_revb(int irq, void *data)
10801070
PPC4XX_TMO_ERR_INT);
10811071
}
10821072

1083-
static int ppc4xx_prng_data_read(struct crypto4xx_device *dev,
1084-
u8 *data, unsigned int max)
1085-
{
1086-
unsigned int i, curr = 0;
1087-
u32 val[2];
1088-
1089-
do {
1090-
/* trigger PRN generation */
1091-
writel(PPC4XX_PRNG_CTRL_AUTO_EN,
1092-
dev->ce_base + CRYPTO4XX_PRNG_CTRL);
1093-
1094-
for (i = 0; i < 1024; i++) {
1095-
/* usually 19 iterations are enough */
1096-
if ((readl(dev->ce_base + CRYPTO4XX_PRNG_STAT) &
1097-
CRYPTO4XX_PRNG_STAT_BUSY))
1098-
continue;
1099-
1100-
val[0] = readl_be(dev->ce_base + CRYPTO4XX_PRNG_RES_0);
1101-
val[1] = readl_be(dev->ce_base + CRYPTO4XX_PRNG_RES_1);
1102-
break;
1103-
}
1104-
if (i == 1024)
1105-
return -ETIMEDOUT;
1106-
1107-
if ((max - curr) >= 8) {
1108-
memcpy(data, &val, 8);
1109-
data += 8;
1110-
curr += 8;
1111-
} else {
1112-
/* copy only remaining bytes */
1113-
memcpy(data, &val, max - curr);
1114-
break;
1115-
}
1116-
} while (curr < max);
1117-
1118-
return curr;
1119-
}
1120-
1121-
static int crypto4xx_prng_generate(struct crypto_rng *tfm,
1122-
const u8 *src, unsigned int slen,
1123-
u8 *dstn, unsigned int dlen)
1124-
{
1125-
struct rng_alg *alg = crypto_rng_alg(tfm);
1126-
struct crypto4xx_alg *amcc_alg;
1127-
struct crypto4xx_device *dev;
1128-
int ret;
1129-
1130-
amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.rng);
1131-
dev = amcc_alg->dev;
1132-
1133-
mutex_lock(&dev->core_dev->rng_lock);
1134-
ret = ppc4xx_prng_data_read(dev, dstn, dlen);
1135-
mutex_unlock(&dev->core_dev->rng_lock);
1136-
return ret;
1137-
}
1138-
1139-
1140-
static int crypto4xx_prng_seed(struct crypto_rng *tfm, const u8 *seed,
1141-
unsigned int slen)
1142-
{
1143-
return 0;
1144-
}
1145-
11461073
/*
11471074
* Supported Crypto Algorithms
11481075
*/
@@ -1312,18 +1239,6 @@ static struct crypto4xx_alg_common crypto4xx_alg[] = {
13121239
.cra_module = THIS_MODULE,
13131240
},
13141241
} },
1315-
{ .type = CRYPTO_ALG_TYPE_RNG, .u.rng = {
1316-
.base = {
1317-
.cra_name = "stdrng",
1318-
.cra_driver_name = "crypto4xx_rng",
1319-
.cra_priority = 300,
1320-
.cra_ctxsize = 0,
1321-
.cra_module = THIS_MODULE,
1322-
},
1323-
.generate = crypto4xx_prng_generate,
1324-
.seed = crypto4xx_prng_seed,
1325-
.seedsize = 0,
1326-
} },
13271242
};
13281243

13291244
/*
@@ -1401,7 +1316,6 @@ static int crypto4xx_probe(struct platform_device *ofdev)
14011316
core_dev->dev->core_dev = core_dev;
14021317
core_dev->dev->is_revb = is_revb;
14031318
core_dev->device = dev;
1404-
mutex_init(&core_dev->rng_lock);
14051319
spin_lock_init(&core_dev->lock);
14061320
INIT_LIST_HEAD(&core_dev->dev->alg_list);
14071321
ratelimit_default_init(&core_dev->dev->aead_ratelimit);
@@ -1479,7 +1393,6 @@ static int crypto4xx_remove(struct platform_device *ofdev)
14791393
tasklet_kill(&core_dev->tasklet);
14801394
/* Un-register with Linux CryptoAPI */
14811395
crypto4xx_unregister_alg(core_dev->dev);
1482-
mutex_destroy(&core_dev->rng_lock);
14831396
/* Free all allocated memory */
14841397
crypto4xx_stop_all(core_dev);
14851398

drivers/crypto/amcc/crypto4xx_core.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
#define __CRYPTO4XX_CORE_H__
1515

1616
#include <linux/ratelimit.h>
17-
#include <linux/mutex.h>
1817
#include <linux/scatterlist.h>
1918
#include <crypto/internal/aead.h>
20-
#include <crypto/internal/rng.h>
2119
#include <crypto/internal/skcipher.h>
2220
#include "crypto4xx_reg_def.h"
2321
#include "crypto4xx_sa.h"
@@ -111,7 +109,6 @@ struct crypto4xx_core_device {
111109
u32 irq;
112110
struct tasklet_struct tasklet;
113111
spinlock_t lock;
114-
struct mutex rng_lock;
115112
};
116113

117114
struct crypto4xx_ctx {
@@ -135,7 +132,6 @@ struct crypto4xx_alg_common {
135132
union {
136133
struct skcipher_alg cipher;
137134
struct aead_alg aead;
138-
struct rng_alg rng;
139135
} u;
140136
};
141137

drivers/crypto/amcc/crypto4xx_reg_def.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,9 @@
9090
#define CRYPTO4XX_BYTE_ORDER_CFG 0x000600d8
9191
#define CRYPTO4XX_ENDIAN_CFG 0x000600d8
9292

93-
#define CRYPTO4XX_PRNG_STAT 0x00070000
94-
#define CRYPTO4XX_PRNG_STAT_BUSY 0x1
9593
#define CRYPTO4XX_PRNG_CTRL 0x00070004
9694
#define CRYPTO4XX_PRNG_SEED_L 0x00070008
9795
#define CRYPTO4XX_PRNG_SEED_H 0x0007000c
98-
99-
#define CRYPTO4XX_PRNG_RES_0 0x00070020
100-
#define CRYPTO4XX_PRNG_RES_1 0x00070024
101-
#define CRYPTO4XX_PRNG_RES_2 0x00070028
102-
#define CRYPTO4XX_PRNG_RES_3 0x0007002C
103-
104-
#define CRYPTO4XX_PRNG_LFSR_L 0x00070030
105-
#define CRYPTO4XX_PRNG_LFSR_H 0x00070034
106-
10796
/*
10897
* Initialize CRYPTO ENGINE registers, and memory bases.
10998
*/

0 commit comments

Comments
 (0)