teatotal: "Read error" building for iPAQ running Linux


Previous by date: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Alex Holden
Next by date: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Jay Sekora
Previous in thread: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Alex Holden
Next in thread: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Jay Sekora

Subject: Re: "Read error" building for iPAQ running Linux
From: Alex Holden ####@####.####
Date: 18 Nov 2001 11:17:51 -0000
Message-Id: <Pine.LNX.4.33.0111181107350.763-100000@hyperspace.linuxhacker.org>

On Sun, 18 Nov 2001, Alex Holden wrote:
> Hi Jay, sorry for taking so long to get back to you. I've run Tea Total on
> my NetWinder before, so it ought to work okay on ARM Linux.

Oops, I just tried it on my NetWinder again and it seems that the reason
it worked before was that the kernel I was using then had the user mode
alignment trap handler. Newer kernels don't have it, and there was an
alignment bug in Tea Total 0.4. Does the following patch fix your
problems?

diff -urN tea-total-0.4/config.inc tea-total-0.4a/config.inc
--- tea-total-0.4/config.inc	Tue Jan  2 13:09:08 2001
+++ tea-total-0.4a/config.inc	Sun Nov 18 11:04:41 2001
@@ -38,7 +38,7 @@
 # platforms).
 DEBUGGING = N

-# Set to Y to build with -pedantic turned on (may not work on all platorms).
+# Set to Y to build with -pedantic turned on (may not work on all platforms).
 PEDANTIC = N

 # Set to Y to link statically (may not work on all platforms).
diff -urN tea-total-0.4/getarg.c tea-total-0.4a/getarg.c
--- tea-total-0.4/getarg.c	Mon Jan  1 19:18:54 2001
+++ tea-total-0.4a/getarg.c	Sun Nov 18 11:06:56 2001
@@ -110,7 +110,7 @@

 	/* Copy the arguments, ignoring the first argument (the program name) */
 	for(i = 1; i < argc; i++) {
-		len = strlen(argv[i]);
+		len = strlen(argv[i]) + 1;
 		if(!(state->argv[i - 1] = malloc(len))) {
 			/* It failed, so free the list and return */
 			while(i-- > 1) free(state->argv[i]);
diff -urN tea-total-0.4/md5.c tea-total-0.4a/md5.c
--- tea-total-0.4/md5.c	Sun Dec 24 20:29:54 2000
+++ tea-total-0.4a/md5.c	Sun Nov 18 11:01:59 2001
@@ -16,6 +16,8 @@
  *
  */

+#include <string.h>
+
 #include "arch.h"
 #include "md5.h"

diff -urN tea-total-0.4/tea-kgen.c tea-total-0.4a/tea-kgen.c
--- tea-total-0.4/tea-kgen.c	Mon Jan  1 19:19:17 2001
+++ tea-total-0.4a/tea-kgen.c	Sun Nov 18 11:01:48 2001
@@ -9,6 +9,7 @@
  * tea-kgen.c: The tea-kgen applet.
  */

+#include <string.h>
 #include <unistd.h>

 #include "teatotal.h"
diff -urN tea-total-0.4/teaprot.c tea-total-0.4a/teaprot.c
--- tea-total-0.4/teaprot.c	Mon Jan  1 22:50:45 2001
+++ tea-total-0.4a/teaprot.c	Sun Nov 18 11:00:51 2001
@@ -146,6 +146,7 @@
  */
 int encode_block(teastate *state)
 {
+	u8 *p;
 	int i, block_len, clen;

 	/* Copy the TEA header into the packet */
@@ -181,6 +182,16 @@

 	/* encrypt the data */
 	btea(&state->pkt->seq, state->k, block_len / 4, 0, 0);
+
+	/*
+	 * The seq field is aligned because the tea encoder requires that, but
+	 * that does mean that on some architectures there will be a byte (or more)
+	 * of packing between the header and the encoded data which we don't want
+	 * in the final encoded data block. So if necessary, shuffle the data
+	 * down to get rid of any packing.
+	 */
+	p = (u8 *)&state->pkt->datalen + 2;
+	if((u8 *)&state->pkt->seq > p) memmove(p, &state->pkt->seq, block_len);

 	/* The entire packet includes both the encrypted data and the header */
 	block_len += HEADER_LEN + 4;
diff -urN tea-total-0.4/teatotal.h tea-total-0.4a/teatotal.h
--- tea-total-0.4/teatotal.h	Mon Jan  1 20:44:42 2001
+++ tea-total-0.4a/teatotal.h	Sun Nov 18 10:59:51 2001
@@ -30,15 +30,19 @@
 #include "base64.h"
 #endif

-/* The packed attributes are needed to prevent gcc from aligning the structure
- * elements on certain architectures */
+/*
+ * The packed attributes are needed to prevent gcc from aligning the structure
+ * elements on certain architectures. The seq field is intentionally not packed
+ * because the tea encoder/decoder needs its data block to be aligned on some
+ * architectures.
+ */
 typedef struct {
 	u8 hdr[3] __attribute__ ((packed));	/* "TEA" */
 	u8 encoding __attribute__ ((packed));	/* Encoding type */
 	u8 byte_order __attribute__ ((packed));	/* Byte order */
 	u16 datalen __attribute__ ((packed));	/* Length of encoded data */
-	u32 seq __attribute__ ((packed));	/* Encoded sequence number */
-	u32 data[MAXPKTLEN] __attribute__ ((packed));	/* Encoded data */
+	u32 seq;				/* Encoded sequence number */
+	u32 data[MAXPKTLEN] __attribute__ ((packed)); /* Encoded data */
 } teapacket;

 typedef struct {
diff -urN tea-total-0.4/util.c tea-total-0.4a/util.c
--- tea-total-0.4/util.c	Tue Jan  2 09:01:18 2001
+++ tea-total-0.4a/util.c	Sun Nov 18 11:02:12 2001
@@ -13,6 +13,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 #include <sys/time.h>
 #include <termios.h>

-- 
------- Alex Holden -------
http://www.linuxhacker.org/
 http://www.robogeeks.org/


Previous by date: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Alex Holden
Next by date: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Jay Sekora
Previous in thread: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Alex Holden
Next in thread: 18 Nov 2001 11:17:51 -0000 Re: "Read error" building for iPAQ running Linux, Jay Sekora


Powered by ezmlm-browse 0.20.