Tk Library Source Code

View Ticket
Login
Ticket UUID: 446997
Title: sha1 fails on 64-bit platform
Type: Bug Version: None
Submitter: dgp Created on: 2001-08-02 00:18:06
Subsystem: sha1 Assigned To: dgp
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2002-02-21 07:16:26
Resolution: Fixed Closed By: dgp
    Closed on: 2002-02-21 00:16:26
Description:
% package require sha1
1.0
% sha1::sha1 abc     
integer value too large to represent as non-long
integer
% set errorInfo
integer value too large to represent as non-long
integer
    while executing
"format %0.8x%0.8x%0.8x%0.8x%0.8x $H0 $H1 $H2 $H3 $H4"
    (procedure "sha1::sha1" line 112)
    invoked from within
"sha1::sha1 abc"
User Comments: dgp added on 2002-02-21 07:16:26:
Logged In: YES 
user_id=80530

committed.

dgp added on 2002-02-21 07:10:52:

File Added - 18170: 64.patch

Logged In: YES 
user_id=80530

Yes, 32-bit register arithmetic assumption was the
culprit.  Here's a patch that fixes things.

dgp added on 2002-02-21 06:50:55:
Logged In: YES 
user_id=80530

hmmm... I guess those look the same don't they?
^$#*&#$& ./config.site file!

OK, *Here*'s the real test failures:

==== sha1-2.1 sha1 FAILED
==== Contents of test case:

        ::sha1::sha1 $msg
    
---- Result was:
d5b4f54ca9993e36e86031f24706816aa1834873ba3e2571281e6df67850c26c98fdf6ae9cd0d89d
---- Result should have been (exact matching):
a9993e364706816aba3e25717850c26c9cd0d89d
==== sha1-2.1 FAILED


==== sha1-2.2 sha1 FAILED
==== Contents of test case:

        ::sha1::sha1 $msg
    
---- Result was:
a6b14ada84983e449153c7871c3bd26ee1f36da4baae4aa1e91ed56ff95129e561738f02e54670f1
---- Result should have been (exact matching):
84983e441c3bd26ebaae4aa1f95129e5e54670f1
==== sha1-2.2 FAILED


==== sha1-3.1 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
dd0aac2fe7ad10bdc4ddbc4482b71c3c6f12b75887cd945543829e3113b4f2a6e2f1ad0526c48ef3
---- Result should have been (exact matching):
fbdb1d1b18aa6c08324b7d64b71fb76370690e1d
==== sha1-3.1 FAILED


==== sha1-3.2 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
5a17b268d0e2fa7f2dac78a9561a86c0bf542b56d80f08539e0dc83f2e401cb464e53e7768b82066
---- Result should have been (exact matching):
4c883e9bc42763641bba04185d492de00de7ce2c
==== sha1-3.2 FAILED


==== sha1-3.3 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ea0fbc027c29d69390261ca758438a1c2f8ed3364849b033fa9a35cdcacc8a423c2dec038000cdf2
---- Result should have been (exact matching):
a905e79f51faa446cb5a3888b577e34577ef7fce
==== sha1-3.3 FAILED


==== sha1-3.4 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
cc3ff427d2fbf753a1628cb921ab822b6b6bd9e34426b6e0f56f5309c5a1a77fab50fb292f23dd17
---- Result should have been (exact matching):
369e2959eb49450338b212748f77d8ded74847bb
==== sha1-3.4 FAILED


==== sha1-3.5 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
1d2da43db1f9a7df97a8aba8f0bb6ccd9559b9da2e1496d7f77aa4e787acf95c47d5421a8ba82409
---- Result should have been (exact matching):
2660aeeccf432596e56f8f8260de971322e8935b
==== sha1-3.5 FAILED


==== sha1-3.6 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
94a6b3c391128572ab943424d5c29d4ca1b9844afa746148dfc1bd81e2e704ddba1093e1f73eb2c
---- Result should have been (exact matching):
170523fd610da92dd4b4fb948a01a8365d66511a
==== sha1-3.6 FAILED


==== sha1-3.7 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
6622b6be347a00eca598a3ba0ed2e4dd5e865a18b7413715b88aac85bbaff3d587886185c4b6807
---- Result should have been (exact matching):
5154473317173f66212fc59365233ffd9cbaab94
==== sha1-3.7 FAILED


==== sha1-3.8 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
f10225d437a408968c2974b33bc2592c9b3b22a533f5ffa2f8defaa449114f19e7a418edab76fadc
---- Result should have been (exact matching):
9e08393f6ac829c4385930ea38567dad582d958f
==== sha1-3.8 FAILED


==== sha1-3.9 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
45e5a8199154232cdacc219d0f5bdf14929d2b0e1e4afad1a0ee7246a413b9965a408dca976eacb
---- Result should have been (exact matching):
6541c34492618a052c12cb9f88fb795d97595b34
==== sha1-3.9 FAILED

dgp added on 2002-02-21 06:30:37:
Logged In: YES 
user_id=80530

Those test failures were based on a broken Tcl
(see Tcl Bug 52690).

