Skip to content

Commit b66c187

Browse files
Gilad Ben-Yossefherbertx
authored andcommitted
crypto: ccree - use crypto_ipsec_check_assoclen()
Use crypto_ipsec_check_assoclen() instead of home grown functions. Clean up some unneeded code as a result. Delete stale comments while we're at it. Signed-off-by: Gilad Ben-Yossef <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 69cd3e1 commit b66c187

File tree

1 file changed

+20
-53
lines changed

1 file changed

+20
-53
lines changed

drivers/crypto/ccree/cc_aead.c

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <crypto/algapi.h>
77
#include <crypto/internal/aead.h>
88
#include <crypto/authenc.h>
9+
#include <crypto/gcm.h>
10+
#include <linux/rtnetlink.h>
911
#include <crypto/internal/des.h>
1012
#include <linux/rtnetlink.h>
1113
#include "cc_driver.h"
@@ -60,11 +62,6 @@ struct cc_aead_ctx {
6062
enum drv_hash_mode auth_mode;
6163
};
6264

63-
static inline bool valid_assoclen(struct aead_request *req)
64-
{
65-
return ((req->assoclen == 16) || (req->assoclen == 20));
66-
}
67-
6865
static void cc_aead_exit(struct crypto_aead *tfm)
6966
{
7067
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
@@ -2050,15 +2047,11 @@ static int cc_rfc4309_ccm_encrypt(struct aead_request *req)
20502047
/* Very similar to cc_aead_encrypt() above. */
20512048

20522049
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2053-
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2054-
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2055-
struct device *dev = drvdata_to_dev(ctx->drvdata);
2056-
int rc = -EINVAL;
2050+
int rc;
20572051

2058-
if (!valid_assoclen(req)) {
2059-
dev_dbg(dev, "invalid Assoclen:%u\n", req->assoclen);
2052+
rc = crypto_ipsec_check_assoclen(req->assoclen);
2053+
if (rc)
20602054
goto out;
2061-
}
20622055

20632056
memset(areq_ctx, 0, sizeof(*areq_ctx));
20642057

@@ -2099,16 +2092,12 @@ static int cc_aead_decrypt(struct aead_request *req)
20992092

21002093
static int cc_rfc4309_ccm_decrypt(struct aead_request *req)
21012094
{
2102-
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2103-
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2104-
struct device *dev = drvdata_to_dev(ctx->drvdata);
21052095
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2106-
int rc = -EINVAL;
2096+
int rc;
21072097

2108-
if (!valid_assoclen(req)) {
2109-
dev_dbg(dev, "invalid Assoclen:%u\n", req->assoclen);
2098+
rc = crypto_ipsec_check_assoclen(req->assoclen);
2099+
if (rc)
21102100
goto out;
2111-
}
21122101

21132102
memset(areq_ctx, 0, sizeof(*areq_ctx));
21142103

@@ -2216,18 +2205,12 @@ static int cc_rfc4543_gcm_setauthsize(struct crypto_aead *authenc,
22162205

22172206
static int cc_rfc4106_gcm_encrypt(struct aead_request *req)
22182207
{
2219-
/* Very similar to cc_aead_encrypt() above. */
2220-
2221-
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2222-
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2223-
struct device *dev = drvdata_to_dev(ctx->drvdata);
22242208
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2225-
int rc = -EINVAL;
2209+
int rc;
22262210

2227-
if (!valid_assoclen(req)) {
2228-
dev_dbg(dev, "invalid Assoclen:%u\n", req->assoclen);
2211+
rc = crypto_ipsec_check_assoclen(req->assoclen);
2212+
if (rc)
22292213
goto out;
2230-
}
22312214

22322215
memset(areq_ctx, 0, sizeof(*areq_ctx));
22332216

@@ -2248,17 +2231,12 @@ static int cc_rfc4106_gcm_encrypt(struct aead_request *req)
22482231

22492232
static int cc_rfc4543_gcm_encrypt(struct aead_request *req)
22502233
{
2251-
/* Very similar to cc_aead_encrypt() above. */
2252-
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2253-
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2254-
struct device *dev = drvdata_to_dev(ctx->drvdata);
22552234
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2256-
int rc = -EINVAL;
2235+
int rc;
22572236

2258-
if (!valid_assoclen(req)) {
2259-
dev_dbg(dev, "invalid Assoclen:%u\n", req->assoclen);
2237+
rc = crypto_ipsec_check_assoclen(req->assoclen);
2238+
if (rc)
22602239
goto out;
2261-
}
22622240

22632241
memset(areq_ctx, 0, sizeof(*areq_ctx));
22642242

@@ -2281,18 +2259,12 @@ static int cc_rfc4543_gcm_encrypt(struct aead_request *req)
22812259

22822260
static int cc_rfc4106_gcm_decrypt(struct aead_request *req)
22832261
{
2284-
/* Very similar to cc_aead_decrypt() above. */
2285-
2286-
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2287-
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2288-
struct device *dev = drvdata_to_dev(ctx->drvdata);
22892262
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2290-
int rc = -EINVAL;
2263+
int rc;
22912264

2292-
if (!valid_assoclen(req)) {
2293-
dev_dbg(dev, "invalid Assoclen:%u\n", req->assoclen);
2265+
rc = crypto_ipsec_check_assoclen(req->assoclen);
2266+
if (rc)
22942267
goto out;
2295-
}
22962268

22972269
memset(areq_ctx, 0, sizeof(*areq_ctx));
22982270

@@ -2313,17 +2285,12 @@ static int cc_rfc4106_gcm_decrypt(struct aead_request *req)
23132285

23142286
static int cc_rfc4543_gcm_decrypt(struct aead_request *req)
23152287
{
2316-
/* Very similar to cc_aead_decrypt() above. */
2317-
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
2318-
struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm);
2319-
struct device *dev = drvdata_to_dev(ctx->drvdata);
23202288
struct aead_req_ctx *areq_ctx = aead_request_ctx(req);
2321-
int rc = -EINVAL;
2289+
int rc;
23222290

2323-
if (!valid_assoclen(req)) {
2324-
dev_dbg(dev, "invalid Assoclen:%u\n", req->assoclen);
2291+
rc = crypto_ipsec_check_assoclen(req->assoclen);
2292+
if (rc)
23252293
goto out;
2326-
}
23272294

23282295
memset(areq_ctx, 0, sizeof(*areq_ctx));
23292296

0 commit comments

Comments
 (0)