* [PATCH] crypto: fix unaligned access in khazad module
@ 2006-03-09 3:26 Atsushi Nemoto
2006-03-09 22:10 ` Herbert Xu
2006-04-03 15:05 ` Atsushi Nemoto
0 siblings, 2 replies; 6+ messages in thread
From: Atsushi Nemoto @ 2006-03-09 3:26 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-crypto, herbert, akpm
On 64-bit platform, reading directly from keys (which supposed to be
32-bit aligned) will result in unaligned access.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
diff --git a/crypto/khazad.c b/crypto/khazad.c
index 807f2bf..c7e1d25 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -26,6 +26,7 @@
#include <asm/scatterlist.h>
#include <linux/crypto.h>
#include <linux/types.h>
+#include <asm/unaligned.h>
#define KHAZAD_KEY_SIZE 16
#define KHAZAD_BLOCK_SIZE 8
@@ -769,8 +770,8 @@ static int khazad_setkey(void *ctx_arg,
return -EINVAL;
}
- K2 = be64_to_cpu(key[0]);
- K1 = be64_to_cpu(key[1]);
+ K2 = be64_to_cpu(get_unaligned(&key[0]));
+ K1 = be64_to_cpu(get_unaligned(&key[1]));
/* setup the encrypt key */
for (r = 0; r <= KHAZAD_ROUNDS; r++) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: fix unaligned access in khazad module
2006-03-09 3:26 [PATCH] crypto: fix unaligned access in khazad module Atsushi Nemoto
@ 2006-03-09 22:10 ` Herbert Xu
2006-04-03 15:05 ` Atsushi Nemoto
1 sibling, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2006-03-09 22:10 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-kernel, linux-crypto, akpm
On Thu, Mar 09, 2006 at 12:26:38PM +0900, Atsushi Nemoto wrote:
>
> - K2 = be64_to_cpu(key[0]);
> - K1 = be64_to_cpu(key[1]);
> + K2 = be64_to_cpu(get_unaligned(&key[0]));
> + K1 = be64_to_cpu(get_unaligned(&key[1]));
How about doing two 32-bit reads:
const __be32 *key = (const __be32 *)in_key;
K2 = ((u64)be32_to_cpu(key[0])) << 32 + be32_to_cpu(key[1]);
K1 = ((u64)be32_to_cpu(key[2])) << 32 + be32_to_cpu(key[3]);
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: fix unaligned access in khazad module
2006-03-09 3:26 [PATCH] crypto: fix unaligned access in khazad module Atsushi Nemoto
2006-03-09 22:10 ` Herbert Xu
@ 2006-04-03 15:05 ` Atsushi Nemoto
2006-04-03 23:11 ` Herbert Xu
1 sibling, 1 reply; 6+ messages in thread
From: Atsushi Nemoto @ 2006-04-03 15:05 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-crypto, herbert, akpm
Ping. This patch can be applied cleanly to 2.6.17-rc1.
On 64-bit platform, reading directly from keys (which supposed to be
32-bit aligned) will result in unaligned access.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
diff --git a/crypto/khazad.c b/crypto/khazad.c
index 807f2bf..c7e1d25 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -26,6 +26,7 @@
#include <asm/scatterlist.h>
#include <linux/crypto.h>
#include <linux/types.h>
+#include <asm/unaligned.h>
#define KHAZAD_KEY_SIZE 16
#define KHAZAD_BLOCK_SIZE 8
@@ -769,8 +770,8 @@ static int khazad_setkey(void *ctx_arg,
return -EINVAL;
}
- K2 = be64_to_cpu(key[0]);
- K1 = be64_to_cpu(key[1]);
+ K2 = be64_to_cpu(get_unaligned(&key[0]));
+ K1 = be64_to_cpu(get_unaligned(&key[1]));
/* setup the encrypt key */
for (r = 0; r <= KHAZAD_ROUNDS; r++) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: fix unaligned access in khazad module
2006-04-03 15:05 ` Atsushi Nemoto
@ 2006-04-03 23:11 ` Herbert Xu
2006-04-04 7:55 ` Atsushi Nemoto
0 siblings, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2006-04-03 23:11 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-kernel, linux-crypto, akpm
On Tue, Apr 04, 2006 at 12:05:18AM +0900, Atsushi Nemoto wrote:
>
> - K2 = be64_to_cpu(key[0]);
> - K1 = be64_to_cpu(key[1]);
> + K2 = be64_to_cpu(get_unaligned(&key[0]));
> + K1 = be64_to_cpu(get_unaligned(&key[1]));
Would it be possible to turn these into two 32-bit aligned reads instead?
Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: fix unaligned access in khazad module
2006-04-03 23:11 ` Herbert Xu
@ 2006-04-04 7:55 ` Atsushi Nemoto
2006-04-05 17:29 ` Herbert Xu
0 siblings, 1 reply; 6+ messages in thread
From: Atsushi Nemoto @ 2006-04-04 7:55 UTC (permalink / raw)
To: herbert; +Cc: linux-kernel, linux-crypto, akpm
On Tue, 4 Apr 2006 09:11:22 +1000, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> > - K2 = be64_to_cpu(key[0]);
> > - K1 = be64_to_cpu(key[1]);
> > + K2 = be64_to_cpu(get_unaligned(&key[0]));
> > + K1 = be64_to_cpu(get_unaligned(&key[1]));
>
> Would it be possible to turn these into two 32-bit aligned reads instead?
Done now. I've missed your comment on 10 Mar, sorry for duplication.
On 64-bit platform, reading 64-bit keys (which is supposed to be
32-bit aligned) at a time will result in unaligned access.
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
diff --git a/crypto/khazad.c b/crypto/khazad.c
index 807f2bf..5b8dc9a 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -758,7 +758,7 @@ static int khazad_setkey(void *ctx_arg,
unsigned int key_len, u32 *flags)
{
struct khazad_ctx *ctx = ctx_arg;
- const __be64 *key = (const __be64 *)in_key;
+ const __be32 *key = (const __be32 *)in_key;
int r;
const u64 *S = T7;
u64 K2, K1;
@@ -769,8 +769,9 @@ static int khazad_setkey(void *ctx_arg,
return -EINVAL;
}
- K2 = be64_to_cpu(key[0]);
- K1 = be64_to_cpu(key[1]);
+ /* key is supposed to be 32-bit aligned */
+ K2 = ((u64)be32_to_cpu(key[0]) << 32) | be32_to_cpu(key[1]);
+ K1 = ((u64)be32_to_cpu(key[2]) << 32) | be32_to_cpu(key[3]);
/* setup the encrypt key */
for (r = 0; r <= KHAZAD_ROUNDS; r++) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: fix unaligned access in khazad module
2006-04-04 7:55 ` Atsushi Nemoto
@ 2006-04-05 17:29 ` Herbert Xu
0 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2006-04-05 17:29 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-kernel, linux-crypto, akpm
On Tue, Apr 04, 2006 at 04:55:52PM +0900, Atsushi Nemoto wrote:
>
> On 64-bit platform, reading 64-bit keys (which is supposed to be
> 32-bit aligned) at a time will result in unaligned access.
Patch applied. Thanks a lot.
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-04-05 17:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-09 3:26 [PATCH] crypto: fix unaligned access in khazad module Atsushi Nemoto
2006-03-09 22:10 ` Herbert Xu
2006-04-03 15:05 ` Atsushi Nemoto
2006-04-03 23:11 ` Herbert Xu
2006-04-04 7:55 ` Atsushi Nemoto
2006-04-05 17:29 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®