diff options
Diffstat (limited to 'crypto/algapi.c')
-rw-r--r-- | crypto/algapi.c | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index 42fe316f80ee..4c1e6079d271 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c | |||
@@ -1078,6 +1078,239 @@ int crypto_type_has_alg(const char *name, const struct crypto_type *frontend, | |||
1078 | } | 1078 | } |
1079 | EXPORT_SYMBOL_GPL(crypto_type_has_alg); | 1079 | EXPORT_SYMBOL_GPL(crypto_type_has_alg); |
1080 | 1080 | ||
1081 | #ifdef CONFIG_CRYPTO_STATS | ||
1082 | void crypto_stats_get(struct crypto_alg *alg) | ||
1083 | { | ||
1084 | crypto_alg_get(alg); | ||
1085 | } | ||
1086 | EXPORT_SYMBOL_GPL(crypto_stats_get); | ||
1087 | |||
1088 | void crypto_stats_ablkcipher_encrypt(unsigned int nbytes, int ret, | ||
1089 | struct crypto_alg *alg) | ||
1090 | { | ||
1091 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1092 | atomic64_inc(&alg->cipher_err_cnt); | ||
1093 | } else { | ||
1094 | atomic64_inc(&alg->encrypt_cnt); | ||
1095 | atomic64_add(nbytes, &alg->encrypt_tlen); | ||
1096 | } | ||
1097 | crypto_alg_put(alg); | ||
1098 | } | ||
1099 | EXPORT_SYMBOL_GPL(crypto_stats_ablkcipher_encrypt); | ||
1100 | |||
1101 | void crypto_stats_ablkcipher_decrypt(unsigned int nbytes, int ret, | ||
1102 | struct crypto_alg *alg) | ||
1103 | { | ||
1104 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1105 | atomic64_inc(&alg->cipher_err_cnt); | ||
1106 | } else { | ||
1107 | atomic64_inc(&alg->decrypt_cnt); | ||
1108 | atomic64_add(nbytes, &alg->decrypt_tlen); | ||
1109 | } | ||
1110 | crypto_alg_put(alg); | ||
1111 | } | ||
1112 | EXPORT_SYMBOL_GPL(crypto_stats_ablkcipher_decrypt); | ||
1113 | |||
1114 | void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg, | ||
1115 | int ret) | ||
1116 | { | ||
1117 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1118 | atomic64_inc(&alg->aead_err_cnt); | ||
1119 | } else { | ||
1120 | atomic64_inc(&alg->encrypt_cnt); | ||
1121 | atomic64_add(cryptlen, &alg->encrypt_tlen); | ||
1122 | } | ||
1123 | crypto_alg_put(alg); | ||
1124 | } | ||
1125 | EXPORT_SYMBOL_GPL(crypto_stats_aead_encrypt); | ||
1126 | |||
1127 | void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg, | ||
1128 | int ret) | ||
1129 | { | ||
1130 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1131 | atomic64_inc(&alg->aead_err_cnt); | ||
1132 | } else { | ||
1133 | atomic64_inc(&alg->decrypt_cnt); | ||
1134 | atomic64_add(cryptlen, &alg->decrypt_tlen); | ||
1135 | } | ||
1136 | crypto_alg_put(alg); | ||
1137 | } | ||
1138 | EXPORT_SYMBOL_GPL(crypto_stats_aead_decrypt); | ||
1139 | |||
1140 | void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret, | ||
1141 | struct crypto_alg *alg) | ||
1142 | { | ||
1143 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1144 | atomic64_inc(&alg->akcipher_err_cnt); | ||
1145 | } else { | ||
1146 | atomic64_inc(&alg->encrypt_cnt); | ||
1147 | atomic64_add(src_len, &alg->encrypt_tlen); | ||
1148 | } | ||
1149 | crypto_alg_put(alg); | ||
1150 | } | ||
1151 | EXPORT_SYMBOL_GPL(crypto_stats_akcipher_encrypt); | ||
1152 | |||
1153 | void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret, | ||
1154 | struct crypto_alg *alg) | ||
1155 | { | ||
1156 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1157 | atomic64_inc(&alg->akcipher_err_cnt); | ||
1158 | } else { | ||
1159 | atomic64_inc(&alg->decrypt_cnt); | ||
1160 | atomic64_add(src_len, &alg->decrypt_tlen); | ||
1161 | } | ||
1162 | crypto_alg_put(alg); | ||
1163 | } | ||
1164 | EXPORT_SYMBOL_GPL(crypto_stats_akcipher_decrypt); | ||
1165 | |||
1166 | void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg) | ||
1167 | { | ||
1168 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) | ||
1169 | atomic64_inc(&alg->akcipher_err_cnt); | ||
1170 | else | ||
1171 | atomic64_inc(&alg->sign_cnt); | ||
1172 | crypto_alg_put(alg); | ||
1173 | } | ||
1174 | EXPORT_SYMBOL_GPL(crypto_stats_akcipher_sign); | ||
1175 | |||
1176 | void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg) | ||
1177 | { | ||
1178 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) | ||
1179 | atomic64_inc(&alg->akcipher_err_cnt); | ||
1180 | else | ||
1181 | atomic64_inc(&alg->verify_cnt); | ||
1182 | crypto_alg_put(alg); | ||
1183 | } | ||
1184 | EXPORT_SYMBOL_GPL(crypto_stats_akcipher_verify); | ||
1185 | |||
1186 | void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg) | ||
1187 | { | ||
1188 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1189 | atomic64_inc(&alg->compress_err_cnt); | ||
1190 | } else { | ||
1191 | atomic64_inc(&alg->compress_cnt); | ||
1192 | atomic64_add(slen, &alg->compress_tlen); | ||
1193 | } | ||
1194 | crypto_alg_put(alg); | ||
1195 | } | ||
1196 | EXPORT_SYMBOL_GPL(crypto_stats_compress); | ||
1197 | |||
1198 | void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg) | ||
1199 | { | ||
1200 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1201 | atomic64_inc(&alg->compress_err_cnt); | ||
1202 | } else { | ||
1203 | atomic64_inc(&alg->decompress_cnt); | ||
1204 | atomic64_add(slen, &alg->decompress_tlen); | ||
1205 | } | ||
1206 | crypto_alg_put(alg); | ||
1207 | } | ||
1208 | EXPORT_SYMBOL_GPL(crypto_stats_decompress); | ||
1209 | |||
1210 | void crypto_stats_ahash_update(unsigned int nbytes, int ret, | ||
1211 | struct crypto_alg *alg) | ||
1212 | { | ||
1213 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) | ||
1214 | atomic64_inc(&alg->hash_err_cnt); | ||
1215 | else | ||
1216 | atomic64_add(nbytes, &alg->hash_tlen); | ||
1217 | crypto_alg_put(alg); | ||
1218 | } | ||
1219 | EXPORT_SYMBOL_GPL(crypto_stats_ahash_update); | ||
1220 | |||
1221 | void crypto_stats_ahash_final(unsigned int nbytes, int ret, | ||
1222 | struct crypto_alg *alg) | ||
1223 | { | ||
1224 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1225 | atomic64_inc(&alg->hash_err_cnt); | ||
1226 | } else { | ||
1227 | atomic64_inc(&alg->hash_cnt); | ||
1228 | atomic64_add(nbytes, &alg->hash_tlen); | ||
1229 | } | ||
1230 | crypto_alg_put(alg); | ||
1231 | } | ||
1232 | EXPORT_SYMBOL_GPL(crypto_stats_ahash_final); | ||
1233 | |||
1234 | void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret) | ||
1235 | { | ||
1236 | if (ret) | ||
1237 | atomic64_inc(&alg->kpp_err_cnt); | ||
1238 | else | ||
1239 | atomic64_inc(&alg->setsecret_cnt); | ||
1240 | crypto_alg_put(alg); | ||
1241 | } | ||
1242 | EXPORT_SYMBOL_GPL(crypto_stats_kpp_set_secret); | ||
1243 | |||
1244 | void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret) | ||
1245 | { | ||
1246 | if (ret) | ||
1247 | atomic64_inc(&alg->kpp_err_cnt); | ||
1248 | else | ||
1249 | atomic64_inc(&alg->generate_public_key_cnt); | ||
1250 | crypto_alg_put(alg); | ||
1251 | } | ||
1252 | EXPORT_SYMBOL_GPL(crypto_stats_kpp_generate_public_key); | ||
1253 | |||
1254 | void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret) | ||
1255 | { | ||
1256 | if (ret) | ||
1257 | atomic64_inc(&alg->kpp_err_cnt); | ||
1258 | else | ||
1259 | atomic64_inc(&alg->compute_shared_secret_cnt); | ||
1260 | crypto_alg_put(alg); | ||
1261 | } | ||
1262 | EXPORT_SYMBOL_GPL(crypto_stats_kpp_compute_shared_secret); | ||
1263 | |||
1264 | void crypto_stats_rng_seed(struct crypto_alg *alg, int ret) | ||
1265 | { | ||
1266 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) | ||
1267 | atomic64_inc(&alg->rng_err_cnt); | ||
1268 | else | ||
1269 | atomic64_inc(&alg->seed_cnt); | ||
1270 | crypto_alg_put(alg); | ||
1271 | } | ||
1272 | EXPORT_SYMBOL_GPL(crypto_stats_rng_seed); | ||
1273 | |||
1274 | void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen, | ||
1275 | int ret) | ||
1276 | { | ||
1277 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1278 | atomic64_inc(&alg->rng_err_cnt); | ||
1279 | } else { | ||
1280 | atomic64_inc(&alg->generate_cnt); | ||
1281 | atomic64_add(dlen, &alg->generate_tlen); | ||
1282 | } | ||
1283 | crypto_alg_put(alg); | ||
1284 | } | ||
1285 | EXPORT_SYMBOL_GPL(crypto_stats_rng_generate); | ||
1286 | |||
1287 | void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret, | ||
1288 | struct crypto_alg *alg) | ||
1289 | { | ||
1290 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1291 | atomic64_inc(&alg->cipher_err_cnt); | ||
1292 | } else { | ||
1293 | atomic64_inc(&alg->encrypt_cnt); | ||
1294 | atomic64_add(cryptlen, &alg->encrypt_tlen); | ||
1295 | } | ||
1296 | crypto_alg_put(alg); | ||
1297 | } | ||
1298 | EXPORT_SYMBOL_GPL(crypto_stats_skcipher_encrypt); | ||
1299 | |||
1300 | void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret, | ||
1301 | struct crypto_alg *alg) | ||
1302 | { | ||
1303 | if (ret && ret != -EINPROGRESS && ret != -EBUSY) { | ||
1304 | atomic64_inc(&alg->cipher_err_cnt); | ||
1305 | } else { | ||
1306 | atomic64_inc(&alg->decrypt_cnt); | ||
1307 | atomic64_add(cryptlen, &alg->decrypt_tlen); | ||
1308 | } | ||
1309 | crypto_alg_put(alg); | ||
1310 | } | ||
1311 | EXPORT_SYMBOL_GPL(crypto_stats_skcipher_decrypt); | ||
1312 | #endif | ||
1313 | |||
1081 | static int __init crypto_algapi_init(void) | 1314 | static int __init crypto_algapi_init(void) |
1082 | { | 1315 | { |
1083 | crypto_init_proc(); | 1316 | crypto_init_proc(); |