Re: Alignment in the API, once again
From: Sebastian Siewior <hidden>
Date: 2007-08-02 07:41:26
* Herbert Xu | 2007-08-02 10:30:06 [+0800]:
quoted
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?Yeah if your ctx needs to be aligned you need to use crypto_tfm_ctx_aligned.
Okey this makes sense. What about crypto_ctxsize()? Isn't a bug there? I can't specify an alignmask of 16 (what I assumed yesterday after a part of brain switched to sleep()) because this brakes the ALIGN() macro. Isn't something like
--- a/crypto/api.c
+++ b/crypto/api.c@@ -273,7 +273,7 @@ static unsigned int crypto_ctxsize(struc const struct crypto_type *type_obj = alg->cra_type; unsigned int len; - len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); + len = alg->cra_alignmask | (crypto_tfm_ctx_alignment() -1) if (type_obj) return len + type_obj->ctxsize(alg, type, mask); ----
required? VIA's PadLock driver uses manully ALIGN() instead of crypto_.*_ctx_aligned() to do this. Therefore it will overwrite memory or am I overlooking something?
quoted
--- 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)Looks good. Could you add a description and sign-off?
Yes, no problem. Sebastian