Merge "crypto: msm: multiple device support for FIPS"

This commit is contained in:
Linux Build Service Account 2014-07-14 18:10:27 -07:00 committed by Gerrit - the friendly Code Review server
commit 110f3df623

View file

@ -70,37 +70,34 @@ int _fips_qcrypto_sha_selftest(struct fips_selftest_data *selftest_d)
struct crypto_ahash *tfm;
struct ahash_request *ahash_req;
struct _fips_completion fips_completion;
struct _fips_test_vector_sha_hmac tv_sha_hmac;
num_tv = (sizeof(fips_test_vector_sha_hmac)) /
(sizeof(struct _fips_test_vector_sha_hmac));
/* One-by-one testing */
for (tv_index = 0; tv_index < num_tv; tv_index++) {
k_out_buf = kzalloc(fips_test_vector_sha_hmac[tv_index].diglen,
GFP_KERNEL);
memcpy(&tv_sha_hmac, &fips_test_vector_sha_hmac[tv_index],
(sizeof(struct _fips_test_vector_sha_hmac)));
k_out_buf = kzalloc(tv_sha_hmac.diglen, GFP_KERNEL);
if (k_out_buf == NULL) {
pr_err("qcrypto: Failed to allocate memory for k_out_buf %ld\n",
PTR_ERR(k_out_buf));
return -ENOMEM;
}
memset(k_out_buf, 0,
fips_test_vector_sha_hmac[tv_index].diglen);
memset(k_out_buf, 0, tv_sha_hmac.diglen);
init_completion(&fips_completion.completion);
/* use_sw flags are set in dtsi file which makes
default Linux API calls to go to s/w crypto instead
of h/w crypto. This code makes sure that all selftests
calls always go to h/w, independent of DTSI flags. */
if (fips_test_vector_sha_hmac[tv_index].klen == 0) {
if (tv_sha_hmac.klen == 0) {
if (selftest_d->prefix_ahash_algo)
if (_fips_get_alg_cra_name(
fips_test_vector_sha_hmac[tv_index]
if (_fips_get_alg_cra_name(tv_sha_hmac
.hash_alg, selftest_d->algo_prefix,
strlen(
fips_test_vector_sha_hmac[tv_index]
.hash_alg)
)) {
strlen(tv_sha_hmac.hash_alg))) {
rc = -1;
pr_err("Algo Name is too long for tv %d\n",
tv_index);
@ -108,13 +105,9 @@ int _fips_qcrypto_sha_selftest(struct fips_selftest_data *selftest_d)
}
} else {
if (selftest_d->prefix_hmac_algo)
if (_fips_get_alg_cra_name(
fips_test_vector_sha_hmac[tv_index]
if (_fips_get_alg_cra_name(tv_sha_hmac
.hash_alg, selftest_d->algo_prefix,
strlen(
fips_test_vector_sha_hmac[tv_index]
.hash_alg)
)) {
strlen(tv_sha_hmac.hash_alg))) {
rc = -1;
pr_err("Algo Name is too long for tv %d\n",
tv_index);
@ -122,11 +115,10 @@ int _fips_qcrypto_sha_selftest(struct fips_selftest_data *selftest_d)
}
}
tfm = crypto_alloc_ahash(
fips_test_vector_sha_hmac[tv_index].hash_alg, 0, 0);
tfm = crypto_alloc_ahash(tv_sha_hmac.hash_alg, 0, 0);
if (IS_ERR(tfm)) {
pr_err("qcrypto: %s algorithm not found\n",
fips_test_vector_sha_hmac[tv_index].hash_alg);
tv_sha_hmac.hash_alg);
rc = PTR_ERR(tfm);
goto clr_buf;
}
@ -147,15 +139,12 @@ int _fips_qcrypto_sha_selftest(struct fips_selftest_data *selftest_d)
CRYPTO_TFM_REQ_MAY_BACKLOG,
_fips_cb, &fips_completion);
sg_init_one(&fips_sg,
&fips_test_vector_sha_hmac[tv_index].input[0],
fips_test_vector_sha_hmac[tv_index].ilen);
sg_init_one(&fips_sg, &tv_sha_hmac.input[0], tv_sha_hmac.ilen);
crypto_ahash_clear_flags(tfm, ~0);
if (fips_test_vector_sha_hmac[tv_index].klen != 0) {
rc = crypto_ahash_setkey(tfm,
fips_test_vector_sha_hmac[tv_index].key,
fips_test_vector_sha_hmac[tv_index].klen);
if (tv_sha_hmac.klen != 0) {
rc = crypto_ahash_setkey(tfm, tv_sha_hmac.key,
tv_sha_hmac.klen);
if (rc) {
pr_err("qcrypto: crypto_ahash_setkey failed\n");
goto clr_ahash_req;
@ -163,7 +152,7 @@ int _fips_qcrypto_sha_selftest(struct fips_selftest_data *selftest_d)
}
ahash_request_set_crypt(ahash_req, &fips_sg, k_out_buf,
fips_test_vector_sha_hmac[tv_index].ilen);
tv_sha_hmac.ilen);
rc = crypto_ahash_digest(ahash_req);
if (rc == -EINPROGRESS || rc == -EBUSY) {
rc = wait_for_completion_interruptible(
@ -178,9 +167,8 @@ int _fips_qcrypto_sha_selftest(struct fips_selftest_data *selftest_d)
}
if (memcmp(k_out_buf,
fips_test_vector_sha_hmac[tv_index].digest,
fips_test_vector_sha_hmac[tv_index].diglen))
if (memcmp(k_out_buf, tv_sha_hmac.digest,
tv_sha_hmac.diglen))
rc = -1;
clr_ahash_req:
@ -209,6 +197,7 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
struct _fips_completion fips_completion;
char *k_align_src = NULL;
struct scatterlist fips_sg;
struct _fips_test_vector_cipher tv_cipher;
num_tv = (sizeof(fips_test_vector_cipher)) /
(sizeof(struct _fips_test_vector_cipher));
@ -216,32 +205,30 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
/* One-by-one testing */
for (tv_index = 0; tv_index < num_tv; tv_index++) {
memcpy(&tv_cipher, &fips_test_vector_cipher[tv_index],
(sizeof(struct _fips_test_vector_cipher)));
/* Single buffer allocation for in place operation */
k_align_src = kzalloc(
fips_test_vector_cipher[tv_index].pln_txt_len,
GFP_KERNEL);
k_align_src = kzalloc(tv_cipher.pln_txt_len, GFP_KERNEL);
if (k_align_src == NULL) {
pr_err("qcrypto:, Failed to allocate memory for k_align_src %ld\n",
PTR_ERR(k_align_src));
return -ENOMEM;
}
memcpy(&k_align_src[0],
fips_test_vector_cipher[tv_index].pln_txt,
fips_test_vector_cipher[tv_index].pln_txt_len);
memcpy(&k_align_src[0], tv_cipher.pln_txt,
tv_cipher.pln_txt_len);
/* use_sw flags are set in dtsi file which makes
default Linux API calls to go to s/w crypto instead
of h/w crypto. This code makes sure that all selftests
calls always go to h/w, independent of DTSI flags. */
if (!strcmp(fips_test_vector_cipher[tv_index].mod_alg,
"xts(aes)")) {
if (!strcmp(tv_cipher.mod_alg, "xts(aes)")) {
if (selftest_d->prefix_aes_xts_algo)
if (_fips_get_alg_cra_name(
fips_test_vector_cipher[tv_index]
.mod_alg, selftest_d->algo_prefix,
strlen(fips_test_vector_cipher[tv_index]
.mod_alg))) {
tv_cipher.mod_alg,
selftest_d->algo_prefix,
strlen(tv_cipher.mod_alg))) {
rc = -1;
pr_err("Algo Name is too long for tv %d\n",
tv_index);
@ -250,10 +237,9 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
} else {
if (selftest_d->prefix_aes_cbc_ecb_ctr_algo)
if (_fips_get_alg_cra_name(
fips_test_vector_cipher[tv_index]
.mod_alg, selftest_d->algo_prefix,
strlen(fips_test_vector_cipher[tv_index]
.mod_alg))) {
tv_cipher.mod_alg,
selftest_d->algo_prefix,
strlen(tv_cipher.mod_alg))) {
rc = -1;
pr_err("Algo Name is too long for tv %d\n",
tv_index);
@ -261,11 +247,10 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
}
}
tfm = crypto_alloc_ablkcipher(
fips_test_vector_cipher[tv_index].mod_alg, 0, 0);
tfm = crypto_alloc_ablkcipher(tv_cipher.mod_alg, 0, 0);
if (IS_ERR(tfm)) {
pr_err("qcrypto: %s algorithm not found\n",
fips_test_vector_cipher[tv_index].mod_alg);
tv_cipher.mod_alg);
rc = -ENOMEM;
goto clr_buf;
}
@ -288,20 +273,17 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
_fips_cb, &fips_completion);
crypto_ablkcipher_clear_flags(tfm, ~0);
rc = crypto_ablkcipher_setkey(tfm,
fips_test_vector_cipher[tv_index].key,
fips_test_vector_cipher[tv_index].klen);
rc = crypto_ablkcipher_setkey(tfm, tv_cipher.key,
tv_cipher.klen);
if (rc) {
pr_err("qcrypto: crypto_ablkcipher_setkey failed\n");
goto clr_ablkcipher_req;
}
sg_set_buf(&fips_sg, k_align_src,
fips_test_vector_cipher[tv_index].enc_txt_len);
sg_set_buf(&fips_sg, k_align_src, tv_cipher.enc_txt_len);
sg_mark_end(&fips_sg);
ablkcipher_request_set_crypt(ablkcipher_req,
&fips_sg, &fips_sg,
fips_test_vector_cipher[tv_index].pln_txt_len,
fips_test_vector_cipher[tv_index].iv);
&fips_sg, &fips_sg, tv_cipher.pln_txt_len,
tv_cipher.iv);
/**** Encryption Test ****/
init_completion(&fips_completion.completion);
@ -319,9 +301,8 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
}
if (memcmp(k_align_src,
fips_test_vector_cipher[tv_index].enc_txt,
fips_test_vector_cipher[tv_index].enc_txt_len)) {
if (memcmp(k_align_src, tv_cipher.enc_txt,
tv_cipher.enc_txt_len)) {
rc = -1;
goto clr_ablkcipher_req;
}
@ -342,9 +323,8 @@ int _fips_qcrypto_cipher_selftest(struct fips_selftest_data *selftest_d)
}
if (memcmp(k_align_src,
fips_test_vector_cipher[tv_index].pln_txt,
fips_test_vector_cipher[tv_index].pln_txt_len))
if (memcmp(k_align_src, tv_cipher.pln_txt,
tv_cipher.pln_txt_len))
rc = -1;
clr_ablkcipher_req:
@ -372,6 +352,7 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
struct _fips_completion fips_completion;
struct scatterlist fips_sg, fips_assoc_sg;
char *k_align_src = NULL;
struct _fips_test_vector_aead tv_aead;
num_tv = (sizeof(fips_test_vector_aead)) /
(sizeof(struct _fips_test_vector_aead));
@ -379,13 +360,13 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
/* One-by-one testing */
for (tv_index = 0; tv_index < num_tv; tv_index++) {
if (fips_test_vector_aead[tv_index].pln_txt_len >
fips_test_vector_aead[tv_index].enc_txt_len)
buf_length =
fips_test_vector_aead[tv_index].pln_txt_len;
memcpy(&tv_aead, &fips_test_vector_aead[tv_index],
(sizeof(struct _fips_test_vector_aead)));
if (tv_aead.pln_txt_len > tv_aead.enc_txt_len)
buf_length = tv_aead.pln_txt_len;
else
buf_length =
fips_test_vector_aead[tv_index].enc_txt_len;
buf_length = tv_aead.enc_txt_len;
/* Single buffer allocation for in place operation */
k_align_src = kzalloc(buf_length, GFP_KERNEL);
@ -394,31 +375,27 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
PTR_ERR(k_align_src));
return -ENOMEM;
}
memcpy(&k_align_src[0],
fips_test_vector_aead[tv_index].pln_txt,
fips_test_vector_aead[tv_index].pln_txt_len);
memcpy(&k_align_src[0], tv_aead.pln_txt,
tv_aead.pln_txt_len);
/* use_sw flags are set in dtsi file which makes
default Linux API calls to go to s/w crypto instead
of h/w crypto. This code makes sure that all selftests
calls always go to h/w, independent of DTSI flags. */
if (selftest_d->prefix_aead_algo) {
if (_fips_get_alg_cra_name(
fips_test_vector_aead[tv_index].mod_alg,
if (_fips_get_alg_cra_name(tv_aead.mod_alg,
selftest_d->algo_prefix,
strlen(fips_test_vector_aead[tv_index].mod_alg
))) {
strlen(tv_aead.mod_alg))) {
rc = -1;
pr_err("Algo Name is too long for tv %d\n",
tv_index);
goto clr_buf;
}
}
tfm = crypto_alloc_aead(
fips_test_vector_aead[tv_index].mod_alg, 0, 0);
tfm = crypto_alloc_aead(tv_aead.mod_alg, 0, 0);
if (IS_ERR(tfm)) {
pr_err("qcrypto: %s algorithm not found\n",
fips_test_vector_aead[tv_index].mod_alg);
tv_aead.mod_alg);
rc = -ENOMEM;
goto clr_buf;
}
@ -439,32 +416,23 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
CRYPTO_TFM_REQ_MAY_BACKLOG,
_fips_cb, &fips_completion);
crypto_aead_clear_flags(tfm, ~0);
rc = crypto_aead_setkey(tfm,
fips_test_vector_aead[tv_index].key,
fips_test_vector_aead[tv_index].klen);
rc = crypto_aead_setkey(tfm, tv_aead.key, tv_aead.klen);
if (rc) {
pr_err("qcrypto:crypto_aead_setkey failed\n");
goto clr_aead_req;
}
authsize = abs(fips_test_vector_aead[tv_index].enc_txt_len -
fips_test_vector_aead[tv_index].pln_txt_len);
authsize = abs(tv_aead.enc_txt_len - tv_aead.pln_txt_len);
rc = crypto_aead_setauthsize(tfm, authsize);
if (rc) {
pr_err("qcrypto:crypto_aead_setauthsize failed\n");
goto clr_aead_req;
}
sg_init_one(&fips_sg, k_align_src,
fips_test_vector_aead[tv_index].pln_txt_len + authsize);
aead_request_set_crypt(aead_req,
&fips_sg, &fips_sg,
fips_test_vector_aead[tv_index].pln_txt_len ,
fips_test_vector_aead[tv_index].iv);
sg_init_one(&fips_assoc_sg,
fips_test_vector_aead[tv_index].assoc,
fips_test_vector_aead[tv_index].alen);
aead_request_set_assoc(aead_req,
&fips_assoc_sg,
fips_test_vector_aead[tv_index].alen);
tv_aead.pln_txt_len + authsize);
aead_request_set_crypt(aead_req, &fips_sg, &fips_sg,
tv_aead.pln_txt_len , tv_aead.iv);
sg_init_one(&fips_assoc_sg, tv_aead.assoc, tv_aead.alen);
aead_request_set_assoc(aead_req, &fips_assoc_sg, tv_aead.alen);
/**** Encryption test ****/
rc = crypto_aead_encrypt(aead_req);
if (rc == -EINPROGRESS || rc == -EBUSY) {
@ -479,9 +447,7 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
}
}
if (memcmp(k_align_src,
fips_test_vector_aead[tv_index].enc_txt,
fips_test_vector_aead[tv_index].enc_txt_len)) {
if (memcmp(k_align_src, tv_aead.enc_txt, tv_aead.enc_txt_len)) {
rc = -1;
goto clr_aead_req;
}
@ -492,16 +458,13 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
CRYPTO_TFM_REQ_MAY_BACKLOG,
_fips_cb, &fips_completion);
crypto_aead_clear_flags(tfm, ~0);
rc = crypto_aead_setkey(tfm,
fips_test_vector_aead[tv_index].key,
fips_test_vector_aead[tv_index].klen);
rc = crypto_aead_setkey(tfm, tv_aead.key, tv_aead.klen);
if (rc) {
pr_err("qcrypto:aead:DEC, crypto_aead_setkey failed\n");
goto clr_aead_req;
}
authsize = abs(fips_test_vector_aead[tv_index].enc_txt_len -
fips_test_vector_aead[tv_index].pln_txt_len);
authsize = abs(tv_aead.enc_txt_len - tv_aead.pln_txt_len);
rc = crypto_aead_setauthsize(tfm, authsize);
if (rc) {
pr_err("qcrypto:aead:DEC, crypto_aead_setauthsize failed\n");
@ -509,17 +472,12 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
}
sg_init_one(&fips_sg, k_align_src,
fips_test_vector_aead[tv_index].enc_txt_len + authsize);
aead_request_set_crypt(aead_req,
&fips_sg, &fips_sg,
fips_test_vector_aead[tv_index].enc_txt_len,
fips_test_vector_aead[tv_index].iv);
sg_init_one(&fips_assoc_sg,
fips_test_vector_aead[tv_index].assoc,
fips_test_vector_aead[tv_index].alen);
aead_request_set_assoc(aead_req,
&fips_assoc_sg,
fips_test_vector_aead[tv_index].alen);
tv_aead.enc_txt_len + authsize);
aead_request_set_crypt(aead_req, &fips_sg, &fips_sg,
tv_aead.enc_txt_len, tv_aead.iv);
sg_init_one(&fips_assoc_sg, tv_aead.assoc, tv_aead.alen);
aead_request_set_assoc(aead_req, &fips_assoc_sg,
tv_aead.alen);
rc = crypto_aead_decrypt(aead_req);
if (rc == -EINPROGRESS || rc == -EBUSY) {
rc = wait_for_completion_interruptible(
@ -534,9 +492,7 @@ int _fips_qcrypto_aead_selftest(struct fips_selftest_data *selftest_d)
}
if (memcmp(k_align_src,
fips_test_vector_aead[tv_index].pln_txt,
fips_test_vector_aead[tv_index].pln_txt_len)) {
if (memcmp(k_align_src, tv_aead.pln_txt, tv_aead.pln_txt_len)) {
rc = -1;
goto clr_aead_req;
}