aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorCristian Stoica <cristian.stoica@freescale.com>2014-08-08 07:27:51 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2014-08-25 08:27:18 -0400
commita1aa44a2eb498d17e725578f5c30c160a8ed9f8d (patch)
tree14ba887d2f7ee22b67dc956610a1f5f3eb460d8c /crypto/testmgr.c
parent5f2b424e5c6c2d4de2c72875ea970e5984fe9268 (diff)
crypto: testmgr - white space removal on __test_skcipher
This patch inverts two if conditions to remove code blocks indentation. Several white space clean-ups follow. Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c287
1 files changed, 138 insertions, 149 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 66d536421448..7fe4225b5513 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -966,73 +966,69 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
966 else 966 else
967 memset(iv, 0, MAX_IVLEN); 967 memset(iv, 0, MAX_IVLEN);
968 968
969 if (!(template[i].np) || (template[i].also_non_np)) { 969 if (template[i].np && !template[i].also_non_np)
970 j++; 970 continue;
971 971
972 ret = -EINVAL; 972 j++;
973 if (WARN_ON(align_offset + template[i].ilen >
974 PAGE_SIZE))
975 goto out;
976 973
977 data = xbuf[0]; 974 ret = -EINVAL;
978 data += align_offset; 975 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
979 memcpy(data, template[i].input, template[i].ilen); 976 goto out;
980
981 crypto_ablkcipher_clear_flags(tfm, ~0);
982 if (template[i].wk)
983 crypto_ablkcipher_set_flags(
984 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
985
986 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
987 template[i].klen);
988 if (!ret == template[i].fail) {
989 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
990 d, j, algo,
991 crypto_ablkcipher_get_flags(tfm));
992 goto out;
993 } else if (ret)
994 continue;
995 977
996 sg_init_one(&sg[0], data, template[i].ilen); 978 data = xbuf[0];
997 if (diff_dst) { 979 data += align_offset;
998 data = xoutbuf[0]; 980 memcpy(data, template[i].input, template[i].ilen);
999 data += align_offset;
1000 sg_init_one(&sgout[0], data, template[i].ilen);
1001 }
1002 981
1003 ablkcipher_request_set_crypt(req, sg, 982 crypto_ablkcipher_clear_flags(tfm, ~0);
1004 (diff_dst) ? sgout : sg, 983 if (template[i].wk)
1005 template[i].ilen, iv); 984 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1006 ret = enc ?
1007 crypto_ablkcipher_encrypt(req) :
1008 crypto_ablkcipher_decrypt(req);
1009 985
1010 switch (ret) { 986 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1011 case 0: 987 template[i].klen);
988 if (!ret == template[i].fail) {
989 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
990 d, j, algo, crypto_ablkcipher_get_flags(tfm));
991 goto out;
992 } else if (ret)
993 continue;
994
995 sg_init_one(&sg[0], data, template[i].ilen);
996 if (diff_dst) {
997 data = xoutbuf[0];
998 data += align_offset;
999 sg_init_one(&sgout[0], data, template[i].ilen);
1000 }
1001
1002 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1003 template[i].ilen, iv);
1004 ret = enc ? crypto_ablkcipher_encrypt(req) :
1005 crypto_ablkcipher_decrypt(req);
1006
1007 switch (ret) {
1008 case 0:
1009 break;
1010 case -EINPROGRESS:
1011 case -EBUSY:
1012 ret = wait_for_completion_interruptible(
1013 &result.completion);
1014 if (!ret && !((ret = result.err))) {
1015 reinit_completion(&result.completion);
1012 break; 1016 break;
1013 case -EINPROGRESS:
1014 case -EBUSY:
1015 ret = wait_for_completion_interruptible(
1016 &result.completion);
1017 if (!ret && !((ret = result.err))) {
1018 reinit_completion(&result.completion);
1019 break;
1020 }
1021 /* fall through */
1022 default:
1023 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1024 d, e, j, algo, -ret);
1025 goto out;
1026 } 1017 }
1018 /* fall through */
1019 default:
1020 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1021 d, e, j, algo, -ret);
1022 goto out;
1023 }
1027 1024
1028 q = data; 1025 q = data;
1029 if (memcmp(q, template[i].result, template[i].rlen)) { 1026 if (memcmp(q, template[i].result, template[i].rlen)) {
1030 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n", 1027 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1031 d, j, e, algo); 1028 d, j, e, algo);
1032 hexdump(q, template[i].rlen); 1029 hexdump(q, template[i].rlen);
1033 ret = -EINVAL; 1030 ret = -EINVAL;
1034 goto out; 1031 goto out;
1035 }
1036 } 1032 }
1037 } 1033 }
1038 1034
@@ -1047,116 +1043,109 @@ static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1047 else 1043 else
1048 memset(iv, 0, MAX_IVLEN); 1044 memset(iv, 0, MAX_IVLEN);
1049 1045
1050 if (template[i].np) { 1046 if (!template[i].np)
1051 j++; 1047 continue;
1052 1048
1053 crypto_ablkcipher_clear_flags(tfm, ~0); 1049 j++;
1054 if (template[i].wk)
1055 crypto_ablkcipher_set_flags(
1056 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1057 1050
1058 ret = crypto_ablkcipher_setkey(tfm, template[i].key, 1051 crypto_ablkcipher_clear_flags(tfm, ~0);
1059 template[i].klen); 1052 if (template[i].wk)
1060 if (!ret == template[i].fail) { 1053 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1061 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1062 d, j, algo,
1063 crypto_ablkcipher_get_flags(tfm));
1064 goto out;
1065 } else if (ret)
1066 continue;
1067 1054
1068 temp = 0; 1055 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1069 ret = -EINVAL; 1056 template[i].klen);
1070 sg_init_table(sg, template[i].np); 1057 if (!ret == template[i].fail) {
1071 if (diff_dst) 1058 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1072 sg_init_table(sgout, template[i].np); 1059 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1073 for (k = 0; k < template[i].np; k++) { 1060 goto out;
1074 if (WARN_ON(offset_in_page(IDX[k]) + 1061 } else if (ret)
1075 template[i].tap[k] > PAGE_SIZE)) 1062 continue;
1076 goto out;
1077 1063
1078 q = xbuf[IDX[k] >> PAGE_SHIFT] + 1064 temp = 0;
1079 offset_in_page(IDX[k]); 1065 ret = -EINVAL;
1066 sg_init_table(sg, template[i].np);
1067 if (diff_dst)
1068 sg_init_table(sgout, template[i].np);
1069 for (k = 0; k < template[i].np; k++) {
1070 if (WARN_ON(offset_in_page(IDX[k]) +
1071 template[i].tap[k] > PAGE_SIZE))
1072 goto out;
1080 1073
1081 memcpy(q, template[i].input + temp, 1074 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1082 template[i].tap[k]);
1083 1075
1084 if (offset_in_page(q) + template[i].tap[k] < 1076 memcpy(q, template[i].input + temp, template[i].tap[k]);
1085 PAGE_SIZE)
1086 q[template[i].tap[k]] = 0;
1087 1077
1088 sg_set_buf(&sg[k], q, template[i].tap[k]); 1078 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1089 if (diff_dst) { 1079 q[template[i].tap[k]] = 0;
1090 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1091 offset_in_page(IDX[k]);
1092 1080
1093 sg_set_buf(&sgout[k], q, 1081 sg_set_buf(&sg[k], q, template[i].tap[k]);
1094 template[i].tap[k]); 1082 if (diff_dst) {
1083 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1084 offset_in_page(IDX[k]);
1095 1085
1096 memset(q, 0, template[i].tap[k]); 1086 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1097 if (offset_in_page(q) +
1098 template[i].tap[k] < PAGE_SIZE)
1099 q[template[i].tap[k]] = 0;
1100 }
1101 1087
1102 temp += template[i].tap[k]; 1088 memset(q, 0, template[i].tap[k]);
1089 if (offset_in_page(q) +
1090 template[i].tap[k] < PAGE_SIZE)
1091 q[template[i].tap[k]] = 0;
1103 } 1092 }
1104 1093
1105 ablkcipher_request_set_crypt(req, sg, 1094 temp += template[i].tap[k];
1106 (diff_dst) ? sgout : sg, 1095 }
1107 template[i].ilen, iv);
1108 1096
1109 ret = enc ? 1097 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1110 crypto_ablkcipher_encrypt(req) : 1098 template[i].ilen, iv);
1111 crypto_ablkcipher_decrypt(req);
1112 1099
1113 switch (ret) { 1100 ret = enc ? crypto_ablkcipher_encrypt(req) :
1114 case 0: 1101 crypto_ablkcipher_decrypt(req);
1115 break; 1102
1116 case -EINPROGRESS: 1103 switch (ret) {
1117 case -EBUSY: 1104 case 0:
1118 ret = wait_for_completion_interruptible( 1105 break;
1106 case -EINPROGRESS:
1107 case -EBUSY:
1108 ret = wait_for_completion_interruptible(
1119 &result.completion); 1109 &result.completion);
1120 if (!ret && !((ret = result.err))) { 1110 if (!ret && !((ret = result.err))) {
1121 reinit_completion(&result.completion); 1111 reinit_completion(&result.completion);
1122 break; 1112 break;
1123 }
1124 /* fall through */
1125 default:
1126 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1127 d, e, j, algo, -ret);
1128 goto out;
1129 } 1113 }
1114 /* fall through */
1115 default:
1116 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1117 d, e, j, algo, -ret);
1118 goto out;
1119 }
1130 1120
1131 temp = 0; 1121 temp = 0;
1132 ret = -EINVAL; 1122 ret = -EINVAL;
1133 for (k = 0; k < template[i].np; k++) { 1123 for (k = 0; k < template[i].np; k++) {
1134 if (diff_dst) 1124 if (diff_dst)
1135 q = xoutbuf[IDX[k] >> PAGE_SHIFT] + 1125 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1136 offset_in_page(IDX[k]); 1126 offset_in_page(IDX[k]);
1137 else 1127 else
1138 q = xbuf[IDX[k] >> PAGE_SHIFT] + 1128 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1139 offset_in_page(IDX[k]); 1129 offset_in_page(IDX[k]);
1140 1130
1141 if (memcmp(q, template[i].result + temp, 1131 if (memcmp(q, template[i].result + temp,
1142 template[i].tap[k])) { 1132 template[i].tap[k])) {
1143 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n", 1133 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1144 d, j, e, k, algo); 1134 d, j, e, k, algo);
1145 hexdump(q, template[i].tap[k]); 1135 hexdump(q, template[i].tap[k]);
1146 goto out; 1136 goto out;
1147 } 1137 }
1148 1138
1149 q += template[i].tap[k]; 1139 q += template[i].tap[k];
1150 for (n = 0; offset_in_page(q + n) && q[n]; n++) 1140 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1151 ; 1141 ;
1152 if (n) { 1142 if (n) {
1153 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n", 1143 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1154 d, j, e, k, algo, n); 1144 d, j, e, k, algo, n);
1155 hexdump(q, n); 1145 hexdump(q, n);
1156 goto out; 1146 goto out;
1157 }
1158 temp += template[i].tap[k];
1159 } 1147 }
1148 temp += template[i].tap[k];
1160 } 1149 }
1161 } 1150 }
1162 1151