Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #17651

Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth

Newsgroups comp.lang.forth
Date 2012-11-28 14:31 -0800
References <e1b992f7-65c4-4115-9f80-10fb671d3763@googlegroups.com> <50b4c134.156405635@192.168.0.50>
Message-ID <7a6a5bbd-eb18-4618-a868-5d152fad0c4f@googlegroups.com> (permalink)
Subject Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth
From Howerd <howerdo@yahoo.co.uk>

Show all headers | View raw


On Tuesday, November 27, 2012 2:40:03 PM UTC+1, Stephen Pelc wrote:
> On Tue, 20 Nov 2012 22:32:48 -0800 (PST), Howerd <howxxxx@yahoo.co.uk>
> 
> wrote:

> >I have just posted a version of the SHA-256 algorithm, complete with a test suite.

> 
> When looking at this code I came across the start of a word
> 
> called ROUNDN which (of course) contains no comments.
> 
> : RoundN  ( a -- u u )
> 
>    HashPtr @ >r
> 
>    15 PICK  15 PICK
> 
>    ...
> 
> ;
> 
> 
> I urge the author of that word to rewrite and comment the code.
> 
> Experienced Forth programmers should not be promoting code of this
> 
> ilk.
>  
> Stephen
> 
> -- 
> 
> Stephen Pelc, stephenXXX@mpeforth.com
> 
> MicroProcessor Engineering Ltd - More Real, Less Time
> 
> 133 Hill Lane, Southampton SO15 5AF, England
> 
> tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
> 
> web: http://www.mpeforth.com - free VFX Forth downloads

Hi Stephen,

> : RoundN  ( a -- u u ) 
>    HashPtr @ >r
>    15 PICK  15 PICK
>    ...
> ;
> I urge the author of that word to rewrite and comment the code.
Yes - I have never knowingly used PICK or ROLL in any original code.
The SHA-256 algorithm sources use this type of offset into a stack to mix in earlier data. I would love to avoid PICK, but life is too short rewrite this!

Just when you thought it couldn't get any better :

I removed the macros ( from Wil Baden's Toolkit ) from the original code by Jabari Zakiya to make it easier to understand the code, and to speed it up. Also because I hate macros more than PICK ( but maybe less than ROLL ;-)

As expected the macro version is slower in high-level SwiftForth - 1499 ms compared to 1237 ms.
But the macro version is *faster* on VFX Forth - 889ms compared to 998ms. 
So I could have saved myself the trouble and let VFX do all of the optimising...

And yes, for this algorithm, the "spot assembler" assumption fails - there is no particular "spot" that only needs to be assembled.

> Experienced Forth programmers should not be promoting code of this ilk.
SHA-256 is an ugly algorithm, compared say to TEA, and the available code in both C and Forth follows suit. Perhaps a warning would suffice : "PICK and ROLL can seriously damage your coding style" or a MISRA style explanation of why it is neccessary in this case.

BTW The great FFL from Dick van Oudheusden contains an implementation of SHA-256, but it is not picked up by Google because the source files are zipped - maybe providing unzipped HTML files would make them easier to find...

Modifying and optimising an already working program is much easier than coding from the spec, or converting from C - so thanks again to Jabari and Dirk :-)

And optimising by hand seems to be largely a waste of time now too...

Best regards,
Howerd


Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-11-20 22:32 -0800
  Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth stephenXXX@mpeforth.com (Stephen Pelc) - 2012-11-22 22:53 +0000
    Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth ritaoakford@gmail.com - 2012-11-23 00:21 -0800
    Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2012-11-23 14:20 +0000
    Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2012-11-25 22:58 +0200
      Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-11-25 14:41 -0800
        Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2012-11-26 00:59 +0200
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-11-25 16:10 -0800
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-11-26 04:18 -0800
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-11-26 19:17 +0100
      Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth stephenXXX@mpeforth.com (Stephen Pelc) - 2012-11-26 11:57 +0000
        Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-11-26 06:17 -0600
        Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2012-11-26 23:22 +0200
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth stephenXXX@mpeforth.com (Stephen Pelc) - 2012-11-27 13:33 +0000
        Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Fritz Wuehler <fritz@spamexpire-201211.rodent.frell.theremailer.net> - 2012-11-27 09:18 +0100
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Mark Wills <forthfreak@gmail.com> - 2012-11-27 01:08 -0800
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth stephenXXX@mpeforth.com (Stephen Pelc) - 2012-11-27 11:18 +0000
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2012-11-27 16:32 +0000
            Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Fritz Wuehler <fritz@spamexpire-201211.rodent.frell.theremailer.net> - 2012-11-28 11:59 +0100
              Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2012-11-28 14:11 +0000
  Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth albert@spenarnc.xs4all.nl (Albert van der Horst) - 2012-11-26 16:50 +0000
  Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth stephenXXX@mpeforth.com (Stephen Pelc) - 2012-11-27 13:36 +0000
    Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-11-28 14:31 -0800
      Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-11-28 14:36 -0800
      Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Josh Grams <josh@qualdan.com> - 2012-11-30 00:08 +0000
        Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-11-30 13:56 -0800
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Josh Grams <josh@qualdan.com> - 2012-12-01 16:02 +0000
            Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-12-01 13:54 -0800
              Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Josh Grams <josh@qualdan.com> - 2012-12-02 11:26 +0000
      Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-12 14:52 -0800
        Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-12-12 23:47 -0800
          Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-13 00:38 -0800
            Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-12-13 20:17 -0800
              Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-13 20:25 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-12-13 20:53 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-13 21:16 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-12-14 03:43 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-12-14 12:15 -0600
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-20 00:21 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-12-14 04:45 -0600
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Howerd <howerdo@yahoo.co.uk> - 2012-12-14 03:33 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-12-14 12:20 -0600
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-14 10:28 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-12-14 12:39 -0600
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-12-15 01:47 +0100
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-19 18:10 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-19 19:53 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-12-20 14:44 +0100
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-12-20 19:28 +0100
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Paul Rubin <no.email@nospam.invalid> - 2012-12-20 13:56 -0800
                Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2012-12-21 01:41 +0100
  Re: ANN: SHA-256 Secure Hash Algorithm in ANS Forth jzakiya@gmail.com - 2012-12-07 14:27 -0800

csiph-web