diff mbox

[v3,3/4] crypto: akcipher: add akcipher declarations useful for templates.

Message ID 1447989215-523-3-git-send-email-andrew.zaborowski@intel.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show

Commit Message

Andrew Zaborowski Nov. 20, 2015, 3:13 a.m. UTC
Expose crypto_akcipher_type like other crypto types are exposed to be
used from outside akcipher.c.  Add a struct akcipher_instance similar to
aead_instance with just the right size for an akcipher template
instance, and two macros for converting to/from crypto_instance.

Signed-off-by: Andrew Zaborowski <andrew.zaborowski@intel.com>
---
v2: no changes since v1
v3: drop the new crypto_akcipher_type methods and
    add struct akcipher_instance
---
 crypto/akcipher.c                  |  3 ++-
 include/crypto/algapi.h            |  1 +
 include/crypto/internal/akcipher.h | 23 +++++++++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

Comments

Herbert Xu Nov. 24, 2015, 9:54 a.m. UTC | #1
Andrew Zaborowski <andrew.zaborowski@intel.com> wrote:
> Expose crypto_akcipher_type like other crypto types are exposed to be
> used from outside akcipher.c.  Add a struct akcipher_instance similar to
> aead_instance with just the right size for an akcipher template
> instance, and two macros for converting to/from crypto_instance.

You're still doing some things in the old way.  With new templates,
you shouldn't need to export the crypto type at all.  Please look
at how AEAD does it.

Thanks,
Andrew Zaborowski Nov. 24, 2015, 8:54 p.m. UTC | #2
On 24 November 2015 at 10:54, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> Andrew Zaborowski <andrew.zaborowski@intel.com> wrote:
>> Expose crypto_akcipher_type like other crypto types are exposed to be
>> used from outside akcipher.c.  Add a struct akcipher_instance similar to
>> aead_instance with just the right size for an akcipher template
>> instance, and two macros for converting to/from crypto_instance.
>
> You're still doing some things in the old way.  With new templates,
> you shouldn't need to export the crypto type at all.  Please look
> at how AEAD does it.

It doesn't need to export crypto_aead_type but instead needs to export
crypto_aead_grab and aead_register_instance.  I'll add those for
akcipher and resend then.  Would there be any point defining a
crypto_akcipher_spawn following the AEAD pattern?

Best regards
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Herbert Xu Nov. 25, 2015, 1:18 a.m. UTC | #3
On Tue, Nov 24, 2015 at 09:54:57PM +0100, Andrzej Zaborowski wrote:
>
> It doesn't need to export crypto_aead_type but instead needs to export
> crypto_aead_grab and aead_register_instance.  I'll add those for
> akcipher and resend then.  Would there be any point defining a
> crypto_akcipher_spawn following the AEAD pattern?

Well if you need to spawn an akcipher (which I presume you do) then
yes you should define it.

Cheers,
diff mbox

Patch

diff --git a/crypto/akcipher.c b/crypto/akcipher.c
index 120ec04..d4bb42c 100644
--- a/crypto/akcipher.c
+++ b/crypto/akcipher.c
@@ -75,7 +75,7 @@  static int crypto_akcipher_init_tfm(struct crypto_tfm *tfm)
 	return 0;
 }
 
-static const struct crypto_type crypto_akcipher_type = {
+const struct crypto_type crypto_akcipher_type = {
 	.extsize = crypto_alg_extsize,
 	.init_tfm = crypto_akcipher_init_tfm,
 #ifdef CONFIG_PROC_FS
@@ -87,6 +87,7 @@  static const struct crypto_type crypto_akcipher_type = {
 	.type = CRYPTO_ALG_TYPE_AKCIPHER,
 	.tfmsize = offsetof(struct crypto_akcipher, base),
 };
+EXPORT_SYMBOL_GPL(crypto_akcipher_type);
 
 struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type,
 					      u32 mask)
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index c9fe145..1089f20 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -130,6 +130,7 @@  struct ablkcipher_walk {
 
 extern const struct crypto_type crypto_ablkcipher_type;
 extern const struct crypto_type crypto_blkcipher_type;
+extern const struct crypto_type crypto_akcipher_type;
 
 void crypto_mod_put(struct crypto_alg *alg);
 
diff --git a/include/crypto/internal/akcipher.h b/include/crypto/internal/akcipher.h
index 9a2bda1..706aa82 100644
--- a/include/crypto/internal/akcipher.h
+++ b/include/crypto/internal/akcipher.h
@@ -13,6 +13,17 @@ 
 #ifndef _CRYPTO_AKCIPHER_INT_H
 #define _CRYPTO_AKCIPHER_INT_H
 #include <crypto/akcipher.h>
+#include <crypto/algapi.h>
+
+struct akcipher_instance {
+	union {
+		struct {
+			char head[offsetof(struct akcipher_alg, base)];
+			struct crypto_instance base;
+		} s;
+		struct akcipher_alg alg;
+	};
+};
 
 /*
  * Transform internal helpers.
@@ -57,4 +68,16 @@  int crypto_register_akcipher(struct akcipher_alg *alg);
  * @alg:	algorithm definition
  */
 void crypto_unregister_akcipher(struct akcipher_alg *alg);
+
+static inline struct crypto_instance *akcipher_crypto_instance(
+		struct akcipher_instance *inst)
+{
+	return container_of(&inst->alg.base, struct crypto_instance, alg);
+}
+
+static inline struct akcipher_instance *akcipher_instance(
+		struct crypto_instance *inst)
+{
+	return container_of(&inst->alg, struct akcipher_instance, alg.base);
+}
 #endif