Here's the real failures:
sha1 1.0.2 (pure Tcl)

==== sha1-2.1 sha1 FAILED
==== Contents of test case:

        ::sha1::sha1 $msg
    
---- Result was:
ffffffffa9993e364706816affffffffba3e25717850c26cffffffff9cd0d89d
---- Result should have been (exact matching):
a9993e364706816aba3e25717850c26c9cd0d89d
==== sha1-2.1 FAILED


==== sha1-2.2 sha1 FAILED
==== Contents of test case:

        ::sha1::sha1 $msg
    
---- Result was:
ffffffff84983e441c3bd26effffffffbaae4aa1fffffffff95129e5ffffffffe54670f1
---- Result should have been (exact matching):
84983e441c3bd26ebaae4aa1f95129e5e54670f1
==== sha1-2.2 FAILED


==== sha1-3.1 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
fffffffffc0044907cf645a436be66354b3dcb7efffffffff9303abb
---- Result should have been (exact matching):
fbdb1d1b18aa6c08324b7d64b71fb76370690e1d
==== sha1-3.1 FAILED


==== sha1-3.2 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
fffffffff74c1c66ffffffffb6e5089bffffffffc85144c242d5b6a869e4efd1
---- Result should have been (exact matching):
4c883e9bc42763641bba04185d492de00de7ce2c
==== sha1-3.2 FAILED


==== sha1-3.3 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff8754ab89ffffffff8e5c5bad7875ccf6ffffffff9177cc85fffffffff3dc8d68
---- Result should have been (exact matching):
a905e79f51faa446cb5a3888b577e34577ef7fce
==== sha1-3.3 FAILED


==== sha1-3.4 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff9d4ac438ffffffffac6a9629ffffffff90d9d10dffffffffed60d04cffffffff88184cce
---- Result should have been (exact matching):
369e2959eb49450338b212748f77d8ded74847bb
==== sha1-3.4 FAILED


==== sha1-3.5 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
7769bcdaffffffffe977b8731c8be7f3ffffffffd370300e4ba6b57b
---- Result should have been (exact matching):
2660aeeccf432596e56f8f8260de971322e8935b
==== sha1-3.5 FAILED


==== sha1-3.6 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff8fb2eba3ffffffff945e91a8ffffffffb21478523535a8aa16695b74
---- Result should have been (exact matching):
170523fd610da92dd4b4fb948a01a8365d66511a
==== sha1-3.6 FAILED


==== sha1-3.7 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffffad0202a8ffffffffe9c108f713620267fffffffff0e38586ffffffff80c745b7
---- Result should have been (exact matching):
5154473317173f66212fc59365233ffd9cbaab94
==== sha1-3.7 FAILED


==== sha1-3.8 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
fffffffff82a5587fffffffff3abe5b8fffffffff0b4c383ffffffff988fd352ffffffffbbfc4493
---- Result should have been (exact matching):
9e08393f6ac829c4385930ea38567dad582d958f
==== sha1-3.8 FAILED


==== sha1-3.9 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff92f662d9ffffffff923dfeb63636ae4fffffffff85226fa66b9cd7ce
---- Result should have been (exact matching):
6541c34492618a052c12cb9f88fb795d97595b34
==== sha1-3.9 FAILED

Note the underlying problem appears to be that the
sha1 package assumes all arithmetic is modulo-2^32.

dgp added on 2002-02-21 01:54:22:
Logged In: YES 
user_id=80530

To be precise, I see these test failures
on Linux/Alpha:

sha1 1.0.2 (pure Tcl)

==== sha1-2.1 sha1 FAILED
==== Contents of test case:

        ::sha1::sha1 $msg
    
---- Result was:
ffffffffa9993e364706816affffffffba3e25717850c26cffffffff9cd0d89d
---- Result should have been (exact matching):
a9993e364706816aba3e25717850c26c9cd0d89d
==== sha1-2.1 FAILED


==== sha1-2.2 sha1 FAILED
==== Contents of test case:

        ::sha1::sha1 $msg
    
---- Result was:
ffffffff84983e441c3bd26effffffffbaae4aa1fffffffff95129e5ffffffffe54670f1
---- Result should have been (exact matching):
84983e441c3bd26ebaae4aa1f95129e5e54670f1
==== sha1-2.2 FAILED


==== sha1-3.1 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
fffffffffc0044907cf645a436be66354b3dcb7efffffffff9303abb
---- Result should have been (exact matching):
fbdb1d1b18aa6c08324b7d64b71fb76370690e1d
==== sha1-3.1 FAILED


==== sha1-3.2 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
fffffffff74c1c66ffffffffb6e5089bffffffffc85144c242d5b6a869e4efd1
---- Result should have been (exact matching):
4c883e9bc42763641bba04185d492de00de7ce2c
==== sha1-3.2 FAILED


==== sha1-3.3 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff8754ab89ffffffff8e5c5bad7875ccf6ffffffff9177cc85fffffffff3dc8d68
---- Result should have been (exact matching):
a905e79f51faa446cb5a3888b577e34577ef7fce
==== sha1-3.3 FAILED


