crypto: gcm - make GMAC work when dst and src are different
Subsystems (2)
PATCH 1/4 crypto: gcm - make GMAC work when dst and src are different
The GMAC code assumes that dst==src, which causes problems when trying to add rfc4543(gcm(aes)) test vectors.
So fix this code to work when source and destination buffer are different.
--- crypto/Kconfig | 1 + crypto/gcm.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 17 deletions(-)
crypto/Kconfig +1 -0
@@ -198,6 +198,7 @@ config CRYPTO_GCM select CRYPTO_CTR select CRYPTO_AEAD select CRYPTO_GHASH + select CRYPTO_NULL help Support for Galois/Counter Mode (GCM) and Galois Message Authentication Code (GMAC). Required for IPSec.
crypto/gcm.c +80 -17
227 lines not on this page · raw message
PATCH 2/4 crypto: gcm - fix rfc4543 to handle async crypto correctly
If the gcm cipher used by rfc4543 does not complete request immediately, the authentication tag is not copied to destination buffer. Patch adds correct async logic for this case.
--- crypto/gcm.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
crypto/gcm.c +17 -2
@@ -1099,6 +1099,21 @@ static int crypto_rfc4543_setauthsize(struct crypto_aead *parent,return crypto_aead_setauthsize (ctx->child, authsize); } +static void crypto_rfc4543_done (struct crypto_async_request *areq,int err) +{ +struct aead_request *req = areq->data; +struct crypto_aead *aead =crypto_aead_reqtfm (req); +struct crypto_rfc4543_req_ctx *rctx =crypto_rfc4543_reqctx (req); + +if (!err) { +scatterwalk_map_and_copy (rctx->auth_tag, req->dst, + req->cryptlen, +crypto_aead_authsize (aead),1 ); + } + +aead_request_complete (req, err); +} +static struct aead_request *crypto_rfc4543_crypt (struct aead_request *req,bool enc) {
@@ -1145,8 +1160,8 @@ static struct aead_request *crypto_rfc4543_crypt(struct aead_request *req,scatterwalk_crypto_chain (assoc, payload,0 ,2 );aead_request_set_tfm (subreq, ctx->child); -aead_request_set_callback (subreq, req->base.flags, req->base.complete, - req->base.data); +aead_request_set_callback (subreq, req->base.flags, crypto_rfc4543_done, + req);aead_request_set_crypt (subreq, cipher, cipher, enc ?0 : authsize, iv);aead_request_set_assoc (subreq, assoc, assoclen);
PATCH 3/4 crypto: testmgr - add AES GMAC test vectors
In reply to Jussi Kivilinna--- crypto/tcrypt.c | 4 ++ crypto/testmgr.c | 17 +++++++++- crypto/testmgr.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-)
crypto/tcrypt.c +4 -0
@@ -1225,6 +1225,10 @@ static int do_test(int m) ret +=tcrypt_test ("rfc4106(gcm(aes))" );break ; +case 152 : + ret +=tcrypt_test ("rfc4543(gcm(aes))" ); +break ; +case 200 :test_cipher_speed ("ecb(aes)" ,ENCRYPT , sec,NULL ,0 , speed_template_16_24_32);
crypto/testmgr.c +15 -2
@@ -2696,8 +2696,6 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { - - .alg = "rfc4309(ccm(aes))", .test = alg_test_aead, .fips_allowed = 1,
@@ -2714,6 +2712,21 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "rfc4543(gcm(aes))", + .test = alg_test_aead, + .suite = { + .aead = { + .enc = { + .vecs = aes_gcm_rfc4543_enc_tv_template, + .count =AES_GCM_4543_ENC_TEST_VECTORS + }, + .dec = { + .vecs = aes_gcm_rfc4543_dec_tv_template, + .count =AES_GCM_4543_DEC_TEST_VECTORS + }, + } + } + }, { .alg = "rmd128", .test = alg_test_hash, .suite = {
crypto/testmgr.h +89 -0
101 lines not on this page · raw message
PATCH 4/4 crypto: testmgr - add empty test vectors for null ciphers
In reply to Jussi KivilinnaWithout these, kernel log shows:
[ 5.984881] alg: No test for cipher_null (cipher_null-generic) [ 5.985096] alg: No test for ecb(cipher_null) (ecb-cipher_null) [ 5.985170] alg: No test for compress_null (compress_null-generic) [ 5.985297] alg: No test for digest_null (digest_null-generic)
--- crypto/testmgr.c | 9 +++++++++ 1 file changed, 9 insertions(+)
crypto/testmgr.c +9 -0
@@ -1913,6 +1913,9 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "compress_null", + .test = alg_test_null, + }, { .alg = "crc32c", .test = alg_test_crc32c, .fips_allowed = 1,
@@ -2127,6 +2130,9 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "digest_null", + .test = alg_test_null, + }, { .alg = "ecb(__aes-aesni)", .test = alg_test_null, .fips_allowed = 1,
@@ -2237,6 +2243,9 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "ecb(cipher_null)", + .test = alg_test_null, + }, { .alg = "ecb(des)", .test = alg_test_skcipher, .fips_allowed = 1,
Herbert Xu
maintainerQuoted 6 lines · Jussi Kivilinna
The GMAC code assumes that dst==src, which causes problems when trying to add rfc4543(gcm(aes)) test vectors.
So fix this code to work when source and destination buffer are different.
Signed-off-by Jussi Kivilinna <[email protected]>
All applied. Thanks Jussi!
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt