summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-08-20 03:21:46 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-08-21 10:21:20 -0400
commit12773d932fc22c60e0d5a20660d564542fab811b (patch)
treedc29cc9b2cd188083885bb3fb3b60187918b90ad /crypto
parent7a7ffe65c8c5fbf272b132d8980b2511d5e5fc98 (diff)
crypto: testmgr - Use new skcipher interface
This patch replaces uses of blkcipher and ablkcipher with the new skcipher interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/testmgr.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index a865ea99a057..35c2de136971 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -22,6 +22,7 @@
22 22
23#include <crypto/aead.h> 23#include <crypto/aead.h>
24#include <crypto/hash.h> 24#include <crypto/hash.h>
25#include <crypto/skcipher.h>
25#include <linux/err.h> 26#include <linux/err.h>
26#include <linux/fips.h> 27#include <linux/fips.h>
27#include <linux/module.h> 28#include <linux/module.h>
@@ -921,15 +922,15 @@ out_nobuf:
921 return ret; 922 return ret;
922} 923}
923 924
924static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc, 925static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
925 struct cipher_testvec *template, unsigned int tcount, 926 struct cipher_testvec *template, unsigned int tcount,
926 const bool diff_dst, const int align_offset) 927 const bool diff_dst, const int align_offset)
927{ 928{
928 const char *algo = 929 const char *algo =
929 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); 930 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
930 unsigned int i, j, k, n, temp; 931 unsigned int i, j, k, n, temp;
931 char *q; 932 char *q;
932 struct ablkcipher_request *req; 933 struct skcipher_request *req;
933 struct scatterlist sg[8]; 934 struct scatterlist sg[8];
934 struct scatterlist sgout[8]; 935 struct scatterlist sgout[8];
935 const char *e, *d; 936 const char *e, *d;
@@ -958,15 +959,15 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
958 959
959 init_completion(&result.completion); 960 init_completion(&result.completion);
960 961
961 req = ablkcipher_request_alloc(tfm, GFP_KERNEL); 962 req = skcipher_request_alloc(tfm, GFP_KERNEL);
962 if (!req) { 963 if (!req) {
963 pr_err("alg: skcipher%s: Failed to allocate request for %s\n", 964 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
964 d, algo); 965 d, algo);
965 goto out; 966 goto out;
966 } 967 }
967 968
968 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 969 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
969 tcrypt_complete, &result); 970 tcrypt_complete, &result);
970 971
971 j = 0; 972 j = 0;
972 for (i = 0; i < tcount; i++) { 973 for (i = 0; i < tcount; i++) {
@@ -987,15 +988,16 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
987 data += align_offset; 988 data += align_offset;
988 memcpy(data, template[i].input, template[i].ilen); 989 memcpy(data, template[i].input, template[i].ilen);
989 990
990 crypto_ablkcipher_clear_flags(tfm, ~0); 991 crypto_skcipher_clear_flags(tfm, ~0);
991 if (template[i].wk) 992 if (template[i].wk)
992 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 993 crypto_skcipher_set_flags(tfm,
994 CRYPTO_TFM_REQ_WEAK_KEY);
993 995
994 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 996 ret = crypto_skcipher_setkey(tfm, template[i].key,
995 template[i].klen); 997 template[i].klen);
996 if (!ret == template[i].fail) { 998 if (!ret == template[i].fail) {
997 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n", 999 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
998 d, j, algo, crypto_ablkcipher_get_flags(tfm)); 1000 d, j, algo, crypto_skcipher_get_flags(tfm));
999 goto out; 1001 goto out;
1000 } else if (ret) 1002 } else if (ret)
1001 continue; 1003 continue;
@@ -1007,10 +1009,10 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1007 sg_init_one(&sgout[0], data, template[i].ilen); 1009 sg_init_one(&sgout[0], data, template[i].ilen);
1008 } 1010 }
1009 1011
1010 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 1012 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1011 template[i].ilen, iv); 1013 template[i].ilen, iv);
1012 ret = enc ? crypto_ablkcipher_encrypt(req) : 1014 ret = enc ? crypto_skcipher_encrypt(req) :
1013 crypto_ablkcipher_decrypt(req); 1015 crypto_skcipher_decrypt(req);
1014 1016
1015 switch (ret) { 1017 switch (ret) {
1016 case 0: 1018 case 0:
@@ -1054,15 +1056,16 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1054 memset(iv, 0, MAX_IVLEN); 1056 memset(iv, 0, MAX_IVLEN);
1055 1057
1056 j++; 1058 j++;
1057 crypto_ablkcipher_clear_flags(tfm, ~0); 1059 crypto_skcipher_clear_flags(tfm, ~0);
1058 if (template[i].wk) 1060 if (template[i].wk)
1059 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY); 1061 crypto_skcipher_set_flags(tfm,
1062 CRYPTO_TFM_REQ_WEAK_KEY);
1060 1063
1061 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 1064 ret = crypto_skcipher_setkey(tfm, template[i].key,
1062 template[i].klen); 1065 template[i].klen);
1063 if (!ret == template[i].fail) { 1066 if (!ret == template[i].fail) {
1064 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n", 1067 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1065 d, j, algo, crypto_ablkcipher_get_flags(tfm)); 1068 d, j, algo, crypto_skcipher_get_flags(tfm));
1066 goto out; 1069 goto out;
1067 } else if (ret) 1070 } else if (ret)
1068 continue; 1071 continue;
@@ -1100,11 +1103,11 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1100 temp += template[i].tap[k]; 1103 temp += template[i].tap[k];
1101 } 1104 }
1102 1105
1103 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg, 1106 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1104 template[i].ilen, iv); 1107 template[i].ilen, iv);
1105 1108
1106 ret = enc ? crypto_ablkcipher_encrypt(req) : 1109 ret = enc ? crypto_skcipher_encrypt(req) :
1107 crypto_ablkcipher_decrypt(req); 1110 crypto_skcipher_decrypt(req);
1108 1111
1109 switch (ret) { 1112 switch (ret) {
1110 case 0: 1113 case 0:
@@ -1157,7 +1160,7 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1157 ret = 0; 1160 ret = 0;
1158 1161
1159out: 1162out:
1160 ablkcipher_request_free(req); 1163 skcipher_request_free(req);
1161 if (diff_dst) 1164 if (diff_dst)
1162 testmgr_free_buf(xoutbuf); 1165 testmgr_free_buf(xoutbuf);
1163out_nooutbuf: 1166out_nooutbuf:
@@ -1166,7 +1169,7 @@ out_nobuf:
1166 return ret; 1169 return ret;
1167} 1170}
1168 1171
1169static int test_skcipher(struct crypto_ablkcipher *tfm, int enc, 1172static int test_skcipher(struct crypto_skcipher *tfm, int enc,
1170 struct cipher_testvec *template, unsigned int tcount) 1173 struct cipher_testvec *template, unsigned int tcount)
1171{ 1174{
1172 unsigned int alignmask; 1175 unsigned int alignmask;
@@ -1578,10 +1581,10 @@ out:
1578static int alg_test_skcipher(const struct alg_test_desc *desc, 1581static int alg_test_skcipher(const struct alg_test_desc *desc,
1579 const char *driver, u32 type, u32 mask) 1582 const char *driver, u32 type, u32 mask)
1580{ 1583{
1581 struct crypto_ablkcipher *tfm; 1584 struct crypto_skcipher *tfm;
1582 int err = 0; 1585 int err = 0;
1583 1586
1584 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask); 1587 tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1585 if (IS_ERR(tfm)) { 1588 if (IS_ERR(tfm)) {
1586 printk(KERN_ERR "alg: skcipher: Failed to load transform for " 1589 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1587 "%s: %ld\n", driver, PTR_ERR(tfm)); 1590 "%s: %ld\n", driver, PTR_ERR(tfm));
@@ -1600,7 +1603,7 @@ static int alg_test_skcipher(const struct alg_test_desc *desc,
1600 desc->suite.cipher.dec.count); 1603 desc->suite.cipher.dec.count);
1601 1604
1602out: 1605out:
1603 crypto_free_ablkcipher(tfm); 1606 crypto_free_skcipher(tfm);
1604 return err; 1607 return err;
1605} 1608}
1606 1609