0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #define pr_fmt(fmt) "SIG: "fmt
0011 #include <keys/asymmetric-subtype.h>
0012 #include <linux/export.h>
0013 #include <linux/err.h>
0014 #include <linux/slab.h>
0015 #include <linux/keyctl.h>
0016 #include <crypto/public_key.h>
0017 #include <keys/user-type.h>
0018 #include "asymmetric_keys.h"
0019
0020
0021
0022
0023 void public_key_signature_free(struct public_key_signature *sig)
0024 {
0025 int i;
0026
0027 if (sig) {
0028 for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++)
0029 kfree(sig->auth_ids[i]);
0030 kfree(sig->s);
0031 kfree(sig->digest);
0032 kfree(sig);
0033 }
0034 }
0035 EXPORT_SYMBOL_GPL(public_key_signature_free);
0036
0037
0038
0039
0040
0041
0042 int query_asymmetric_key(const struct kernel_pkey_params *params,
0043 struct kernel_pkey_query *info)
0044 {
0045 const struct asymmetric_key_subtype *subtype;
0046 struct key *key = params->key;
0047 int ret;
0048
0049 pr_devel("==>%s()\n", __func__);
0050
0051 if (key->type != &key_type_asymmetric)
0052 return -EINVAL;
0053 subtype = asymmetric_key_subtype(key);
0054 if (!subtype ||
0055 !key->payload.data[0])
0056 return -EINVAL;
0057 if (!subtype->query)
0058 return -ENOTSUPP;
0059
0060 ret = subtype->query(params, info);
0061
0062 pr_devel("<==%s() = %d\n", __func__, ret);
0063 return ret;
0064 }
0065 EXPORT_SYMBOL_GPL(query_asymmetric_key);
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 int encrypt_blob(struct kernel_pkey_params *params,
0081 const void *data, void *enc)
0082 {
0083 params->op = kernel_pkey_encrypt;
0084 return asymmetric_key_eds_op(params, data, enc);
0085 }
0086 EXPORT_SYMBOL_GPL(encrypt_blob);
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 int decrypt_blob(struct kernel_pkey_params *params,
0102 const void *enc, void *data)
0103 {
0104 params->op = kernel_pkey_decrypt;
0105 return asymmetric_key_eds_op(params, enc, data);
0106 }
0107 EXPORT_SYMBOL_GPL(decrypt_blob);
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 int create_signature(struct kernel_pkey_params *params,
0123 const void *data, void *enc)
0124 {
0125 params->op = kernel_pkey_sign;
0126 return asymmetric_key_eds_op(params, data, enc);
0127 }
0128 EXPORT_SYMBOL_GPL(create_signature);
0129
0130
0131
0132
0133
0134
0135
0136
0137 int verify_signature(const struct key *key,
0138 const struct public_key_signature *sig)
0139 {
0140 const struct asymmetric_key_subtype *subtype;
0141 int ret;
0142
0143 pr_devel("==>%s()\n", __func__);
0144
0145 if (key->type != &key_type_asymmetric)
0146 return -EINVAL;
0147 subtype = asymmetric_key_subtype(key);
0148 if (!subtype ||
0149 !key->payload.data[0])
0150 return -EINVAL;
0151 if (!subtype->verify_signature)
0152 return -ENOTSUPP;
0153
0154 ret = subtype->verify_signature(key, sig);
0155
0156 pr_devel("<==%s() = %d\n", __func__, ret);
0157 return ret;
0158 }
0159 EXPORT_SYMBOL_GPL(verify_signature);