==== sha1-3.4 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff9d4ac438ffffffffac6a9629ffffffff90d9d10dffffffffed60d04cffffffff88184cce
---- Result should have been (exact matching):
369e2959eb49450338b212748f77d8ded74847bb
==== sha1-3.4 FAILED


==== sha1-3.5 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
7769bcdaffffffffe977b8731c8be7f3ffffffffd370300e4ba6b57b
---- Result should have been (exact matching):
2660aeeccf432596e56f8f8260de971322e8935b
==== sha1-3.5 FAILED


==== sha1-3.6 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff8fb2eba3ffffffff945e91a8ffffffffb21478523535a8aa16695b74
---- Result should have been (exact matching):
170523fd610da92dd4b4fb948a01a8365d66511a
==== sha1-3.6 FAILED


==== sha1-3.7 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffffad0202a8ffffffffe9c108f713620267fffffffff0e38586ffffffff80c745b7
---- Result should have been (exact matching):
5154473317173f66212fc59365233ffd9cbaab94
==== sha1-3.7 FAILED


==== sha1-3.8 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
fffffffff82a5587fffffffff3abe5b8fffffffff0b4c383ffffffff988fd352ffffffffbbfc4493
---- Result should have been (exact matching):
9e08393f6ac829c4385930ea38567dad582d958f
==== sha1-3.8 FAILED


==== sha1-3.9 hmac FAILED
==== Contents of test case:

        ::sha1::hmac $key $text
    
---- Result was:
ffffffff92f662d9ffffffff923dfeb63636ae4fffffffff85226fa66b9cd7ce
---- Result should have been (exact matching):
6541c34492618a052c12cb9f88fb795d97595b34
==== sha1-3.9 FAILED

dgp added on 2002-02-21 01:33:22:
Logged In: YES 
user_id=80530

This patch restores correct operation on 32-bit
platforms.  Still broken on 64-bit.

dkf added on 2002-02-20 16:54:13:
Logged In: YES 
user_id=79902

Bother! Can't attach a patch here!  Pasting instead (email
me if you want an unmangled version):

Index: modules/sha1/ChangeLog
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/sha1/ChangeLog,v
retrieving revision 1.5
diff -u -r1.5 ChangeLog
--- modules/sha1/ChangeLog      8 Feb 2002 06:05:20
-0000       1.5
+++ modules/sha1/ChangeLog      20 Feb 2002 09:51:56 -0000
@@ -1,3 +1,8 @@
+2002-02-20  Donal K. Fellows  <[email protected]>
+
+       * sha1.tcl (initK,sha1): Force 32-bit interpretation
of constants
+       larger than INT_MAX on 32-bit processors, due to
TIP#72.
+
 2002-02-07  Andreas Kupries 
<[email protected]>
 
        * Version up to 1.0.2 to differentiate development
from the
Index: modules/sha1/sha1.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/sha1/sha1.tcl,v
retrieving revision 1.5
diff -u -r1.5 sha1.tcl
--- modules/sha1/sha1.tcl       8 Feb 2002 06:05:20
-0000       1.5
+++ modules/sha1/sha1.tcl       20 Feb 2002 09:51:57 -0000
@@ -97,7 +97,7 @@
                0xCA62C1D6
            } {
                for {set i 0} {$i < 20} {incr i} {
-                   lappend K $t
+                   lappend K [expr {int($t)}]
                }
            }
        }
@@ -180,11 +180,11 @@
 
        # initial H buffer
 
-       set H0 0x67452301
-       set H1 0xEFCDAB89
-       set H2 0x98BADCFE
-       set H3 0x10325476
-       set H4 0xC3D2E1F0
+       set H0 [expr {int(0x67452301)}]
+       set H1 [expr {int(0xEFCDAB89)}]
+       set H2 [expr {int(0x98BADCFE)}]
+       set H3 [expr {int(0x10325476)}]
+       set H4 [expr {int(0xC3D2E1F0)}]
 
        #
        # process message in 16-word blocks (64-byte blocks)

dgp added on 2002-02-20 05:25:11:
Logged In: YES 
user_id=80530

After TIP 72, this bug (or something similar) 
appears on all platforms.  Try the test suite.

dgp added on 2001-09-20 23:42:40:

File Added - 11019: sha1.test

Logged In: YES 
user_id=80530

Now that Tcl Bug 219223 has been fixed in Tcl 8.4a4
and Tcl 8.3.4, the errors in the sha1 package on
64-bit platforms can be clarified.  Attached is the
output of the sha1 test suite on a 64-bit platform.

dkf added on 2001-08-21 15:57:03:
Logged In: YES 
user_id=79902

The problem is that [format] (and [binary format] too) use
Tcl_GetIntFromObj when they would actually be better off
using Tcl_GetLongFromObj. Unfortunately, the Tcl core is not
that clean about the difference between these two, and most
developers do not have a platform which differentiates
between them (making it a bit tricky to develop fixes.)  :^(

andreas_kupries added on 2001-08-03 01:13:30:
Logged In: YES 
user_id=75003

Should consult Don Libes and Donal K. Fellows here.

Attachments: