[openfirmware] [commit] r3137 - cpu/arm/mmp2 cpu/arm/olpc cpu/arm/olpc/1.75 cpu/arm/olpc/3.0 cpu/arm/olpc/cl4 ofw/wifi

repository service svn at openfirmware.info
Thu Aug 9 01:30:03 CEST 2012


Author: wmb
Date: Thu Aug  9 01:30:02 2012
New Revision: 3137
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3137

Log:
OLPC ARM - Use software for SHA1 and MD5 hashes instead of the MMP2 hash accelerator, which I haven't gotten to work on MMP3.

Added:
   cpu/arm/mmp2/random.fth
Modified:
   cpu/arm/mmp2/hash.fth
   cpu/arm/olpc/1.75/crypto-version.fth
   cpu/arm/olpc/3.0/crypto-version.fth
   cpu/arm/olpc/cl4/crypto-version.fth
   cpu/arm/olpc/prefw.fth
   ofw/wifi/hmacsha1.fth

Modified: cpu/arm/mmp2/hash.fth
==============================================================================
--- cpu/arm/mmp2/hash.fth	Thu Aug  9 01:27:09 2012	(r3136)
+++ cpu/arm/mmp2/hash.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -1,6 +1,7 @@
 \ See license at end of file
 purpose: Hashes (MD5, SHA1, SHA-256) using Marvell hardware acceleration
 
+[ifdef] use-mmp2-hashes
 h# 8101 constant dval
 : dma>hash  ( adr len -- )
    4 round-up  2 rshift  h# 29080c io!    ( adr )
@@ -119,48 +120,8 @@
 : sha1-init   use-sha1 hash-init  ;
 : sha1-update hash-update  ;
 : sha1-final hash-final drop to sha1-digest  ;
-
-: ebg-set  ( n -- )  h# 292c00 io@  or  h# 292c00 io!  ;
-: ebg-clr  ( n -- )  invert  h# 292c00 io@  and  h# 292c00 io!  ;
-
-0 [if]
-\ This is the procedure recommended by the datasheet, but it doesn't work
-: init-entropy-digital  ( -- )
-\   h# ffffffff ebg-clr   \ All off
-   h# 00008000 ebg-set   \ Digital entropy mode
-   h# 00000400 ebg-clr   \ RNG reset
-   h# 00000200 ebg-set   \ Bias power up
-   d# 400 us
-   h# 00000100 ebg-set   \ Fast OSC enable
-   h# 00000080 ebg-set   \ Slow OSC enable
-   h# 02000000 ebg-set   \ Downsampling ratio
-   h# 00110000 ebg-set   \ Slow OSC divider
-   h# 00000400 ebg-set   \ RNG unreset
-   h# 00000040 ebg-set   \ Post processor enable
-   h# 00001000 ebg-set
-;
-[else]
-\ This procedure works
-: init-entropy  ( -- )  \ Using digital method
-   h# 21117c0 h# 292c00 io!
-;
 [then]
 
-: random-short  ( -- w )
-   begin  h# 292c04 io@  dup 0>=  while  drop  repeat
-   h# ffff and
-;
-: random-byte  ( -- b )  random-short 2/ h# ff and  ;
-: random-long  ( -- l )
-   random-short random-short wljoin
-;
-alias random random-long
-
-stand-init: Random number generator
-   h# 1b h# 68 pmua!   \ Ensure WTM clock is enabled
-   init-entropy
-;
-
 \ LICENSE_BEGIN
 \ Copyright (c) 2010 FirmWorks
 \ 

Added: cpu/arm/mmp2/random.fth
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ cpu/arm/mmp2/random.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -0,0 +1,67 @@
+\ See license at end of file
+purpose: Random numbers using Marvell hardware acceleration
+
+0 [if]
+: ebg-set  ( n -- )  h# 292c00 io@  or  h# 292c00 io!  ;
+: ebg-clr  ( n -- )  invert  h# 292c00 io@  and  h# 292c00 io!  ;
+
+\ This is the procedure recommended by the datasheet, but it doesn't work
+: init-entropy-digital  ( -- )
+\   h# ffffffff ebg-clr   \ All off
+   h# 00008000 ebg-set   \ Digital entropy mode
+   h# 00000400 ebg-clr   \ RNG reset
+   h# 00000200 ebg-set   \ Bias power up
+   d# 400 us
+   h# 00000100 ebg-set   \ Fast OSC enable
+   h# 00000080 ebg-set   \ Slow OSC enable
+   h# 02000000 ebg-set   \ Downsampling ratio
+   h# 00110000 ebg-set   \ Slow OSC divider
+   h# 00000400 ebg-set   \ RNG unreset
+   h# 00000040 ebg-set   \ Post processor enable
+   h# 00001000 ebg-set
+;
+[else]
+\ This procedure works
+: init-entropy  ( -- )  \ Using digital method
+   h# 21117c0 h# 292c00 io!
+;
+[then]
+
+: random-short  ( -- w )
+   begin  h# 292c04 io@  dup 0>=  while  drop  repeat
+   h# ffff and
+;
+: random-byte  ( -- b )  random-short 2/ h# ff and  ;
+: random-long  ( -- l )
+   random-short random-short wljoin
+;
+alias random random-long
+
+stand-init: Random number generator
+   h# 1b h# 68 pmua!   \ Ensure WTM clock is enabled
+   init-entropy
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2010 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Modified: cpu/arm/olpc/1.75/crypto-version.fth
==============================================================================
--- cpu/arm/olpc/1.75/crypto-version.fth	Thu Aug  9 01:27:09 2012	(r3136)
+++ cpu/arm/olpc/1.75/crypto-version.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -3,4 +3,4 @@
 \ macro: KEYS testkeys
 
 \ The bios_verify image
-macro: CRYPTO_VERSION 0.5-ARM
+macro: CRYPTO_VERSION 0.6-ARM

Modified: cpu/arm/olpc/3.0/crypto-version.fth
==============================================================================
--- cpu/arm/olpc/3.0/crypto-version.fth	Thu Aug  9 01:27:09 2012	(r3136)
+++ cpu/arm/olpc/3.0/crypto-version.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -3,4 +3,4 @@
 \ macro: KEYS testkeys
 
 \ The bios_verify image
-macro: CRYPTO_VERSION 0.5-ARM
+macro: CRYPTO_VERSION 0.6-ARM

Modified: cpu/arm/olpc/cl4/crypto-version.fth
==============================================================================
--- cpu/arm/olpc/cl4/crypto-version.fth	Thu Aug  9 01:27:09 2012	(r3136)
+++ cpu/arm/olpc/cl4/crypto-version.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -3,4 +3,4 @@
 \ macro: KEYS testkeys
 
 \ The bios_verify image
-macro: CRYPTO_VERSION 0.5-ARM
+macro: CRYPTO_VERSION 0.6-ARM

Modified: cpu/arm/olpc/prefw.fth
==============================================================================
--- cpu/arm/olpc/prefw.fth	Thu Aug  9 01:27:09 2012	(r3136)
+++ cpu/arm/olpc/prefw.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -150,8 +150,9 @@
 
 fload ${BP}/cpu/arm/mmp2/socregs.fth   \ MMP2 registers used by many functional units
 
-fload ${BP}/cpu/arm/mmp2/hash.fth      \ Hashes - SHA1, SHA-256, MD5
+fload ${BP}/cpu/arm/mmp2/random.fth    \ Random numbers
 fload ${BP}/cpu/x86/pc/olpc/crypto.fth \ Cryptographic image validation
+fload ${BP}/cpu/arm/olpc/swhash.fth    \ Hashes - SHA1, SHA-256, MD5
 fload ${BP}/cpu/x86/pc/olpc/lzip.fth   \ Access zip images from memory
 
 fload ${BP}/ofw/inet/loadtcp.fth

Modified: ofw/wifi/hmacsha1.fth
==============================================================================
--- ofw/wifi/hmacsha1.fth	Thu Aug  9 01:27:09 2012	(r3136)
+++ ofw/wifi/hmacsha1.fth	Thu Aug  9 01:30:02 2012	(r3137)
@@ -36,27 +36,28 @@
       sha1-tkey /sha1-digest		( key$ )
    then
 ;
+[ifndef] sha1-n
+: sha1-n  ( datan$..data1$ n -- digest$ )
+   sha1-init
+   0  ?do  sha1-update  loop
+   sha1-final
+   sha1-digest /sha1-digest		( digest$ )
+;
+[then]
 : hmac-sha1  ( datan$..data1$ n key$ -- digest$ )
-   ?sha1-reset-key			( datan$..data1$ n key$' )
-   2dup key>keypad >r >r		( datan$..data1$ n )  ( R: key$ )
+   ?sha1-reset-key 2>r			( datan$..data1$ n )  ( R: key$' )
 
    \ sha1-idigest = SHA1(K XOR ipad, text)
-   keypad h# 36 xor-keypad		( datan$..data1$ n )  ( R: key$ )
-   sha1-init				( datan$..data1$ n )  ( R: key$ )
-   keypad /keypad sha1-update		( datan$..data1$ n )  ( R: key$ )
-   0  ?do  sha1-update  loop		( )  ( R: key$ )
-   sha1-final				( )  ( R: key$ )
-   sha1-digest sha1-idigest /sha1-digest move	( )  ( R: key$ )
+   2r@ key>keypad			( datan$..data1$ n )  ( R: key$ )
+   keypad h# 36 xor-keypad		( datan$..data1$ n )
 
-   \ sha1-digest = SHA1(K XOR opad, sha1-idigest)
-   r> r> key>keypad			( )
+   keypad /keypad  rot 1+  sha1-n	( digest$ )	      ( R: key$ )
+   sha1-idigest swap move		( )		      ( R: key$ )
+
+   2r> key>keypad			( )
    keypad h# 5c xor-keypad
-   sha1-init
-   keypad /keypad sha1-update
-   sha1-idigest /sha1-digest sha1-update
-   sha1-final
 
-   sha1-digest /sha1-digest		( digest$ )
+   sha1-idigest /sha1-digest  keypad /keypad  2  sha1-n	( digest$ )
 ;
 
 \ ----------------------------------------------------------------------------
@@ -74,8 +75,8 @@
 /sha1-digest buffer: temp			\ Last digest
 /sha1-digest buffer: temp2			\ Current digest
 : (pbkdf2-sha1)  ( passphrase$ ssid$ -- )
-   2over >r >r					( passphrase$ ssid$ )  ( R: passphrase$ )
-   pbkdf2-cnt-buf 4 2swap 2 r> r> hmac-sha1	( passphrase$ digest$ )
+   2over 2>r					( passphrase$ ssid$ )  ( R: passphrase$ )
+   pbkdf2-cnt-buf 4 2swap 2 2r> hmac-sha1	( passphrase$ digest$ )
    temp2 swap move				( passphrase$ )
    d# 4096 1  do
       sha1-digest temp /sha1-digest move	( passphrase$ )
@@ -89,8 +90,8 @@
    0 to pbkdf2-cnt
    begin  dup 0>  while			( passphrase$ ssid$ psk$ )
       pbkdf2-cnt++		 	( passphrase$ ssid$ psk$ )
-      >r >r 2over 2over (pbkdf2-sha1)	( passphrase$ ssid$ )  ( R: psk$ )
-      r> r> 2dup /sha1-digest min sha1-digest -rot move	( passphrase$ ssid$ psk$ )
+      2>r 2over 2over (pbkdf2-sha1)	( passphrase$ ssid$ )  ( R: psk$ )
+      2r> 2dup /sha1-digest min sha1-digest -rot move	( passphrase$ ssid$ psk$ )
       /sha1-digest /string		( passphrase$ ssid$ psk$' )
    repeat  2drop 2drop 2drop		( )
 ;
@@ -101,15 +102,14 @@
 : sha1-prf  ( key$ label$ data$ result$ -- )
    0 prf-cnt c!
    begin  dup 0>  while			( key$ label$ data$ result$ )
-      >r >r 		 		( key$ label$ data$ )  ( R: result$ )
+      2>r 		 		( key$ label$ data$ )  ( R: result$ )
       prf-cnt 1 2over zero$		( key$ label$ data$ cnt$ data$ zero$ )  ( R: result$ )
       9 pick 9 pick 4			( key$ label$ data$ cnt$ data$ zero$ label$ n )  ( R: result$ )
       d# 14 pick d# 14 pick hmac-sha1	( key$ label$ data$ digest$ )  ( R: result$ )
-      r> r> 2swap 2over rot min move	( key$ label$ data$ result$ )
+      2r> 2swap 2over rot min move	( key$ label$ data$ result$ )
       /sha1-digest /string		( key$ label$ data$ result$' )
       prf-cnt c@ 1+ prf-cnt c!		( key$ label$ data$ result$ )
    repeat  2drop 2drop 2drop 2drop	( )
-  
 ;
 
 



More information about the openfirmware mailing list