Alignment in the API, once again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Herbert, 

about the aligment in the crypto API, I'm lost once again.
In commit f10b7897ee29649fa7f0ccdc8d859ccd6ce7dbfd you extended the
alignment to be as wide as possible (i.e. algo specified 3, natural is
8, do 8).
Currently crypto_ctxsize(), what is used by __crypto_alloc_tfm() in
order to allocate space for tfm + priv ctx, looks like:

 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1);
 if (type_obj)
        return len + type_obj->ctxsize(alg, type, mask);

Now, in my case alg->cra_alignmask is 15 and crypto_tfm_ctx_alignment()
returns 8 (ppc64). This makes 15 & ~(8-1) = 8 or too less. My mistake,
make it 16 instead of 15 and everything is fine again. aes.c + cbc.c
specify a mask of 3. The same thing once again: 3 & ~(8-1) = 0. This
makes me thing, that the line that calculates len, should maybe be 

 len = alg->cra_alignmask | (crypto_tfm_ctx_alignment() - 1);

or?
I noticed this, after my code did not work properly. The reason was,
that my private ctx was not retrieved with
crypto_ablkcipher_ctx_aligned() (attached) but with
crypto_ablkcipher_ctx() (and it was not properly aligned anymore).
My fault right? 
Shouldn't the behavior of crypto_blkcipher_ctx_aligned() (which is
currently unused) be the default one?

Sebastian
---

--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -160,6 +160,11 @@ static inline void *crypto_ablkcipher_ct
 	return crypto_tfm_ctx(&tfm->base);
 }
 
+static inline void *crypto_ablkcipher_ctx_aligned(struct crypto_ablkcipher *tfm)
+{
+	return crypto_tfm_ctx_aligned(&tfm->base);
+}
+
 static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
 	struct crypto_spawn *spawn)
 {
-
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux