From: Tadeusz Struk <tadeusz.struk@intel.com>
To: herbert@gondor.apana.org.au
Cc: tadeusz.struk@intel.com, smueller@chronox.de,
linux-api@vger.kernel.org, marcel@holtmann.org,
linux-kernel@vger.kernel.org, dhowells@redhat.com,
keyrings@vger.kernel.org, linux-crypto@vger.kernel.org,
dwmw2@infradead.org, davem@davemloft.net
Subject: [PATCH v4 6/7] crypto: KEYS - add generic handlers to symmetric key type
Date: Thu, 31 Mar 2016 18:38:20 -0700 [thread overview]
Message-ID: <20160401013819.16799.38454.stgit@tstruk-mobl1> (raw)
In-Reply-To: <20160401013745.16799.91093.stgit@tstruk-mobl1>
This adds generic sign, verify, encrypt, decrypt accessor
functions to the asymmetric key type. These will be defined by
asymmetric subtypes, similarly to how public_key currently defines
the verify_signature function.
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
---
crypto/asymmetric_keys/asymmetric_type.c | 88 ++++++++++++++++++++++++++++++
include/keys/asymmetric-subtype.h | 10 +++
include/keys/asymmetric-type.h | 15 ++++-
3 files changed, 110 insertions(+), 3 deletions(-)
diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c
index 9f2165b..d9416df 100644
--- a/crypto/asymmetric_keys/asymmetric_type.c
+++ b/crypto/asymmetric_keys/asymmetric_type.c
@@ -416,6 +416,94 @@ void unregister_asymmetric_key_parser(struct asymmetric_key_parser *parser)
}
EXPORT_SYMBOL_GPL(unregister_asymmetric_key_parser);
+/**
+ * asymmetric_key_encrypt - invoke encrypt operation on a key
+ * of the asymmetric subtype
+ * @key: key from the system keyring
+ * @input: data to be encrypted
+ * @insize: size of data to encrypt
+ * @output: output buffer
+ * @outsize: size of the output buffer. This will be updated to the actual
+ * size of encrypted data.
+ *
+ * return: 0 on success or errno on failure
+ */
+int asymmetric_key_encrypt(const struct key *key, char *input, u32 insize,
+ char *output, u32 *outsize)
+{
+ struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
+
+ if (subtype && subtype->encrypt)
+ return subtype->encrypt(key, input, insize, output, outsize);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(asymmetric_key_encrypt);
+
+/**
+ * asymmetric_key_decrypt - invoke decrypt operation on a key
+ * of the asymmetric subtype
+ * @key: key from the system keyring
+ * @input: data to be decrypted
+ * @insize: size of data to decrypt
+ * @output: output buffer
+ * @outsize: size of the output buffer. This will be updated to the actual
+ * size of decrypted data.
+ *
+ * return: 0 on success or errno on failure
+ */
+int asymmetric_key_decrypt(const struct key *key, char *input, u32 insize,
+ char *output, u32 *outsize)
+{
+ struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
+
+ if (subtype && subtype->decrypt)
+ return subtype->decrypt(key, input, insize, output, outsize);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(asymmetric_key_decrypt);
+
+/**
+ * asymmetric_key_verify_signature - invoke verify signature operation on a key
+ * of the asymmetric subtype
+ * @key: key from the system keyring
+ * @sig: signature to verify
+ *
+ * return: 0 on success or errno on failure
+ */
+int asymmetric_key_verify_signature(const struct key *key,
+ const struct public_key_signature *sig)
+{
+ struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
+
+ if (subtype && subtype->verify_signature)
+ return subtype->verify_signature(key, sig);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(asymmetric_key_verify_signature);
+
+/**
+ * asymmetric_key_create_signature - invoke create signature operation on a key
+ * of the asymmetric subtype
+ * @key: key from the system keyring
+ * @sig: output signature
+ *
+ * return: 0 on success or errno on failure
+ */
+int asymmetric_key_create_signature(const struct key *key, char *data, u32 size,
+ const struct public_key_signature **sig)
+{
+ struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
+
+ if (subtype && subtype->create_signature)
+ return subtype->create_signature(key, data, size, sig);
+
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(asymmetric_key_create_signature);
+
/*
* Module stuff
*/
diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
index 4915d40..30f673a 100644
--- a/include/keys/asymmetric-subtype.h
+++ b/include/keys/asymmetric-subtype.h
@@ -37,6 +37,16 @@ struct asymmetric_key_subtype {
/* Verify the signature on a key of this subtype (optional) */
int (*verify_signature)(const struct key *key,
const struct public_key_signature *sig);
+
+ /* Sign data using key and return the signature (optional) */
+ int (*create_signature)(const struct key *key, char *data, u32 size,
+ const struct public_key_signature **sig);
+
+ int (*encrypt)(const struct key *key, char *input, u32 insize,
+ char *output, u32 *outsize);
+
+ int (*decrypt)(const struct key *key, char *input, u32 insize,
+ char *output, u32 *outsize);
};
/**
diff --git a/include/keys/asymmetric-type.h b/include/keys/asymmetric-type.h
index 59c1df9..7a571be 100644
--- a/include/keys/asymmetric-type.h
+++ b/include/keys/asymmetric-type.h
@@ -68,14 +68,23 @@ extern struct asymmetric_key_id *asymmetric_key_generate_id(const void *val_1,
size_t len_1,
const void *val_2,
size_t len_2);
+/*
+ * The payload is at the discretion of the subtype.
+ */
static inline
const struct asymmetric_key_ids *asymmetric_key_ids(const struct key *key)
{
return key->payload.data[asym_key_ids];
}
-/*
- * The payload is at the discretion of the subtype.
- */
+struct public_key_signature;
+int asymmetric_key_encrypt(const struct key *key, char *input, u32 insize,
+ char *output, u32 *outsize);
+int asymmetric_key_decrypt(const struct key *key, char *input, u32 insize,
+ char *output, u32 *outsize);
+int asymmetric_key_verify_signature(const struct key *key,
+ const struct public_key_signature *sig);
+int asymmetric_key_create_signature(const struct key *key, char *data, u32 size,
+ const struct public_key_signature **sig);
#endif /* _KEYS_ASYMMETRIC_TYPE_H */
next prev parent reply other threads:[~2016-04-01 1:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-01 1:37 [PATCH v4 0/7] crypto: algif - add akcipher Tadeusz Struk
2016-04-01 1:37 ` [PATCH v4 1/7] crypto: AF_ALG -- add sign/verify API Tadeusz Struk
2016-04-01 1:37 ` [PATCH v4 2/7] crypto: AF_ALG -- add setpubkey setsockopt call Tadeusz Struk
2016-04-01 1:38 ` [PATCH v4 3/7] crypto: AF_ALG -- add asymmetric cipher interface Tadeusz Struk
2016-04-01 1:38 ` [PATCH v4 4/7] crypto: algif_akcipher - enable compilation Tadeusz Struk
2016-04-01 1:38 ` [PATCH v4 5/7] crypto: algif_akcipher - add ops_nokey Tadeusz Struk
2016-04-01 1:38 ` Tadeusz Struk [this message]
2016-04-12 22:10 ` [PATCH v4 6/7] crypto: KEYS - add generic handlers to symmetric key type David Howells
[not found] ` <16339.1460499046-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2016-04-12 22:20 ` Tadeusz Struk
2016-04-01 1:38 ` [PATCH v4 7/7] crypto: AF_ALG - add support for key_id Tadeusz Struk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160401013819.16799.38454.stgit@tstruk-mobl1 \
--to=tadeusz.struk@intel.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=herbert@gondor.apana.org.au \
--cc=keyrings@vger.kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=smueller@chronox.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox