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


Groups > comp.lang.forth > #18838 > unrolled thread

ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth

Started byjzakiya@gmail.com
First post2013-01-15 21:31 -0800
Last post2013-01-16 23:29 +0100
Articles 20 on this page of 26 — 5 participants

Back to article view | Back to comp.lang.forth


Contents

  ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-15 21:31 -0800
    Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-15 21:57 -0800
      Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-26 10:01 -0800
    Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-16 15:25 +0100
      Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-16 09:45 -0800
        Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-16 19:08 +0100
          Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-16 10:32 -0800
            Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-16 23:33 +0100
              Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Alex McDonald <blog@rivadpm.com> - 2013-01-16 14:53 -0800
                Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-16 20:40 -0800
                  Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2013-01-17 22:36 +0200
                    Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-17 22:24 -0800
                      Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-17 22:46 -0800
                      Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2013-01-19 09:14 +0200
                        Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Alex McDonald <blog@rivadpm.com> - 2013-01-19 08:24 -0800
                          Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth jzakiya@gmail.com - 2013-01-19 18:10 -0800
                          Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2013-01-20 08:56 +0200
                            Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-20 14:38 +0100
                              Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2013-01-20 16:25 +0200
                            Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Alex McDonald <blog@rivadpm.com> - 2013-01-20 11:44 -0800
                            Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-21 17:22 +0000
                              Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2013-01-21 22:51 +0200
                                Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-22 17:26 +0000
          Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-18 16:50 +0000
      Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth mhx@iae.nl (Marcel Hendrix) - 2013-01-16 19:53 +0200
        Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth Bernd Paysan <bernd.paysan@gmx.de> - 2013-01-16 23:29 +0100

Page 1 of 2  [1] 2  Next page →


#18838 — ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth

Fromjzakiya@gmail.com
Date2013-01-15 21:31 -0800
SubjectANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth
Message-ID<f1326980-fc6b-40ad-a767-84d17d55cf5b@googlegroups.com>
I have updated/improved/implemented all the
Secure Hash Algorithms listed in FIPS PUB 180-4

http://csrc.nist.gov/publications/PubsFIPS.html

The algorithms are:

SHA.1.F  for  SHA-1 for 32-bit systems

SHA-256||224.F for both SHA-224 and SHA-256 for 32-bit systems.

SHA-384||512xxx.F for SHA-384, SHA-512, SHA-512/224, and SHA-512/256 for 64-bit systems.

All files are downloadable from my 4shared.com repository here:

https://www.4shared.com/folder/4o-httdZ/Forth.html

or from here:      https://gist.github.com/jzakiya

or individually:

SHA-1.F             https://gist.github.com/4544426

SHA-256||224.F      https://gist.github.com/4544459
 
SHA-384||512xxx.F   https://gist.github.com/4544478


I will implement the new SHA-3 after a NIST FIPS PUB
specifying its official implementation is released.


Jabari Zakiya

[toc] | [next] | [standalone]


#18839

Fromjzakiya@gmail.com
Date2013-01-15 21:57 -0800
Message-ID<339acf82-7e1c-4228-94f9-f41413a48be1@googlegroups.com>
In reply to#18838
On Wednesday, January 16, 2013 12:31:49 AM UTC-5, jza...@gmail.com wrote:
> I have updated/improved/implemented all the
> 
> Secure Hash Algorithms listed in FIPS PUB 180-4
> 
> 
> 
> http://csrc.nist.gov/publications/PubsFIPS.html
> 
> 
> 
> The algorithms are:
> 
> 
> 
> SHA.1.F  for  SHA-1 for 32-bit systems
> 
> 
> 
> SHA-256||224.F for both SHA-224 and SHA-256 for 32-bit systems.
> 
> 
> 
> SHA-384||512xxx.F for SHA-384, SHA-512, SHA-512/224, and SHA-512/256 for 64-bit systems.
> 
> 
> 
> All files are downloadable from my 4shared.com repository here:
> 
> 
> 
> https://www.4shared.com/folder/4o-httdZ/Forth.html
> 
> 
> 
> or from here:      https://gist.github.com/jzakiya
> 
> 
> 
> or individually:
> 
> 
> 
> SHA-1.F             https://gist.github.com/4544426
> 
> 
> 
> SHA-256||224.F      https://gist.github.com/4544459
> 
>  
> 
> SHA-384||512xxx.F   https://gist.github.com/4544478
> 
> 
> 
> 
> 
> I will implement the new SHA-3 after a NIST FIPS PUB
> 
> specifying its official implementation is released.
> 
> 
> 
> 
> 
> Jabari Zakiya

Corrections

Changed file names to act nice with different Forths:

SHA-256||224.F      changed to SHA-256_224.F
SHA-384||512.xxx.F  changed to SHA-384_512xxx.F

jz

[toc] | [prev] | [next] | [standalone]


#19172

Fromjzakiya@gmail.com
Date2013-01-26 10:01 -0800
Message-ID<5cb7121c-7501-4696-9b6f-48965e76df7c@googlegroups.com>
In reply to#18839
On Wednesday, January 16, 2013 12:57:27 AM UTC-5, jza...@gmail.com wrote:
> On Wednesday, January 16, 2013 12:31:49 AM UTC-5, jza...@gmail.com wrote:
> 
> > I have updated/improved/implemented all the
> 
> > 
> 
> > Secure Hash Algorithms listed in FIPS PUB 180-4
> 
> > 
> 
> > 
> 
> > 
> 
> > http://csrc.nist.gov/publications/PubsFIPS.html
> 
> > 
> 
> > 
> 
> > 
> 
> > The algorithms are:
> 
> > 
> 
> > 
> 
> > 
> 
> > SHA.1.F  for  SHA-1 for 32-bit systems
> 
> > 
> 
> > 
> 
> > 
> 
> > SHA-256||224.F for both SHA-224 and SHA-256 for 32-bit systems.
> 
> > 
> 
> > 
> 
> > 
> 
> > SHA-384||512xxx.F for SHA-384, SHA-512, SHA-512/224, and SHA-512/256 for 64-bit systems.
> 
> > 
> 
> > 
> 
> > 
> 
> > All files are downloadable from my 4shared.com repository here:
> 
> > 
> 
> > 
> 
> > 
> 
> > https://www.4shared.com/folder/4o-httdZ/Forth.html
> 
> > 
> 
> > 
> 
> > 
> 
> > or from here:      https://gist.github.com/jzakiya
> 
> > 
> 
> > 
> 
> > 
> 
> > or individually:
> 
> > 
> 
> > 
> 
> > 
> 
> > SHA-1.F             https://gist.github.com/4544426
> 
> > 
> 
> > 
> 
> > 
> 
> > SHA-256||224.F      https://gist.github.com/4544459
> 
> > 
> 
> >  
> 
> > 
> 
> > SHA-384||512xxx.F   https://gist.github.com/4544478
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > I will implement the new SHA-3 after a NIST FIPS PUB
> 
> > 
> 
> > specifying its official implementation is released.
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > Jabari Zakiya
> 
> 
> 
> Corrections
> 
> 
> 
> Changed file names to act nice with different Forths:
> 
> 
> 
> SHA-256||224.F      changed to SHA-256_224.F
> 
> SHA-384||512.xxx.F  changed to SHA-384_512xxx.F
> 
> 
> 
> jz

I have revised SHA-384_512xxx.F as follows:

Rev 2013-1-25: Removed use of word DIGIT in ChooseHash and simplied
               Added performance timing test for iForth

Now, since I've eliminated the dependency on DIGIT, I made ChooseHash much easier to understand, and it should port across systems with no problems.
Also added Marcel's timing performance code for iForth.

Can retrieve revised code at my 4shared.com site here:

https://www.4shared.com/folder/4o-httdZ/Forth.html

or as a gist here:      https://gist.github.com/jzakiya 

are individual file here:

SHA-384||512xxx.F   https://gist.github.com/4544478

jz

[toc] | [prev] | [next] | [standalone]


#18845

FromBernd Paysan <bernd.paysan@gmx.de>
Date2013-01-16 15:25 +0100
Message-ID<113197860.yMaEY2lCMy@sunwukong.fritz.box>
In reply to#18838
jzakiya@gmail.com wrote:
> I will implement the new SHA-3 after a NIST FIPS PUB
> specifying its official implementation is released.

I don't think there's need to wait for anything.  I took "readable 
keccak" as base, and implemented keccakf for 64 bit Forths, with a small 
Gforth specific thing:

: ]L  ] postpone Literal ; immediate

\ Keccak: Forth version derived from "readable keccak" by Bernd Paysan
\ 19-Nov-11  Markku-Juhani O. Saarinen <mjos@iki.fi>
\ A baseline Keccak (3rd round) implementation.

24 Value keccak-rounds

Create keccakf-rndc
    $0000000000000001 , $0000000000008082 , $800000000000808a ,
    $8000000080008000 , $000000000000808b , $0000000080000001 ,
    $8000000080008081 , $8000000000008009 , $000000000000008a ,
    $0000000000000088 , $0000000080008009 , $000000008000000a ,
    $000000008000808b , $800000000000008b , $8000000000008089 ,
    $8000000000008003 , $8000000000008002 , $8000000000000080 , 
    $000000000000800a , $800000008000000a , $8000000080008081 ,
    $8000000000008080 , $0000000080000001 , $8000000080008008 ,

Create keccakf-rotc
1 c,  3 c,  6 c,  10 c, 15 c, 21 c, 28 c, 36 c, 45 c, 55 c, 2 c,  14 c, 
27 c, 41 c, 56 c, 8 c,  25 c, 43 c, 62 c, 18 c, 39 c, 61 c, 20 c, 44 c,

Create keccakf-piln
10 c, 7 c,  11 c, 17 c, 18 c, 3 c, 5 c,  16 c, 8 c,  21 c, 24 c, 4 c, 
15 c, 23 c, 19 c, 13 c, 12 c, 2 c, 20 c, 14 c, 22 c, 9 c,  6 c,  1 c,

\ update the state with given number of rounds

5 cells buffer: bc
25 cells buffer: st

: lrot1 ( x1 -- x2 )  dup 2* swap 0< - ;
: lrot ( x1 n -- x2 )  2dup lshift >r 64 swap - rshift r> or ;
: xor! ( x addr -- )  dup >r @ xor r> ! ;

: theta1 ( -- )
    5 0 DO
        0 st i cells + 25 cells bounds DO  I @ xor  [ 5 cells ]L +LOOP
        bc i cells + !
    LOOP ;

: theta2 ( -- )
    5 0 DO
        bc I 4 + 5 mod cells + @
        bc I 1 + 5 mod cells + @ lrot1 xor
        st i cells + 25 cells bounds DO  dup I xor!  [ 5 cells ]L +LOOP
        drop
    LOOP ;

: rhopi ( -- )
    st cell+ @
    24 0 DO
        keccakf-piln I + c@
        cells st + dup @
        rot keccakf-rotc I + c@ lrot
        rot !
    LOOP drop ;

: chi ( -- )
    st 25 cells bounds DO
        I bc 5 cells move
        5 0 DO
            bc I 1+ 5 mod cells + @ bc I 2 + 5 mod cells + @ and
            J I cells + xor!
        LOOP
    [ 5 cells ]L +LOOP ;

: iota ( round -- )
    cells keccakf-rndc + @ st @ xor st ! ;

: keccakf ( -- )
    keccak-rounds 0 ?DO  theta1  theta2  rhopi  chi  I iota  LOOP ;

: st0 ( -- )  st 25 cells erase ;

: >sponge ( addr u -- )
    \ fill in sponge function
    st swap bounds DO  dup @ I xor!  cell+  cell +LOOP  drop ;

144 buffer: kpad

: padded>sponge ( addr u1 u2 -- )  >r
    \ pad last round
    kpad r@ erase  tuck kpad swap move
    kpad + 1 swap c!
    kpad r@ + 1- dup c@ $80 or swap c!
    kpad r> >sponge  ;

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#18854

Fromjzakiya@gmail.com
Date2013-01-16 09:45 -0800
Message-ID<9d0f759d-df71-4274-ba7c-ed7be9df6f01@googlegroups.com>
In reply to#18845
On Wednesday, January 16, 2013 9:25:48 AM UTC-5, Bernd Paysan wrote:
> jzakiya@gmail.com wrote:
> 
> > I will implement the new SHA-3 after a NIST FIPS PUB
> 
> > specifying its official implementation is released.
> 
> 
> 
> I don't think there's need to wait for anything.  I took "readable 
> 
> keccak" as base, and implemented keccakf for 64 bit Forths, with a small 
> 
> Gforth specific thing:
> 
> 
> 
> : ]L  ] postpone Literal ; immediate
> 
> 
> 
> \ Keccak: Forth version derived from "readable keccak" by Bernd Paysan
> 
> \ 19-Nov-11  Markku-Juhani O. Saarinen <mjos@iki.fi>
> 
> \ A baseline Keccak (3rd round) implementation.
> 
> 
> 
> 24 Value keccak-rounds
> 
> 
> 
> Create keccakf-rndc
> 
>     $0000000000000001 , $0000000000008082 , $800000000000808a ,
> 
>     $8000000080008000 , $000000000000808b , $0000000080000001 ,
> 
>     $8000000080008081 , $8000000000008009 , $000000000000008a ,
> 
>     $0000000000000088 , $0000000080008009 , $000000008000000a ,
> 
>     $000000008000808b , $800000000000008b , $8000000000008089 ,
> 
>     $8000000000008003 , $8000000000008002 , $8000000000000080 , 
> 
>     $000000000000800a , $800000008000000a , $8000000080008081 ,
> 
>     $8000000000008080 , $0000000080000001 , $8000000080008008 ,
> 
> 
> 
> Create keccakf-rotc
> 
> 1 c,  3 c,  6 c,  10 c, 15 c, 21 c, 28 c, 36 c, 45 c, 55 c, 2 c,  14 c, 
> 
> 27 c, 41 c, 56 c, 8 c,  25 c, 43 c, 62 c, 18 c, 39 c, 61 c, 20 c, 44 c,
> 
> 
> 
> Create keccakf-piln
> 
> 10 c, 7 c,  11 c, 17 c, 18 c, 3 c, 5 c,  16 c, 8 c,  21 c, 24 c, 4 c, 
> 
> 15 c, 23 c, 19 c, 13 c, 12 c, 2 c, 20 c, 14 c, 22 c, 9 c,  6 c,  1 c,
> 
> 
> 
> \ update the state with given number of rounds
> 
> 
> 
> 5 cells buffer: bc
> 
> 25 cells buffer: st
> 
> 
> 
> : lrot1 ( x1 -- x2 )  dup 2* swap 0< - ;
> 
> : lrot ( x1 n -- x2 )  2dup lshift >r 64 swap - rshift r> or ;
> 
> : xor! ( x addr -- )  dup >r @ xor r> ! ;
> 
> 
> 
> : theta1 ( -- )
> 
>     5 0 DO
> 
>         0 st i cells + 25 cells bounds DO  I @ xor  [ 5 cells ]L +LOOP
> 
>         bc i cells + !
> 
>     LOOP ;
> 
> 
> 
> : theta2 ( -- )
> 
>     5 0 DO
> 
>         bc I 4 + 5 mod cells + @
> 
>         bc I 1 + 5 mod cells + @ lrot1 xor
> 
>         st i cells + 25 cells bounds DO  dup I xor!  [ 5 cells ]L +LOOP
> 
>         drop
> 
>     LOOP ;
> 
> 
> 
> : rhopi ( -- )
> 
>     st cell+ @
> 
>     24 0 DO
> 
>         keccakf-piln I + c@
> 
>         cells st + dup @
> 
>         rot keccakf-rotc I + c@ lrot
> 
>         rot !
> 
>     LOOP drop ;
> 
> 
> 
> : chi ( -- )
> 
>     st 25 cells bounds DO
> 
>         I bc 5 cells move
> 
>         5 0 DO
> 
>             bc I 1+ 5 mod cells + @ bc I 2 + 5 mod cells + @ and
> 
>             J I cells + xor!
> 
>         LOOP
> 
>     [ 5 cells ]L +LOOP ;
> 
> 
> 
> : iota ( round -- )
> 
>     cells keccakf-rndc + @ st @ xor st ! ;
> 
> 
> 
> : keccakf ( -- )
> 
>     keccak-rounds 0 ?DO  theta1  theta2  rhopi  chi  I iota  LOOP ;
> 
> 
> 
> : st0 ( -- )  st 25 cells erase ;
> 
> 
> 
> : >sponge ( addr u -- )
> 
>     \ fill in sponge function
> 
>     st swap bounds DO  dup @ I xor!  cell+  cell +LOOP  drop ;
> 
> 
> 
> 144 buffer: kpad
> 
> 
> 
> : padded>sponge ( addr u1 u2 -- )  >r
> 
>     \ pad last round
> 
>     kpad r@ erase  tuck kpad swap move
> 
>     kpad + 1 swap c!
> 
>     kpad r@ + 1- dup c@ $80 or swap c!
> 
>     kpad r> >sponge  ;
> 
> 
> 
> -- 
> 
> Bernd Paysan
> 
> "If you want it done right, you have to do it yourself"
> 
> http://bernd-paysan.de/

Does Gforth have 64-bit versions for Linux and/or Windoze?
I have gforth 0.7 and couldn't find anything more recent or for 64-bit systems.

[toc] | [prev] | [next] | [standalone]


#18856

FromBernd Paysan <bernd.paysan@gmx.de>
Date2013-01-16 19:08 +0100
Message-ID<1470845.eMG7Yzs4FC@sunwukong.fritz.box>
In reply to#18854
jzakiya@gmail.com wrote:
> Does Gforth have 64-bit versions for Linux

Yes.

> and/or Windoze?

No.  We use the Cygwin environment for Windows, and the 64 bit Cygwin 
doesn't make much progress - at least they have a 64 bit mingw compiler 
now, but no cygwin.dll.  Sorry for that, but Windows is a second-class 
operating system, at least for free software ;-).

> I have gforth 0.7 and couldn't find anything more recent or for 64-bit
> systems.

Where have you looked?  0.7 is the last stable release; it works fine on 
64 bit systems.  There have been times during the development after 0.7 
where we had bugs that were only triggered on a 32 bit system, and 
didn't find them, because all the authors used only 64 bit systems.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#18857

Fromjzakiya@gmail.com
Date2013-01-16 10:32 -0800
Message-ID<e3a53842-87c6-4bec-b82b-0a9e3bb44546@googlegroups.com>
In reply to#18856
On Wednesday, January 16, 2013 1:08:49 PM UTC-5, Bernd Paysan wrote:
> jzakiya@gmail.com wrote:
> 
> > Does Gforth have 64-bit versions for Linux
> 
> 
> 
> Yes.
> 
> 
> 
> > and/or Windoze?
> 
> 
> 
> No.  We use the Cygwin environment for Windows, and the 64 bit Cygwin 
> 
> doesn't make much progress - at least they have a 64 bit mingw compiler 
> 
> now, but no cygwin.dll.  Sorry for that, but Windows is a second-class 
> 
> operating system, at least for free software ;-).
> 
> 
> 
> > I have gforth 0.7 and couldn't find anything more recent or for 64-bit
> 
> > systems.
> 
> 
> 
> Where have you looked?  0.7 is the last stable release; it works fine on 
> 
> 64 bit systems.  There have been times during the development after 0.7 
> 
> where we had bugs that were only triggered on a 32 bit system, and 
> 
> didn't find them, because all the authors used only 64 bit systems.
> 
> 
> 
> -- 
> 
> Bernd Paysan
> 
> "If you want it done right, you have to do it yourself"
> 
> http://bernd-paysan.de/

I have a Lenovo laptop with an Intel I5 64-bit cpu.

I'm running a (currently) 32-bit Linux, so gforth is
only 32-bits (32-bit cells).

I also run Win 7 64-bit home premium as dual-boot and
have gforth 0.7 installed on it too, but it's still a
32-bit forth.

Is there something you have to do to get it to operate
in 64-bit mode (64-bit stack/cells)?

[toc] | [prev] | [next] | [standalone]


#18860

FromBernd Paysan <bernd.paysan@gmx.de>
Date2013-01-16 23:33 +0100
Message-ID<1833043.GjIIGktdfJ@sunwukong.fritz.box>
In reply to#18857
jzakiya@gmail.com wrote:
> I have a Lenovo laptop with an Intel I5 64-bit cpu.
> 
> I'm running a (currently) 32-bit Linux, so gforth is
> only 32-bits (32-bit cells).

Yes, a 32 bit Linux won't give you the capabilities to utilize your 64 
bit CPU.

> I also run Win 7 64-bit home premium as dual-boot and
> have gforth 0.7 installed on it too, but it's still a
> 32-bit forth.

As I said, on Windows, which is a second class operating system for free 
software, we have no easy way to build it to 64 bits.  And the hard way?  
This is a GNU project, this is not a support-Steve-Ballmer's sinking 
platform project.  I'm willing to donate a throwable chair anytime, 
though.

> Is there something you have to do to get it to operate
> in 64-bit mode (64-bit stack/cells)?

Yes, get a first class operating system for free software (Linux) with 
64 bits.  Why install a 32 bit Linux on a 64 bit CPU?  And then expect 
it to run 64 bit programs?

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#18861

FromAlex McDonald <blog@rivadpm.com>
Date2013-01-16 14:53 -0800
Message-ID<5dbd0c93-4b2c-4d6a-bef3-ddf51f1d8375@c14g2000vbd.googlegroups.com>
In reply to#18860
On Jan 16, 10:33 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote:
> jzak...@gmail.com wrote:
> > I have a Lenovo laptop with an Intel I5 64-bit cpu.
>
> > I'm running a (currently) 32-bit Linux, so gforth is
> > only 32-bits (32-bit cells).
>
> Yes, a 32 bit Linux won't give you the capabilities to utilize your 64
> bit CPU.
>
> > I also run Win 7 64-bit home premium as dual-boot and
> > have gforth 0.7 installed on it too, but it's still a
> > 32-bit forth.
>
> As I said, on Windows, which is a second class operating system for free
> software, we have no easy way to build it to 64 bits.  And the hard way?
> This is a GNU project, this is not a support-Steve-Ballmer's sinking
> platform project.  I'm willing to donate a throwable chair anytime,
> though.
>
> > Is there something you have to do to get it to operate
> > in 64-bit mode (64-bit stack/cells)?
>
> Yes, get a first class operating system for free software (Linux) with
> 64 bits.  Why install a 32 bit Linux on a 64 bit CPU?  And then expect
> it to run 64 bit programs?
>
> --
> Bernd Paysan
> "If you want it done right, you have to do it yourself"http://bernd-paysan.de/

Run a VM. Vbox https://www.virtualbox.org/ will run a 64bit OS inside
a 32 or 64bit OS; I was running a 64bit Linux on a WindowsXP 32bit for
years. All that's required for half decent performance is >1.5GB of
RAM (leave Windows 1GB and add the size of the VM; 512KB should
suffice for most Linux distros if you ignore the fancy graphics
options) and make sure the BIOS support for VM-VT and EPT is turned
on. The i5 supports VM assist; http://ark.intel.com/Products/VirtualizationTechnology

[toc] | [prev] | [next] | [standalone]


#18871

Fromjzakiya@gmail.com
Date2013-01-16 20:40 -0800
Message-ID<b0dce636-7bb4-4717-9a3a-99bf4ffceafb@googlegroups.com>
In reply to#18861
On Wednesday, January 16, 2013 5:53:13 PM UTC-5, Alex McDonald wrote:
> On Jan 16, 10:33 pm, Bernd Paysan <bernd.pay...@gmx.de> wrote:
> 
> > jzak...@gmail.com wrote:
> 
> > > I have a Lenovo laptop with an Intel I5 64-bit cpu.
> 
> >
> 
> > > I'm running a (currently) 32-bit Linux, so gforth is
> 
> > > only 32-bits (32-bit cells).
> 
> >
> 
> > Yes, a 32 bit Linux won't give you the capabilities to utilize your 64
> 
> > bit CPU.
> 
> >
> 
> > > I also run Win 7 64-bit home premium as dual-boot and
> 
> > > have gforth 0.7 installed on it too, but it's still a
> 
> > > 32-bit forth.
> 
> >
> 
> > As I said, on Windows, which is a second class operating system for free
> 
> > software, we have no easy way to build it to 64 bits.  And the hard way?
> 
> > This is a GNU project, this is not a support-Steve-Ballmer's sinking
> 
> > platform project.  I'm willing to donate a throwable chair anytime,
> 
> > though.
> 
> >
> 
> > > Is there something you have to do to get it to operate
> 
> > > in 64-bit mode (64-bit stack/cells)?
> 
> >
> 
> > Yes, get a first class operating system for free software (Linux) with
> 
> > 64 bits.  Why install a 32 bit Linux on a 64 bit CPU?  And then expect
> 
> > it to run 64 bit programs?
> 
> >
> 
> > --
> 
> > Bernd Paysan
> 
> > "If you want it done right, you have to do it yourself"http://bernd-paysan.de/
> 
> 
> 
> Run a VM. Vbox https://www.virtualbox.org/ will run a 64bit OS inside
> 
> a 32 or 64bit OS; I was running a 64bit Linux on a WindowsXP 32bit for
> 
> years. All that's required for half decent performance is >1.5GB of
> 
> RAM (leave Windows 1GB and add the size of the VM; 512KB should
> 
> suffice for most Linux distros if you ignore the fancy graphics
> 
> options) and make sure the BIOS support for VM-VT and EPT is turned
> 
> on. The i5 supports VM assist; http://ark.intel.com/Products/VirtualizationTechnology

Since I (presently) don't have a 64-bit forth, can I get some feedback
from people who do and let me know if the code in SHA-384_512xxx.F works
correctly with no problems, including SHAfile, to hash a file.

jz

[toc] | [prev] | [next] | [standalone]


#18878

Frommhx@iae.nl (Marcel Hendrix)
Date2013-01-17 22:36 +0200
Message-ID<05671318028434@frunobulax.edu>
In reply to#18871
jzakiya@gmail.com writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth
[..]
> Since I (presently) don't have a 64-bit forth, can I get some feedback
> from people who do and let me know if the code in SHA-384_512xxx.F works
> correctly with no problems, including SHAfile, to hash a file.

There are some issues with iForth64:

FORTH> help DIGIT
DIGIT                                                                IFORTH
     ( u -- c )
     c is the alphanumeric character that represents the value u. The current
     number base is not checked.
 ok

: ChooseHash
  CR  CR  ." Selection Menu: "
  CR ." For SHA-384 enter     1: " CR ." For SHA-512 enter     2: "
  CR ." For SHA-512/256 enter 3: " CR ." For SHA-512/224 enter 4: "
  BEGIN  CR ." Enter selection: " KEY '0' - 
         DUP 1 5 WITHIN IF TO SHA? FALSE ELSE DROP TRUE THEN \ A digit 0-9
  WHILE  ." Invalid input, try again." CR REPEAT \ Repeat if not/invalid digit
  CASE SHA?
    1 OF ." SHA-384 selected"     CR ENDOF
    2 OF ." SHA-512 selected"     CR ENDOF
    3 OF ." SHA-512/256 selected" CR ENDOF
    4 OF ." SHA-512/224 selected" CR ENDOF
  ENDCASE
;

[DEFINED] .SIGNON [IF]
\ ===========  iForth specific timing test words ===========

: TIMER-START  ( - ms )  ?ms ;

: TIMER-END    ( ms - )  ?ms SWAP - U>D  msecs ;

[THEN]

Your test words don't check if the generated result is correct.

-marcel



-- --------
FORTH> in
Redefining split-at-char
Redefining MACRO

Selection Menu:
For SHA-384 enter     1:
For SHA-512 enter     2:
For SHA-512/256 enter 3:
For SHA-512/224 enter 4:
Enter selection: SHA-384 selected
 ok
FORTH> SHAtest
SHA-384 test suite:
38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b ""
cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 "abc"
09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039 "abcdefghbcdefghicdefghijdefghijkefghijklfg
hijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
f130f26be2fdb404296211c772565814056ec15f1af58a1eb8d71794b5520c6468c6d7f76857c749faef76b90a6c5570 2 million copies of ASCII 'a' (61h)
d1471912409a024e336a1f03051f5663d138d7edf6b521c89329a4f81b20bb3365a245647174bc8a54d9152833b24ca9 400,000 copies of ASCII BL (20h)
 ok
FORTH> test1 test2 test3
SHA-384 test for EX1 for 100 loops is 0.001 secs ok
SHA-384 test for EX2 for 100 loops is 0.001 secs
SHA-384 test for EX2 for 100 loops is 2.190 secs ok

FORTH> in
Redefining split-at-char
Redefining MACRO

Selection Menu:
For SHA-384 enter     1:
For SHA-512 enter     2:
For SHA-512/256 enter 3:
For SHA-512/224 enter 4:
Enter selection: SHA-512 selected
 ok
FORTH> SHAtest
SHA-512 test suite:
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e ""
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f "abc"
8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 "abcdefghbc
defghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
9bc68759247e3332bec1c79d128d28a8931d0c9f96c8aa975731b563475fdddddf7f873c25086908effe270e23c5a01e5dfb3289bf5d091d8fb454b1bcf98dda 2 million c
opies of ASCII 'a' (61h)
19ef4876e03c93476e00b486c62108d4d7136f6d4782817b449bacf44d0963e03f5ab474cb6822c2963a979e8e15298cd60f22841c51f6161620c0e031c65f4a 400,000 cop
ies of ASCII BL (20h)
 ok
FORTH> test1 test2 test3
SHA-512 test for EX1 for 100 loops is 0.000 secs
SHA-512 test for EX2 for 100 loops is 0.000 secs
SHA-512 test for EX2 for 100 loops is 2.069 secs ok
FORTH> in
Redefining split-at-char
Redefining MACRO

Selection Menu:
For SHA-384 enter     1:
For SHA-512 enter     2:
For SHA-512/256 enter 3:
For SHA-512/224 enter 4:
Enter selection: SHA-512/256 selected
 ok
FORTH> SHAtest
SHA-512/256 test suite:
c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a ""
53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23 "abc"
3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjk
lmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
0b99d698b528d8eea61af5e52651abe4963fe7abb65f3132863ac0962542c6b7 2 million copies of ASCII 'a' (61h)
959f1e539598bfc0e33a9926e76adad6a44ff54f3537ba5c79a58e420e4cd49d 400,000 copies of ASCII BL (20h)
 ok
FORTH> test1 test2 test3
SHA-512/256 test for EX1 for 100 loops is 0.000 secs
SHA-512/256 test for EX2 for 100 loops is 0.000 secs
SHA-512/256 test for EX2 for 100 loops is 2.202 secs ok
FORTH> in
Redefining split-at-char
Redefining MACRO

Selection Menu:
For SHA-384 enter     1:
For SHA-512 enter     2:
For SHA-512/256 enter 3:
For SHA-512/224 enter 4:
Enter selection: SHA-512/224 selected
 ok
FORTH> SHAtest
SHA-512/224 test suite:
6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4 ""
4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa "abc"
23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqkl
mnopqrlmnopqrsmnopqrstnopqrstu"
e4e6eb0b5dc71edec81303eb38e60a89c834c169a9f17a45d18e271c 2 million copies of ASCII 'a' (61h)
86f21595b8a3f940fc20acda3a2d6612b763d65054225c96a79c60fd 400,000 copies of ASCII BL (20h)
 ok
FORTH> test1 test2 test3
SHA-512/224 test for EX1 for 100 loops is 0.001 secs
SHA-512/224 test for EX2 for 100 loops is 0.001 secs
SHA-512/224 test for EX2 for 100 loops is 2.096 secs ok
FORTH> shafile

Filename: C:\idfwforth\examples\internet\idata\securehash.frt
Bytesize: 25080
SHA-512/224 : 695aab8f05f91d89f894bc1756588f784b65ceae4fbb73309dbe82e3
 ok

[toc] | [prev] | [next] | [standalone]


#18880

Fromjzakiya@gmail.com
Date2013-01-17 22:24 -0800
Message-ID<3f70f49b-8bf3-456a-aa26-1fcda9666136@googlegroups.com>
In reply to#18878
On Thursday, January 17, 2013 3:36:30 PM UTC-5, Marcel Hendrix wrote:
> jzakiya@gmail.com writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth
> 
> [..]
> 
> > Since I (presently) don't have a 64-bit forth, can I get some feedback
> 
> > from people who do and let me know if the code in SHA-384_512xxx.F works
> 
> > correctly with no problems, including SHAfile, to hash a file.
> 
> 
> 
> There are some issues with iForth64:
> 
> 
> 
> FORTH> help DIGIT
> 
> DIGIT                                                                IFORTH
> 
>      ( u -- c )
> 
>      c is the alphanumeric character that represents the value u. The current
> 
>      number base is not checked.
> 
>  ok
> 
> 
> 
> : ChooseHash
> 
>   CR  CR  ." Selection Menu: "
> 
>   CR ." For SHA-384 enter     1: " CR ." For SHA-512 enter     2: "
> 
>   CR ." For SHA-512/256 enter 3: " CR ." For SHA-512/224 enter 4: "
> 
>   BEGIN  CR ." Enter selection: " KEY '0' - 
> 
>          DUP 1 5 WITHIN IF TO SHA? FALSE ELSE DROP TRUE THEN \ A digit 0-9
> 
>   WHILE  ." Invalid input, try again." CR REPEAT \ Repeat if not/invalid digit
> 
>   CASE SHA?
> 
>     1 OF ." SHA-384 selected"     CR ENDOF
> 
>     2 OF ." SHA-512 selected"     CR ENDOF
> 
>     3 OF ." SHA-512/256 selected" CR ENDOF
> 
>     4 OF ." SHA-512/224 selected" CR ENDOF
> 
>   ENDCASE
> 
> ;
> 
> 
> 
> [DEFINED] .SIGNON [IF]
> 
> \ ===========  iForth specific timing test words ===========
> 
> 
> 
> : TIMER-START  ( - ms )  ?ms ;
> 
> 
> 
> : TIMER-END    ( ms - )  ?ms SWAP - U>D  msecs ;
> 
> 
> 
> [THEN]
> 
> 
> 
> Your test words don't check if the generated result is correct.
> 
> 
> 
> -marcel
> 
> 
> 
> 
> 
> 
> 
> -- --------
> 
> FORTH> in
> 
> Redefining split-at-char
> 
> Redefining MACRO
> 
> 
> 
> Selection Menu:
> 
> For SHA-384 enter     1:
> 
> For SHA-512 enter     2:
> 
> For SHA-512/256 enter 3:
> 
> For SHA-512/224 enter 4:
> 
> Enter selection: SHA-384 selected
> 
>  ok
> 
> FORTH> SHAtest
> 
> SHA-384 test suite:
> 
> 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b ""
> 
> cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 "abc"
> 
> 09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039 "abcdefghbcdefghicdefghijdefghijkefghijklfg
> 
> hijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
> 
> f130f26be2fdb404296211c772565814056ec15f1af58a1eb8d71794b5520c6468c6d7f76857c749faef76b90a6c5570 2 million copies of ASCII 'a' (61h)
> 
> d1471912409a024e336a1f03051f5663d138d7edf6b521c89329a4f81b20bb3365a245647174bc8a54d9152833b24ca9 400,000 copies of ASCII BL (20h)
> 
>  ok
> 
> FORTH> test1 test2 test3
> 
> SHA-384 test for EX1 for 100 loops is 0.001 secs ok
> 
> SHA-384 test for EX2 for 100 loops is 0.001 secs
> 
> SHA-384 test for EX2 for 100 loops is 2.190 secs ok
> 
> 
> 
> FORTH> in
> 
> Redefining split-at-char
> 
> Redefining MACRO
> 
> 
> 
> Selection Menu:
> 
> For SHA-384 enter     1:
> 
> For SHA-512 enter     2:
> 
> For SHA-512/256 enter 3:
> 
> For SHA-512/224 enter 4:
> 
> Enter selection: SHA-512 selected
> 
>  ok
> 
> FORTH> SHAtest
> 
> SHA-512 test suite:
> 
> cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e ""
> 
> ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f "abc"
> 
> 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 "abcdefghbc
> 
> defghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
> 
> 9bc68759247e3332bec1c79d128d28a8931d0c9f96c8aa975731b563475fdddddf7f873c25086908effe270e23c5a01e5dfb3289bf5d091d8fb454b1bcf98dda 2 million c
> 
> opies of ASCII 'a' (61h)
> 
> 19ef4876e03c93476e00b486c62108d4d7136f6d4782817b449bacf44d0963e03f5ab474cb6822c2963a979e8e15298cd60f22841c51f6161620c0e031c65f4a 400,000 cop
> 
> ies of ASCII BL (20h)
> 
>  ok
> 
> FORTH> test1 test2 test3
> 
> SHA-512 test for EX1 for 100 loops is 0.000 secs
> 
> SHA-512 test for EX2 for 100 loops is 0.000 secs
> 
> SHA-512 test for EX2 for 100 loops is 2.069 secs ok
> 
> FORTH> in
> 
> Redefining split-at-char
> 
> Redefining MACRO
> 
> 
> 
> Selection Menu:
> 
> For SHA-384 enter     1:
> 
> For SHA-512 enter     2:
> 
> For SHA-512/256 enter 3:
> 
> For SHA-512/224 enter 4:
> 
> Enter selection: SHA-512/256 selected
> 
>  ok
> 
> FORTH> SHAtest
> 
> SHA-512/256 test suite:
> 
> c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a ""
> 
> 53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23 "abc"
> 
> 3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjk
> 
> lmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
> 
> 0b99d698b528d8eea61af5e52651abe4963fe7abb65f3132863ac0962542c6b7 2 million copies of ASCII 'a' (61h)
> 
> 959f1e539598bfc0e33a9926e76adad6a44ff54f3537ba5c79a58e420e4cd49d 400,000 copies of ASCII BL (20h)
> 
>  ok
> 
> FORTH> test1 test2 test3
> 
> SHA-512/256 test for EX1 for 100 loops is 0.000 secs
> 
> SHA-512/256 test for EX2 for 100 loops is 0.000 secs
> 
> SHA-512/256 test for EX2 for 100 loops is 2.202 secs ok
> 
> FORTH> in
> 
> Redefining split-at-char
> 
> Redefining MACRO
> 
> 
> 
> Selection Menu:
> 
> For SHA-384 enter     1:
> 
> For SHA-512 enter     2:
> 
> For SHA-512/256 enter 3:
> 
> For SHA-512/224 enter 4:
> 
> Enter selection: SHA-512/224 selected
> 
>  ok
> 
> FORTH> SHAtest
> 
> SHA-512/224 test suite:
> 
> 6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4 ""
> 
> 4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa "abc"
> 
> 23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqkl
> 
> mnopqrlmnopqrsmnopqrstnopqrstu"
> 
> e4e6eb0b5dc71edec81303eb38e60a89c834c169a9f17a45d18e271c 2 million copies of ASCII 'a' (61h)
> 
> 86f21595b8a3f940fc20acda3a2d6612b763d65054225c96a79c60fd 400,000 copies of ASCII BL (20h)
> 
>  ok
> 
> FORTH> test1 test2 test3
> 
> SHA-512/224 test for EX1 for 100 loops is 0.001 secs
> 
> SHA-512/224 test for EX2 for 100 loops is 0.001 secs
> 
> SHA-512/224 test for EX2 for 100 loops is 2.096 secs ok
> 
> FORTH> shafile
> 
> 
> 
> Filename: C:\idfwforth\examples\internet\idata\securehash.frt
> 
> Bytesize: 25080
> 
> SHA-512/224 : 695aab8f05f91d89f894bc1756588f784b65ceae4fbb73309dbe82e3
> 
>  ok

Marcel,

Thanks for posting the test results.
The answers are correct.
In the test code the hash results are given for 'abc' and 'abcd....qrts'
that are provided in FIPS 180-4 for each SHA version. Since these are correct
the others must be correct too.

To further test just download a file (iso, rpm, etc) which has a SHA-512, et al checksum and see if it gives the correct result. Since the algorithm is common to each version, and the only differences are the initial hash values and the number of characters in the final hash value that are displayed, if you get the correct results for any hash version you know the algorithm is being performed correctly, so you will get the correct results for all of them (as you already did with the test results you showed).

By the way, I did a version that didn't place the message block words on that stack, but did it in memory, and it's appreciably slower than using the stack.
PICKing off the stack is much faster than @|! into memory arrays.

But now that you have a reference working versions, you can always play around with them to see if you can do it faster in a more IForth specific manner.

FYI, when I originally did SHA-1 and SHA-256 back in 2000-3 I did ICODEd versions for SwiftForth and VFX that are nearly twice as fast as their ANS Forth versions, but these were specifically tuned to Intel P4 chips back then. A decade later these algorithms still must be done serially and can't take advantage of parallel operations in multi-core/threaded cpus.

jz

[toc] | [prev] | [next] | [standalone]


#18881

Fromjzakiya@gmail.com
Date2013-01-17 22:46 -0800
Message-ID<3e89729d-d578-4fe1-b65f-e7e513d9e792@googlegroups.com>
In reply to#18880
On Friday, January 18, 2013 1:24:45 AM UTC-5, jza...@gmail.com wrote:
> On Thursday, January 17, 2013 3:36:30 PM UTC-5, Marcel Hendrix wrote:
> 
> > jzakiya@gmail.com writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth
> 
> > 
> 
> > [..]
> 
> > 
> 
> > > Since I (presently) don't have a 64-bit forth, can I get some feedback
> 
> > 
> 
> > > from people who do and let me know if the code in SHA-384_512xxx.F works
> 
> > 
> 
> > > correctly with no problems, including SHAfile, to hash a file.
> 
> > 
> 
> > 
> 
> > 
> 
> > There are some issues with iForth64:
> 
> > 
> 
> > 
> 
> > 
> 
> > FORTH> help DIGIT
> 
> > 
> 
> > DIGIT                                                                IFORTH
> 
> > 
> 
> >      ( u -- c )
> 
> > 
> 
> >      c is the alphanumeric character that represents the value u. The current
> 
> > 
> 
> >      number base is not checked.
> 
> > 
> 
> >  ok
> 
> > 
> 
> > 
> 
> > 
> 
> > : ChooseHash
> 
> > 
> 
> >   CR  CR  ." Selection Menu: "
> 
> > 
> 
> >   CR ." For SHA-384 enter     1: " CR ." For SHA-512 enter     2: "
> 
> > 
> 
> >   CR ." For SHA-512/256 enter 3: " CR ." For SHA-512/224 enter 4: "
> 
> > 
> 
> >   BEGIN  CR ." Enter selection: " KEY '0' - 
> 
> > 
> 
> >          DUP 1 5 WITHIN IF TO SHA? FALSE ELSE DROP TRUE THEN \ A digit 0-9
> 
> > 
> 
> >   WHILE  ." Invalid input, try again." CR REPEAT \ Repeat if not/invalid digit
> 
> > 
> 
> >   CASE SHA?
> 
> > 
> 
> >     1 OF ." SHA-384 selected"     CR ENDOF
> 
> > 
> 
> >     2 OF ." SHA-512 selected"     CR ENDOF
> 
> > 
> 
> >     3 OF ." SHA-512/256 selected" CR ENDOF
> 
> > 
> 
> >     4 OF ." SHA-512/224 selected" CR ENDOF
> 
> > 
> 
> >   ENDCASE
> 
> > 
> 
> > ;
> 
> > 
> 
> > 
> 
> > 
> 
> > [DEFINED] .SIGNON [IF]
> 
> > 
> 
> > \ ===========  iForth specific timing test words ===========
> 
> > 
> 
> > 
> 
> > 
> 
> > : TIMER-START  ( - ms )  ?ms ;
> 
> > 
> 
> > 
> 
> > 
> 
> > : TIMER-END    ( ms - )  ?ms SWAP - U>D  msecs ;
> 
> > 
> 
> > 
> 
> > 
> 
> > [THEN]
> 
> > 
> 
> > 
> 
> > 
> 
> > Your test words don't check if the generated result is correct.
> 
> > 
> 
> > 
> 
> > 
> 
> > -marcel
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > -- --------
> 
> > 
> 
> > FORTH> in
> 
> > 
> 
> > Redefining split-at-char
> 
> > 
> 
> > Redefining MACRO
> 
> > 
> 
> > 
> 
> > 
> 
> > Selection Menu:
> 
> > 
> 
> > For SHA-384 enter     1:
> 
> > 
> 
> > For SHA-512 enter     2:
> 
> > 
> 
> > For SHA-512/256 enter 3:
> 
> > 
> 
> > For SHA-512/224 enter 4:
> 
> > 
> 
> > Enter selection: SHA-384 selected
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> SHAtest
> 
> > 
> 
> > SHA-384 test suite:
> 
> > 
> 
> > 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b ""
> 
> > 
> 
> > cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 "abc"
> 
> > 
> 
> > 09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039 "abcdefghbcdefghicdefghijdefghijkefghijklfg
> 
> > 
> 
> > hijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
> 
> > 
> 
> > f130f26be2fdb404296211c772565814056ec15f1af58a1eb8d71794b5520c6468c6d7f76857c749faef76b90a6c5570 2 million copies of ASCII 'a' (61h)
> 
> > 
> 
> > d1471912409a024e336a1f03051f5663d138d7edf6b521c89329a4f81b20bb3365a245647174bc8a54d9152833b24ca9 400,000 copies of ASCII BL (20h)
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> test1 test2 test3
> 
> > 
> 
> > SHA-384 test for EX1 for 100 loops is 0.001 secs ok
> 
> > 
> 
> > SHA-384 test for EX2 for 100 loops is 0.001 secs
> 
> > 
> 
> > SHA-384 test for EX2 for 100 loops is 2.190 secs ok
> 
> > 
> 
> > 
> 
> > 
> 
> > FORTH> in
> 
> > 
> 
> > Redefining split-at-char
> 
> > 
> 
> > Redefining MACRO
> 
> > 
> 
> > 
> 
> > 
> 
> > Selection Menu:
> 
> > 
> 
> > For SHA-384 enter     1:
> 
> > 
> 
> > For SHA-512 enter     2:
> 
> > 
> 
> > For SHA-512/256 enter 3:
> 
> > 
> 
> > For SHA-512/224 enter 4:
> 
> > 
> 
> > Enter selection: SHA-512 selected
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> SHAtest
> 
> > 
> 
> > SHA-512 test suite:
> 
> > 
> 
> > cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e ""
> 
> > 
> 
> > ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f "abc"
> 
> > 
> 
> > 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 "abcdefghbc
> 
> > 
> 
> > defghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
> 
> > 
> 
> > 9bc68759247e3332bec1c79d128d28a8931d0c9f96c8aa975731b563475fdddddf7f873c25086908effe270e23c5a01e5dfb3289bf5d091d8fb454b1bcf98dda 2 million c
> 
> > 
> 
> > opies of ASCII 'a' (61h)
> 
> > 
> 
> > 19ef4876e03c93476e00b486c62108d4d7136f6d4782817b449bacf44d0963e03f5ab474cb6822c2963a979e8e15298cd60f22841c51f6161620c0e031c65f4a 400,000 cop
> 
> > 
> 
> > ies of ASCII BL (20h)
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> test1 test2 test3
> 
> > 
> 
> > SHA-512 test for EX1 for 100 loops is 0.000 secs
> 
> > 
> 
> > SHA-512 test for EX2 for 100 loops is 0.000 secs
> 
> > 
> 
> > SHA-512 test for EX2 for 100 loops is 2.069 secs ok
> 
> > 
> 
> > FORTH> in
> 
> > 
> 
> > Redefining split-at-char
> 
> > 
> 
> > Redefining MACRO
> 
> > 
> 
> > 
> 
> > 
> 
> > Selection Menu:
> 
> > 
> 
> > For SHA-384 enter     1:
> 
> > 
> 
> > For SHA-512 enter     2:
> 
> > 
> 
> > For SHA-512/256 enter 3:
> 
> > 
> 
> > For SHA-512/224 enter 4:
> 
> > 
> 
> > Enter selection: SHA-512/256 selected
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> SHAtest
> 
> > 
> 
> > SHA-512/256 test suite:
> 
> > 
> 
> > c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a ""
> 
> > 
> 
> > 53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23 "abc"
> 
> > 
> 
> > 3928e184fb8690f840da3988121d31be65cb9d3ef83ee6146feac861e19b563a "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjk
> 
> > 
> 
> > lmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
> 
> > 
> 
> > 0b99d698b528d8eea61af5e52651abe4963fe7abb65f3132863ac0962542c6b7 2 million copies of ASCII 'a' (61h)
> 
> > 
> 
> > 959f1e539598bfc0e33a9926e76adad6a44ff54f3537ba5c79a58e420e4cd49d 400,000 copies of ASCII BL (20h)
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> test1 test2 test3
> 
> > 
> 
> > SHA-512/256 test for EX1 for 100 loops is 0.000 secs
> 
> > 
> 
> > SHA-512/256 test for EX2 for 100 loops is 0.000 secs
> 
> > 
> 
> > SHA-512/256 test for EX2 for 100 loops is 2.202 secs ok
> 
> > 
> 
> > FORTH> in
> 
> > 
> 
> > Redefining split-at-char
> 
> > 
> 
> > Redefining MACRO
> 
> > 
> 
> > 
> 
> > 
> 
> > Selection Menu:
> 
> > 
> 
> > For SHA-384 enter     1:
> 
> > 
> 
> > For SHA-512 enter     2:
> 
> > 
> 
> > For SHA-512/256 enter 3:
> 
> > 
> 
> > For SHA-512/224 enter 4:
> 
> > 
> 
> > Enter selection: SHA-512/224 selected
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> SHAtest
> 
> > 
> 
> > SHA-512/224 test suite:
> 
> > 
> 
> > 6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4 ""
> 
> > 
> 
> > 4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa "abc"
> 
> > 
> 
> > 23fec5bb94d60b23308192640b0c453335d664734fe40e7268674af9 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqkl
> 
> > 
> 
> > mnopqrlmnopqrsmnopqrstnopqrstu"
> 
> > 
> 
> > e4e6eb0b5dc71edec81303eb38e60a89c834c169a9f17a45d18e271c 2 million copies of ASCII 'a' (61h)
> 
> > 
> 
> > 86f21595b8a3f940fc20acda3a2d6612b763d65054225c96a79c60fd 400,000 copies of ASCII BL (20h)
> 
> > 
> 
> >  ok
> 
> > 
> 
> > FORTH> test1 test2 test3
> 
> > 
> 
> > SHA-512/224 test for EX1 for 100 loops is 0.001 secs
> 
> > 
> 
> > SHA-512/224 test for EX2 for 100 loops is 0.001 secs
> 
> > 
> 
> > SHA-512/224 test for EX2 for 100 loops is 2.096 secs ok
> 
> > 
> 
> > FORTH> shafile
> 
> > 
> 
> > 
> 
> > 
> 
> > Filename: C:\idfwforth\examples\internet\idata\securehash.frt
> 
> > 
> 
> > Bytesize: 25080
> 
> > 
> 
> > SHA-512/224 : 695aab8f05f91d89f894bc1756588f784b65ceae4fbb73309dbe82e3
> 
> > 
> 
> >  ok
> 
> 
> 
> Marcel,
> 
> 
> 
> Thanks for posting the test results.
> 
> The answers are correct.
> 
> In the test code the hash results are given for 'abc' and 'abcd....qrts'
> 
> that are provided in FIPS 180-4 for each SHA version. Since these are correct
> 
> the others must be correct too.
> 
> 
> 
> To further test just download a file (iso, rpm, etc) which has a SHA-512, et al checksum and see if it gives the correct result. Since the algorithm is common to each version, and the only differences are the initial hash values and the number of characters in the final hash value that are displayed, if you get the correct results for any hash version you know the algorithm is being performed correctly, so you will get the correct results for all of them (as you already did with the test results you showed).
> 
> 
> 
> By the way, I did a version that didn't place the message block words on that stack, but did it in memory, and it's appreciably slower than using the stack.
> 
> PICKing off the stack is much faster than @|! into memory arrays.
> 
> 
> 
> But now that you have a reference working versions, you can always play around with them to see if you can do it faster in a more IForth specific manner.
> 
> 
> 
> FYI, when I originally did SHA-1 and SHA-256 back in 2000-3 I did ICODEd versions for SwiftForth and VFX that are nearly twice as fast as their ANS Forth versions, but these were specifically tuned to Intel P4 chips back then. A decade later these algorithms still must be done serially and can't take advantage of parallel operations in multi-core/threaded cpus.
> 
> 
> 
> jz

Technical correction.

FIPS 180-4 doesn't have the test examples itself, but rather has a link to them here: http://csrc.nist.gov/groups/ST/toolkit/examples.html.

This has test examples for each algorithm separately or you can download all the examples in a pdf called SHA_ALL.pdf.

jz

[toc] | [prev] | [next] | [standalone]


#18890

Frommhx@iae.nl (Marcel Hendrix)
Date2013-01-19 09:14 +0200
Message-ID<71899416028434@frunobulax.edu>
In reply to#18880
jzakiya@gmail.com writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth

> On Thursday, January 17, 2013 3:36:30 PM UTC-5, Marcel Hendrix wrote:
>> jzakiya@gmail.com writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth
[..]
> Thanks for posting the test results.
> The answers are correct.

I am suggesting that you add the expected results of the build-in tests 
to the file. The (conditionally compiled) test words can then auto-check 
if there was any problem. It is not always possible or useful to do that, 
but here it certainly is.

> By the way, I did a version that didn't place the message block words on that 
> stack, but did it in memory, and it's appreciably slower than using the stack.
> PICKing off the stack is much faster than @|! into memory arrays.

OK. I think you remember that I showed a version for SHA-512 which does 
not use PICK and runs the benchmark for EX3 in 10.7 seconds. Your latest
published source (with PICK) compiles on iForth64 and the EX3 bench 
takes about 20 seconds. 

> But now that you have a reference working versions, you can always play around
> with them to see if you can do it faster in a more IForth specific manner.

I can get the EX3 bench down to 17 seconds by *removing* all MACRO 
and ]L and [ ] constructs... Isn't that nice, not even is CODE .. 
ENDCODE obsolete, but also compiler hints are rapidly becoming 
unnecessary. 

It would be interesting to do a straightforward translation of the 
C-description to see if the 'Forth thinking-style' is at all necessary 
to get those results. 
I suspect that it suffices to remove pointer-chasing nighmares and 
locals for the ~20 seconds result. 

> FYI, when I originally did SHA-1 and SHA-256 back in 2000-3 I did ICODEd versions 
> for SwiftForth and VFX that are nearly twice as fast as their ANS Forth versions, 
> but these were specifically tuned to Intel P4 chips back then. 

It would be interesting to know what was P4-specific in the ICODE ? 
I find that my assembly language tricks from the pre-P4 days still 
work. At some point it became important to not mix code and data, 
that's about it.

I have never understood why push and pop are slower than memory 
references on Intel chips. It must be something with changing the 
stack pointer, because other languages use the stack all of the 
time for their locals. However, if it were that, it would suffice 
to use e.g. rbp for the Forth stack. I have never seen reports 
that that is fundamentally faster then using rsp.

>                                                                A decade later 
> these algorithms still must be done serially and can't take 
> advantage of parallel operations in multi-core/threaded cpus.

I don't think time has anything to do with it. This algorithm is 
*designed* to be serial and slow -- you don't want brute force 
cracks to succeed.

I think we will see microcontrollers with on-board FPGA, RSN. 
Maybe the FPGA peripheral will find a way to the desktop. Forth 
has the flexibility and extensibility to use these things :-)

-marcel

[toc] | [prev] | [next] | [standalone]


#18896

FromAlex McDonald <blog@rivadpm.com>
Date2013-01-19 08:24 -0800
Message-ID<6944e941-c6bc-4c82-9d8c-44dd7beda849@c14g2000vbd.googlegroups.com>
In reply to#18890
On Jan 19, 7:14 am, m...@iae.nl (Marcel Hendrix) wrote:

>
> I have never understood why push and pop are slower than memory
> references on Intel chips. It must be something with changing the
> stack pointer, because other languages use the stack all of the
> time for their locals. However, if it were that, it would suffice
> to use e.g. rbp for the Forth stack. I have never seen reports
> that that is fundamentally faster then using rsp.

I user EBP for the stack in my Forth. It's marginally faster (in a
micro benchmark on an i7) than using ESP; and a lot faster than using
ESI and STOS/LODS. The code is, however, a lot larger.

[toc] | [prev] | [next] | [standalone]


#18914

Fromjzakiya@gmail.com
Date2013-01-19 18:10 -0800
Message-ID<6591fbdf-3798-471e-97fd-b0c44bc7a4a0@googlegroups.com>
In reply to#18896
On Saturday, January 19, 2013 11:24:53 AM UTC-5, Alex McDonald wrote:
> On Jan 19, 7:14 am, m...@iae.nl (Marcel Hendrix) wrote:
> 
> 
> 
> >
> 
> > I have never understood why push and pop are slower than memory
> 
> > references on Intel chips. It must be something with changing the
> 
> > stack pointer, because other languages use the stack all of the
> 
> > time for their locals. However, if it were that, it would suffice
> 
> > to use e.g. rbp for the Forth stack. I have never seen reports
> 
> > that that is fundamentally faster then using rsp.
> 
> 
> 
> I user EBP for the stack in my Forth. It's marginally faster (in a
> 
> micro benchmark on an i7) than using ESP; and a lot faster than using
> 
> ESI and STOS/LODS. The code is, however, a lot larger.

Part of optimizing code for the P4 is to keep the dual execution pipelines in constant use without flushing them.  There was a guy (I can't recall his site now) that had an ongoing programming manual on coding idioms for the P4 class chips to show how to parse arithmetic operations to keep both pipelines in parallel operation, and how to use conditionals and jump instructions to minimize pipeline flushing, etc. Using these idioms I was able to hand assemble the algorithms to get the times I was talking about. I still have the code, and it still works on my Intel I5, but I don't know to what extent it is "optimized" to the new class of Intel chips.

Using MACROS is just a way to specifically inline code snippets.
I used the Windows version of VFX 4.6 running under Wine on my 32-bit Linux distro to optimize performance under it (which runs faster than VFX running natively under 64-bit Windows 7).

Since I don't have a 64-bit VFX (is there one?) to run these examples on I  have no empirical base to assess what the code performance would be on it.

But the main purpose of the code is to provide a working "reference" implementation that people can use as a starting point to understanding the algorithm and make improvements on for their specific systems if desired.

jz

[toc] | [prev] | [next] | [standalone]


#18917

Frommhx@iae.nl (Marcel Hendrix)
Date2013-01-20 08:56 +0200
Message-ID<88799515028434@frunobulax.edu>
In reply to#18896
Alex McDonald <blog@rivadpm.com> writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth

> On Jan 19, 7:14am, m...@iae.nl (Marcel Hendrix) wrote:
>> I have never understood why push and pop are slower than memory
>> references on Intel chips. It must be something with changing the
>> stack pointer, because other languages use the stack all of the
>> time for their locals. However, if it were that, it would suffice
>> to use e.g. rbp for the Forth stack. I have never seen reports
>> that that is fundamentally faster then using rsp.

> I use EBP for the stack in my Forth. It's marginally faster (in a
>micro benchmark on an i7) than using ESP; and a lot faster than using
>ESI and STOS/LODS. The code is, however, a lot larger.

To make this more concrete, I wrote a small program and ran the tests:

FORTH> bench ( i7 2,66 GHz)
direct : 1.800 seconds elapsed.
null   : 0.601 seconds elapsed.
inc    : 1.726 seconds elapsed.
xchg   : 4.533 seconds elapsed.
rsp    : 1.804 seconds elapsed.
rbp    : 1.807 seconds elapsed. ok

Here "direct" copies 12 memory locations 1 cell up (stack without a 
stack pointer), "rsp" tests stack pushes on the user return stack,
"rbp" tests stack pushes on a stack indexed by RBP, "null" is a 
reference for how long it takes to execute 5,120,000,000 nop opcodes,
and "xchg" executes 5,120,000,000 xchg opcodes.

Conclusions: 
  1) it doesn't matter (for speed) if rsp or rbp is 
     used to build a stack.
  2) Memory R/W is exactly the same as stack R/W
  3) A push is as fast as a simple register opcode (inc)
  4) A nop is very fast (I believe it is optimized away in the CPU)
  5) A simple xchg of two registers (in 64 bit mode) is very slow.

It might even follow that there is no advantage in using registers
over directly adressed memory locations...

Conclusion 5) is not relevant to the discussion, I just mention it 
as an interesting experimental finding. (An assembler should provide 
a bit-trick replacement.)

-marcel

-- ------------
NEEDS -assemble

ANEW -testreg

#512 =: /ss
CREATE stack /ss CELLS ALLOT stack /ss CELLS ERASE
stack /ss CELLS + =: start

ALSO ASSEMBLER
: many_nop,  ( -- ) /ss 0 ?DO   nop,             LOOP ;
: many_ex,   ( -- ) /ss 0 ?DO   rax -> rax xchg, LOOP ;
: many_inc,  ( -- ) /ss 0 ?DO   rax inc,         LOOP ;
: rax_push0, ( -- ) /ss 0 ?DO   [rcx   I 1+ cells +] qword -> rax mov,  rax -> [rcx I CELLS +] qword mov,  LOOP ;
: rax_push1, ( -- ) /ss 0 ?DO   rax -> push,  LOOP ;
: rax_push2, ( -- ) /ss 0 ?DO   rax -> [rbp] mov,   [rbp -1 cells +] -> rbp lea,  LOOP ;
PREVIOUS

CODE test_direct ( a -- )
	stack q# -> rcx mov,
	  rax_push0, 
	rax pop, rax -> [rcx /ss 1- cells +] qword mov,
	rbx jmp,
END-CODE

CODE test_null ( a -- )
	rax pop,
	rsp -> rcx mov, start q# -> rsp mov,
	  many_nop, 
	rcx -> rsp mov,
	rbx jmp,
END-CODE

CODE test_ex ( a -- )
	rax pop,
	rsp -> rcx mov, start q# -> rsp mov,
	  many_ex, 
	rcx -> rsp mov,
	rbx jmp,
END-CODE

CODE test_inc ( a -- )
	rax pop,
	  many_inc, 
	rbx jmp,
END-CODE

CODE test_rsp ( a -- )
	rax pop,
	rsp -> rcx mov, start q# -> rsp mov,
	  rax_push1, 
	rcx -> rsp mov,
	rbx jmp,
END-CODE

CODE test_rbp ( a -- )
	rax pop,
	rbp -> rcx mov, start q# -> rbp mov,
	  rax_push2,
	rcx -> rbp mov,
	rbx jmp,
END-CODE


#10000000 VALUE #times
: bench	CR ." direct : " TIMER-RESET #times 0 DO  I test_direct  LOOP .ELAPSED 
	CR ." null   : " TIMER-RESET #times 0 DO  I test_null    LOOP .ELAPSED 
	CR ." inc    : " TIMER-RESET #times 0 DO  I test_inc     LOOP .ELAPSED 
	CR ." xchg   : " TIMER-RESET #times 0 DO  I test_ex      LOOP .ELAPSED 
	CR ." rsp    : " TIMER-RESET #times 0 DO  I test_rsp     LOOP .ELAPSED 
	CR ." rbp    : " TIMER-RESET #times 0 DO  I test_rbp     LOOP .ELAPSED ;

[toc] | [prev] | [next] | [standalone]


#18932

FromBernd Paysan <bernd.paysan@gmx.de>
Date2013-01-20 14:38 +0100
Message-ID<9992845.Pkt4JWEiZa@sunwukong.fritz.box>
In reply to#18917
Marcel Hendrix wrote:
> To make this more concrete, I wrote a small program and ran the tests:
> 
> FORTH> bench ( i7 2,66 GHz)
> direct : 1.800 seconds elapsed.
> null   : 0.601 seconds elapsed.
> inc    : 1.726 seconds elapsed.
> xchg   : 4.533 seconds elapsed.
> rsp    : 1.804 seconds elapsed.
> rbp    : 1.807 seconds elapsed. ok
> 
> Here "direct" copies 12 memory locations 1 cell up (stack without a
> stack pointer), "rsp" tests stack pushes on the user return stack,
> "rbp" tests stack pushes on a stack indexed by RBP, "null" is a
> reference for how long it takes to execute 5,120,000,000 nop opcodes,
> and "xchg" executes 5,120,000,000 xchg opcodes.
> 
> Conclusions:
>   1) it doesn't matter (for speed) if rsp or rbp is
>      used to build a stack.
>   2) Memory R/W is exactly the same as stack R/W
>   3) A push is as fast as a simple register opcode (inc)
>   4) A nop is very fast (I believe it is optimized away in the CPU)

You just can execute 3 nops in parallel on the Core i7, while all the 
other methods have sequential dependencies, which prevents parallel 
execution.  I'm a bit confused, because somehow I remember that Intel 
said, their current microarchitecture has ways to fuse pushs, so that 
you can do more than one push per cycle; but apparently, that's not the 
case.  Apparently doing something like

movq %rax,-8(%esp)
movq %rbx,-16(%esp)
movq %rcx,-24(%esp)
movq %rdx,-32(%esp)
leaq %esp,-32(%esp)

should be twice as fast as four pushs.

>   5) A simple xchg of two registers (in 64 bit mode) is very slow.

Indeed.  It's a bit confusing that it's 2.5 times slower than other 
operations, but apparently the way it is broken up in microops allows it 
to be slightly faster.  I think translating

xchgq %r8, %r9

to

movq %r8, %eax
movq %r9, %r8
movq %eax, %r9

should increase the speed.  Let's schedule two of them:

movq %r8, %eax || movq %r9, %r8
movq %eax, %r9 || movq %r8, %eax
movq %r9, %r8  || movq %eax, %r9

I.e. you should have 1.5 cycles per exchange, not 2.5.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

[toc] | [prev] | [next] | [standalone]


#18937

Frommhx@iae.nl (Marcel Hendrix)
Date2013-01-20 16:25 +0200
Message-ID<95101915028434@frunobulax.edu>
In reply to#18932
Bernd Paysan <bernd.paysan@gmx.de> writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth

> Marcel Hendrix wrote:
>> To make this more concrete, I wrote a small program and ran the tests:
>> 

> You just can execute 3 nops in parallel on the Core i7, while all the 
> other methods have sequential dependencies, which prevents parallel 
> execution.

OK, seems to be consistent.

>             I'm a bit confused, because somehow I remember that Intel 
> said, their current microarchitecture has ways to fuse pushs, so that 
> you can do more than one push per cycle; but apparently, that's not the 
> case.  Apparently doing something like
>
> movq %rax,-8(%esp)
> movq %rbx,-16(%esp)
> movq %rcx,-24(%esp)
> movq %rdx,-32(%esp)
> leaq %esp,-32(%esp)
>
> should be twice as fast as four pushs.

That doesn't seem to work.

>>   5) A simple xchg of two registers (in 64 bit mode) is very slow.
>
> Indeed.  It's a bit confusing that it's 2.5 times slower than other 
> operations, but apparently the way it is broken up in microops allows it 
> to be slightly faster.  I think translating
>
> xchgq %r8, %r9
>
> to
>
> movq %r8, %eax
> movq %r9, %r8
> movq %eax, %r9
>
> should increase the speed.

Should, but doesn't.

>                             Let's schedule two of them:
>
> movq %r8, %eax || movq %r9, %r8
> movq %eax, %r9 || movq %r8, %eax
> movq %r9, %r8  || movq %eax, %r9
>
> I.e. you should have 1.5 cycles per exchange, not 2.5.

Maybe :-)

Here are my results.

FORTH> bench
direct  : 1.855 seconds elapsed.
null    : 0.613 seconds elapsed.
inc     : 1.791 seconds elapsed.
xchg    : 4.681 seconds elapsed.
xchg2   : 5.423 seconds elapsed.
xchg3   : 4.213 seconds elapsed.
xchg4   : 4.485 seconds elapsed.
rsp     : 1.843 seconds elapsed.
par|rsp : 1.832 seconds elapsed.
rbp     : 1.849 seconds elapsed.
par|rbp : 1.843 seconds elapsed. ok

No happiness. 
I redraw the remark that xchg is slow; I can not find
a simple sequence which is faster. The famous XOR does not work,
and using a scratch register gives no speedup.

No way to accelerate parallel pushes yet.

-marcel

-- ----------------

NEEDS -assemble

ANEW -testreg

#512 =: /ss
CREATE stack /ss CELLS ALLOT stack /ss CELLS ERASE
stack /ss CELLS + =: start

ALSO ASSEMBLER
: many_nop,  ( -- ) /ss 0 ?DO   nop,             LOOP ;
: many_inc,  ( -- ) /ss 0 ?DO   rax inc,         LOOP ;
: many_ex,   ( -- ) /ss 0 ?DO   rax -> rax xchg, LOOP ;
: many_ex2,  ( -- ) /ss 0 ?DO   rax -> rcx xor,  rcx -> rax xor,  rax -> rcx xor,  LOOP ;
: many_ex3,  ( -- ) /ss 0 ?DO   rax -> rdx mov,  rcx -> rax mov,  rdx -> rcx xor,  LOOP ;
: rax_push0, ( -- ) /ss 0 ?DO   [rcx   I 1+ cells +] qword -> rax mov,  rax -> [rcx I CELLS +] qword mov,  LOOP ;
: rax_push1, ( -- ) /ss 0 ?DO   rax -> push,  LOOP ;
: rax_push*, ( -- ) /ss 4 / 0 ?DO   rax -> push, rbx -> push, rcx -> push, rdx -> push,  LOOP ;
: rax_push2, ( -- ) /ss 0 ?DO   rax -> [rbp] mov,   [rbp -1 cells +] -> rbp lea,  LOOP ;

: many_ex4,  ( -- ) /ss 2/  0 ?DO   rax -> rcx xor,  r8  -> r9  xor,
				    rcx -> rax xor,  r9  -> r8  xor, 
				    rax -> rcx xor,  r8  -> r9  xor,  	
			     LOOP ;

: fuse_push, ( -- ) /ss 4 / 0 ?DO   [rbp -4 cells +] -> rbp lea,  
				    rax -> [rbp 4 cells +] mov,  rbx -> [rbp 3 cells +] mov,
				    rcx -> [rbp 2 cells +] mov,  rdx -> [rbp 1 cells +] mov,
			     LOOP ;
PREVIOUS

CODE test_direct ( a -- )
	stack q# -> rcx mov,
	  rax_push0, 
	rax pop, rax -> [rcx /ss 1- cells +] qword mov,
	rbx jmp,
END-CODE

CODE test_null ( a -- )
	rax pop,
	  many_nop, 
	rbx jmp,
END-CODE

CODE test_ex ( a -- )
	rax pop,
	  many_ex, 
	rbx jmp,
END-CODE

CODE test_ex2 ( a -- )
	rax pop,
	  many_ex2, 
	rbx jmp,
END-CODE

CODE test_ex3 ( a -- )
	rax pop,
	  many_ex3, 
	rbx jmp,
END-CODE

CODE test_ex4 ( a -- )
	rax pop,
	  many_ex4, 
	rbx jmp,
END-CODE

CODE test_inc ( a -- )
	rax pop,
	  many_inc, 
	rbx jmp,
END-CODE

CODE test_rsp ( a -- )
	rax pop,
	rsp -> rcx mov, start q# -> rsp mov,
	  rax_push1, 
	rcx -> rsp mov,
	rbx jmp,
END-CODE

CODE test_rsp* ( a -- )
	rax pop,
	rsp -> rcx mov, start q# -> rsp mov,
	  rax_push*, 
	rcx -> rsp mov,
	rbx jmp,
END-CODE

CODE test_rbp ( a -- )
	rax pop,
	rbp -> rcx mov, start q# -> rbp mov,
	  rax_push2,
	rcx -> rbp mov,
	rbx jmp,
END-CODE

CODE test_rbp* ( a -- )
	rax pop,
	rbp -> rcx mov, start q# -> rbp mov,
	  fuse_push,
	rcx -> rbp mov,
	rbx jmp,
END-CODE

#10000000 VALUE #times
: bench	CR ." direct  : " TIMER-RESET #times 0 DO  I test_direct     LOOP .ELAPSED 
	CR ." null    : " TIMER-RESET #times 0 DO  I test_null       LOOP .ELAPSED 
	CR ." inc     : " TIMER-RESET #times 0 DO  I test_inc        LOOP .ELAPSED 
	CR ." xchg    : " TIMER-RESET #times 0 DO  I test_ex         LOOP .ELAPSED 
	CR ." xchg2   : " TIMER-RESET #times 0 DO  I test_ex2        LOOP .ELAPSED 
	CR ." xchg3   : " TIMER-RESET #times 0 DO  I test_ex3        LOOP .ELAPSED 
	CR ." xchg4   : " TIMER-RESET #times 0 DO  I test_ex4        LOOP .ELAPSED 
	CR ." rsp     : " TIMER-RESET #times 0 DO  I test_rsp        LOOP .ELAPSED 
	CR ." par|rsp : " TIMER-RESET #times 0 DO  I test_rsp*       LOOP .ELAPSED 
	CR ." rbp     : " TIMER-RESET #times 0 DO  I test_rbp        LOOP .ELAPSED 
	CR ." par|rbp : " TIMER-RESET #times 0 DO  I test_rbp*       LOOP .ELAPSED ;

[toc] | [prev] | [next] | [standalone]


#18944

FromAlex McDonald <blog@rivadpm.com>
Date2013-01-20 11:44 -0800
Message-ID<2350ee4d-0f2e-4eaa-ba6e-8cf4c79a62e8@q27g2000vbx.googlegroups.com>
In reply to#18917
On Jan 20, 6:56 am, m...@iae.nl (Marcel Hendrix) wrote:
> Alex McDonald <b...@rivadpm.com> writes Re: ANN: All FIPS 180-4 Secure Hash Algorithms in ANS Forth
>
> > On Jan 19, 7:14am, m...@iae.nl (Marcel Hendrix) wrote:
> >> I have never understood why push and pop are slower than memory
> >> references on Intel chips. It must be something with changing the
> >> stack pointer, because other languages use the stack all of the
> >> time for their locals. However, if it were that, it would suffice
> >> to use e.g. rbp for the Forth stack. I have never seen reports
> >> that that is fundamentally faster then using rsp.
> > I use EBP for the stack in my Forth. It's marginally faster (in a
> >micro benchmark on an i7) than using ESP; and a lot faster than using
> >ESI and STOS/LODS. The code is, however, a lot larger.
>
> To make this more concrete, I wrote a small program and ran the tests:
>
[test snipped]

Thanks. My results on 32 bits show a slight disadvantage to PUSH/POP;
consistently around 2%.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.forth


csiph-web