Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: aesni - add wrapper for generic gcm(aes)

When I added generic-gcm-aes I didn't add a wrapper like the one
provided for rfc4106(gcm(aes)). We need to add a cryptd wrapper to fall
back on in case the FPU is not available, otherwise we might corrupt the
FPU state.

Fixes: cce2ea8d90fe ("crypto: aesni - add generic gcm(aes)")
Cc: <stable@vger.kernel.org>
Reported-by: Ilya Lesokhin <ilyal@mellanox.com>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Sabrina Dubroca and committed by
Herbert Xu
fc8517bf 106840c4

+54 -12
+54 -12
arch/x86/crypto/aesni-intel_glue.c
··· 690 690 rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len); 691 691 } 692 692 693 - static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key, 694 - unsigned int key_len) 693 + static int gcmaes_wrapper_set_key(struct crypto_aead *parent, const u8 *key, 694 + unsigned int key_len) 695 695 { 696 696 struct cryptd_aead **ctx = crypto_aead_ctx(parent); 697 697 struct cryptd_aead *cryptd_tfm = *ctx; ··· 716 716 717 717 /* This is the Integrity Check Value (aka the authentication tag length and can 718 718 * be 8, 12 or 16 bytes long. */ 719 - static int rfc4106_set_authsize(struct crypto_aead *parent, 720 - unsigned int authsize) 719 + static int gcmaes_wrapper_set_authsize(struct crypto_aead *parent, 720 + unsigned int authsize) 721 721 { 722 722 struct cryptd_aead **ctx = crypto_aead_ctx(parent); 723 723 struct cryptd_aead *cryptd_tfm = *ctx; ··· 929 929 aes_ctx); 930 930 } 931 931 932 - static int rfc4106_encrypt(struct aead_request *req) 932 + static int gcmaes_wrapper_encrypt(struct aead_request *req) 933 933 { 934 934 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 935 935 struct cryptd_aead **ctx = crypto_aead_ctx(tfm); ··· 945 945 return crypto_aead_encrypt(req); 946 946 } 947 947 948 - static int rfc4106_decrypt(struct aead_request *req) 948 + static int gcmaes_wrapper_decrypt(struct aead_request *req) 949 949 { 950 950 struct crypto_aead *tfm = crypto_aead_reqtfm(req); 951 951 struct cryptd_aead **ctx = crypto_aead_ctx(tfm); ··· 1128 1128 aes_ctx); 1129 1129 } 1130 1130 1131 + static int generic_gcmaes_init(struct crypto_aead *aead) 1132 + { 1133 + struct cryptd_aead *cryptd_tfm; 1134 + struct cryptd_aead **ctx = crypto_aead_ctx(aead); 1135 + 1136 + cryptd_tfm = cryptd_alloc_aead("__driver-generic-gcm-aes-aesni", 1137 + CRYPTO_ALG_INTERNAL, 1138 + CRYPTO_ALG_INTERNAL); 1139 + if (IS_ERR(cryptd_tfm)) 1140 + return PTR_ERR(cryptd_tfm); 1141 + 1142 + *ctx = cryptd_tfm; 1143 + crypto_aead_set_reqsize(aead, crypto_aead_reqsize(&cryptd_tfm->base)); 1144 + 1145 + return 0; 1146 + } 1147 + 1148 + static void generic_gcmaes_exit(struct crypto_aead *aead) 1149 + { 1150 + struct cryptd_aead **ctx = crypto_aead_ctx(aead); 1151 + 1152 + cryptd_free_aead(*ctx); 1153 + } 1154 + 1131 1155 static struct aead_alg aesni_aead_algs[] = { { 1132 1156 .setkey = common_rfc4106_set_key, 1133 1157 .setauthsize = common_rfc4106_set_authsize, ··· 1171 1147 }, { 1172 1148 .init = rfc4106_init, 1173 1149 .exit = rfc4106_exit, 1174 - .setkey = rfc4106_set_key, 1175 - .setauthsize = rfc4106_set_authsize, 1176 - .encrypt = rfc4106_encrypt, 1177 - .decrypt = rfc4106_decrypt, 1150 + .setkey = gcmaes_wrapper_set_key, 1151 + .setauthsize = gcmaes_wrapper_set_authsize, 1152 + .encrypt = gcmaes_wrapper_encrypt, 1153 + .decrypt = gcmaes_wrapper_decrypt, 1178 1154 .ivsize = GCM_RFC4106_IV_SIZE, 1179 1155 .maxauthsize = 16, 1180 1156 .base = { ··· 1194 1170 .ivsize = GCM_AES_IV_SIZE, 1195 1171 .maxauthsize = 16, 1196 1172 .base = { 1173 + .cra_name = "__generic-gcm-aes-aesni", 1174 + .cra_driver_name = "__driver-generic-gcm-aes-aesni", 1175 + .cra_priority = 0, 1176 + .cra_flags = CRYPTO_ALG_INTERNAL, 1177 + .cra_blocksize = 1, 1178 + .cra_ctxsize = sizeof(struct generic_gcmaes_ctx), 1179 + .cra_alignmask = AESNI_ALIGN - 1, 1180 + .cra_module = THIS_MODULE, 1181 + }, 1182 + }, { 1183 + .init = generic_gcmaes_init, 1184 + .exit = generic_gcmaes_exit, 1185 + .setkey = gcmaes_wrapper_set_key, 1186 + .setauthsize = gcmaes_wrapper_set_authsize, 1187 + .encrypt = gcmaes_wrapper_encrypt, 1188 + .decrypt = gcmaes_wrapper_decrypt, 1189 + .ivsize = GCM_AES_IV_SIZE, 1190 + .maxauthsize = 16, 1191 + .base = { 1197 1192 .cra_name = "gcm(aes)", 1198 1193 .cra_driver_name = "generic-gcm-aesni", 1199 1194 .cra_priority = 400, 1200 1195 .cra_flags = CRYPTO_ALG_ASYNC, 1201 1196 .cra_blocksize = 1, 1202 - .cra_ctxsize = sizeof(struct generic_gcmaes_ctx), 1203 - .cra_alignmask = AESNI_ALIGN - 1, 1197 + .cra_ctxsize = sizeof(struct cryptd_aead *), 1204 1198 .cra_module = THIS_MODULE, 1205 1199 }, 1206 1200 } };