Try the attached patch to the sha1.c file and see if that takes care of
the problem.

--Mike


On Thu, 2004-05-27 at 20:31, Dinko Korunic wrote:
> On Fri, May 28, 2004 at 02:34:48AM +0200, Dinko Korunic wrote:
> > As we can see, initial challenge calculation has gone wrong somewhere.. which
> > is happening in challenge_hash(), function whish is strictly using OpenSSL SHA1
> > functions. Doh. I thought at least OpenSSL should be endian-clean..
> 
> To prove my wording, here is some more of debug info. Already first SHA1 hash
> is different. However, I'm not sure if challenge-grabbing (20 octets) from end
> SHA1-hash is wrong, or SHA1 is wrong.. Could anyone help?
> 
> Unsuccessful:
> CHAPDBG, challenge_hash: username aland
> CHAPDBG, challenge_hash: peer_challenge 202122232425262728292A2B2C2D2E2F
> CHAPDBG, challenge_hash: auth_challenge 303132333435363738393A3B3C3D3E3F
> CHAPDBG, challenge_hash: sha1-1 41D03A478398AF4E7B18306592E77B8C8F99E76B
> CHAPDBG, challenge_hash: sha1-2 88E8358965B10060C8BEEC85FA03A49E75CC0AAD
> CHAPDBG, challenge_hash: sha1-3 E234830DFF297968936E5BA5A6022D31B32B2AE2
> CHAPDBG, challenge_hash: end hash 389A5773F16E40A37FFB45A5DAEC13829A709102
> CHAPDBG: challenge 389A5773F16E40A3
> CHAPDBG: calculated 0CCC41AB13690C2C83BA7D143C12D758D34762A2194D663F
> CHAPDBG: response 6649E30199C56F7B1413EBA10A19D963D03165C1AEA0EBBF
>   rlm_mschap: FAILED: MS-CHAP2-Response is incorrect
> 
> Successful:
> CHAPDBG, challenge_hash: username aland
> CHAPDBG, challenge_hash: peer_challenge 202122232425262728292A2B2C2D2E2F
> CHAPDBG, challenge_hash: auth_challenge 303132333435363738393A3B3C3D3E3F
> CHAPDBG, challenge_hash: sha1-1 5C3F75DDA77EB61EF6D04B5045BDF661F4FA608C
> CHAPDBG, challenge_hash: sha1-2 9502711A5B6468A0400D095480515D9610F327AC
> CHAPDBG, challenge_hash: sha1-3 CC8E988B421E3260801E39F23C3CAA402C02F2B8
> CHAPDBG, challenge_hash: end hash CC8E988B421E3260801E39F23C3CAA402C02F2B8
> CHAPDBG: challenge CC8E988B421E3260
> CHAPDBG: calculated 6649E30199C56F7B1413EBA10A19D963D03165C1AEA0EBBF
> CHAPDBG: response 6649E30199C56F7B1413EBA10A19D963D03165C1AEA0EBBF
> rlm_mschap: adding MS-CHAPv2 MPPE keys
--- sha1.c.save 2004-05-27 21:26:12.000000000 -0500
+++ sha1.c      2004-05-27 21:34:01.000000000 -0500
@@ -9,6 +9,7 @@
 #include "autoconf.h"
 
 #include <string.h>
+#include <endian.h>
 
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
@@ -24,14 +25,19 @@
 
 #include "sha1.h"
 
-#define blk0(i) (block->l[i] = htonl(block->l[i]))
 
 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
 
 /* blk0() and blk() perform the initial expand. */
 /* I got the idea of expanding during the round function from SSLeay */
 
-#define blk0(i) (block->l[i] = htonl(block->l[i]))
+# if __BYTE_ORDER == __BIG_ENDIAN
+#  define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
+     |(rol(block->l[i],8)&0x00FF00FF))
+# else /* __BYTE_ORDER == __LITTLE_ENDIAN */
+#  define blk0(i) block->l[i]
+# endif
+
 
 #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
     ^block->l[(i+2)&15]^block->l[i&15],1))

Reply via email to