[openfirmware] [commit] r2004 - cpu/arm/marvell cpu/arm/mmp2 cpu/arm/olpc/1.75 dev/mmc/sdhci/mv8686 ofw/wifi
repository service
svn at openfirmware.info
Wed Nov 3 10:41:00 CET 2010
Author: wmb
Date: Wed Nov 3 10:40:59 2010
New Revision: 2004
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2004
Log:
OLPC XO-1.75 - Added hashing support using Marvell's accelerator hardware, and made the WLAN work.
Added:
cpu/arm/mmp2/hash.fth
cpu/arm/olpc/1.75/sd8686.bth
dev/mmc/sdhci/mv8686/loadpkg.fth
ofw/wifi/hmacsha1.fth
Modified:
cpu/arm/marvell/utmiphy.fth
cpu/arm/olpc/1.75/boardgpio.fth
cpu/arm/olpc/1.75/fw-version.fth
cpu/arm/olpc/1.75/fw.bth
cpu/arm/olpc/1.75/olpc.bth
cpu/arm/olpc/1.75/prefw.bth
cpu/arm/olpc/1.75/sdhci.fth
dev/mmc/sdhci/mv8686/mv8686.bth
ofw/wifi/loadpkg.fth
ofw/wifi/sha1.fth
Modified: cpu/arm/marvell/utmiphy.fth
==============================================================================
--- cpu/arm/marvell/utmiphy.fth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/marvell/utmiphy.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -16,21 +16,36 @@
loop
." PLL calibrate timeout" cr
;
+h# 7e03.ffff value pll-clr \ PLLCALI12, PLLVDD18, PLLVDD12, KVCO, ICP, FBDIV, REFDIV,
+h# 7e01.aeeb value pll-set \ 3 3 3 3 2 ee b
+
+h# 00df.c000 value tx-clr \ TXVDD12, CK60_PHSEL, IMPCAL_VTH
+h# 00c9.4000 value tx-set \ 3 4 5
+
+h# 0001.80f0 value rx-clr \ REG_SQ_LENGTH, RX_SQ_THRESH
+h# 0001.000a value rx-set \ 2 a
+
: init-usb-phy ( -- )
+[ifdef] notdef
+ ." Interacting before USB PHY init." cr
+ ." Change pll-set, tx-set, rx-set as desired then type 'resume'" cr
+ interact
+[then]
+
\ Turn on the USB PHY power
h# 1010.0000 utmi-ctrl regset \ INPKT_DELAY_SOF, PU_REF
h# 2 utmi-ctrl regset \ PLL_PWR_UP
h# 1 utmi-ctrl regset \ PWR_UP
\ Configure the PLLs
- h# 7e03.ffff utmi-pll regclr \ PLLCALI12, PLLVDD18, PLLVDD12, KVCO, ICP, FBDIV, REFDIV,
- h# 7e01.aeeb utmi-pll regset \ 3 3 3 3 2 ee b
+ pll-clr utmi-pll regclr \ PLLCALI12, PLLVDD18, PLLVDD12, KVCO, ICP, FBDIV, REFDIV,
+ pll-set utmi-pll regset \ 3 3 3 3 2 ee b
- h# 00df.c000 utmi-tx regclr \ TXVDD12, CK60_PHSEL, IMPCAL_VTH
- h# 00c9.4000 utmi-tx regset \ 3 4 5
+ tx-clr utmi-tx regclr \ TXVDD12, CK60_PHSEL, IMPCAL_VTH
+ tx-set utmi-tx regset \ 3 4 5
- h# 0001.80f0 utmi-rx regclr \ REG_SQ_LENGTH, RX_SQ_THRESH
- h# 0001.000a utmi-rx regset \ 2 a
+ rx-clr utmi-rx regclr \ REG_SQ_LENGTH, RX_SQ_THRESH
+ rx-set utmi-rx regset \ 2 a
d# 10000 wait-cal
@@ -45,4 +60,5 @@
h# 0000.1000 utmi-tx regclr
d# 1000 wait-cal
+\ ." UTMI calibration done" cr
;
Added: cpu/arm/mmp2/hash.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/mmp2/hash.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -0,0 +1,175 @@
+\ See license at end of file
+purpose: Hashes (MD5, SHA1, SHA-256) using Marvell hardware acceleration
+
+h# 8101 constant dval
+: dma>hash ( adr len -- )
+ 4 round-up 2 rshift h# d429080c l! ( adr )
+ h# d4290808 l! ( )
+ dval h# d4290800 l! ( )
+\ begin h# d4290814 l@ 1 and until
+;
+: dma-stop h# d4290800 l@ 1 invert and h# d4290800 l! ;
+: swap-axi-bytes ( -- ) h# 5 h# d4290838 l! ; \ Byte swap input and output
+: in-fifo-remain ( -- n ) h# d429083c l@ ;
+\ : in-fifo@ ( -- n ) h# d4290880 l@ ;
+\ : in-fifo! ( n -- ) h# d4290880 l! ;
+\ : out-fifo@ ( -- n ) h# d4290900 l@ ;
+\ : out-fifo! ( n -- ) h# d4290900 l! ;
+
+h# 40 value /hash-block
+d# 20 value /hash-digest
+/hash-block 2* buffer: (hash-buf)
+: hash-buf ( -- adr ) (hash-buf) /hash-block round-up ; \ Aligned
+0 value #hash-buf
+0 value #hashed
+
+: use-sha1 ( -- ) 0 h# d4291800 l! d# 20 to /hash-digest ;
+: use-sha256 ( -- ) 1 h# d4291800 l! d# 32 to /hash-digest ;
+: use-sha224 ( -- ) 2 h# d4291800 l! d# 28 to /hash-digest ;
+: use-md5 ( -- ) 3 h# d4291800 l! d# 16 to /hash-digest ;
+
+: hash-control! ( n -- ) h# d4291804 l! ;
+: hash-go ( -- )
+ 1 h# d4291808 l!
+ begin h# d429180c l@ 1 and until
+ 1 h# d429180c l!
+;
+: set-msg-size ( n -- )
+ 0 h# d429181c l! \ High word of total size
+ h# d4291818 l! \ Low word of total size
+;
+: hash-init ( -- )
+ 1 h# d4290c00 l! \ Select hash (0) for Accelerator A, crossing to direct DMA to it
+ dma-stop
+ 8 hash-control! \ Reset
+ 0 hash-control! \ Unreset
+ 1 hash-control! \ Init digest
+ hash-go
+ 0 to #hash-buf
+ 0 to #hashed
+;
+
+: hash-update-step ( -- )
+ hash-buf /hash-block dma>hash ( )
+ /hash-block h# d4291810 l! ( )
+ 2 hash-control! \ Update digest ( )
+ hash-go ( )
+ dma-stop
+;
+: copy-to-hashbuf ( adr thislen -- )
+ tuck ( adr thislen )
+ hash-buf #hash-buf + swap move ( thislen )
+ #hash-buf + to #hash-buf ( )
+ #hash-buf /hash-block = if ( )
+ hash-update-step ( )
+ 0 to #hash-buf
+ then
+;
+: hash-update ( adr len -- adr' len' )
+ dup #hashed + to #hashed ( adr len )
+ begin dup while ( adr len )
+ 2dup /hash-block #hash-buf - min ( adr len adr this )
+ tuck copy-to-hashbuf ( adr len this )
+ /string ( adr' len' )
+ repeat ( adr len )
+ 2drop
+;
+: hash-final ( -- )
+ #hashed set-msg-size ( )
+ #hash-buf h# d4291810 l! ( )
+ #hash-buf if
+ hash-buf #hash-buf dma>hash ( )
+ then
+ 7 hash-control! \ Final, with hardware padding
+ hash-go
+ dma-stop
+ h# d4291820 /hash-digest
+;
+: hash1 ( adr len -- )
+ hash-init ( adr len )
+ hash-update ( adr' len' )
+ hash-final
+;
+0 [if]
+: hash2 ( adr1 len1 adr2 len2 -- digest$ )
+ third over + >r ( adr1 len1 adr2 len2 r: total-len )
+ hash-init ( adr1 len1 adr2 len2 r: total-len )
+ 2swap hash-update ( adr2 len2 r: total-len )
+ hash-update ( r: total-len )
+ r> hash-done ( digest$ )
+;
+[then]
+
+: md5 ( adr len -- digest$ ) use-md5 hash1 ;
+\ alias $md5digest1 md5
+
+\ : $md5digest2 ( adr1 len1 adr2 len2 -- digest$ ) use-md5 hash2 ;
+
+: sha-256 ( adr len -- digest$ ) use-sha256 hash1 ;
+
+: sha1 ( adr len -- digest$ ) use-sha1 hash1 ;
+
+\ The following interface is for the benefit of ofw/wifi/hmacsha1.fth
+d# 20 constant /sha1-digest
+0 value sha1-digest
+: sha1-init use-sha1 hash-init ;
+: sha1-update hash-update ;
+: sha1-final hash-final drop to sha1-digest ;
+
+: ebg-set ( n -- ) h# d4292c00 l@ or h# d4292c00 l! ;
+: ebg-clr ( n -- ) invert h# d4292c00 l@ and h# d4292c00 l! ;
+
+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-digital ( -- )
+ h# 21117c0 h# d4292c00 l!
+;
+[then]
+
+: random-short ( -- w )
+ begin h# d4292c04 l@ dup 0>= while drop repeat
+ h# ffff and
+;
+: random-long ( -- l )
+ random-short random-short wljoin
+;
+
+\ 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/boardgpio.fth
==============================================================================
--- cpu/arm/olpc/1.75/boardgpio.fth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/olpc/1.75/boardgpio.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -18,6 +18,7 @@
d# 33 gpio-dir-out \ EN_MSD_PWR
d# 34 gpio-dir-out \ EN_WLAN_PWR
d# 35 gpio-dir-out \ EN_SD_PWR
+ d# 57 gpio-set \ WLAN_PD#
d# 57 gpio-dir-out \ WLAN_PD#
d# 58 gpio-set \ WLAN_RESET#
d# 58 gpio-dir-out \ WLAN_RESET#
Modified: cpu/arm/olpc/1.75/fw-version.fth
==============================================================================
--- cpu/arm/olpc/1.75/fw-version.fth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/olpc/1.75/fw-version.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -1,3 +1,3 @@
\ The overall firmware revision
macro: FW_MAJOR A
-macro: FW_MINOR 01
+macro: FW_MINOR 02
Modified: cpu/arm/olpc/1.75/fw.bth
==============================================================================
--- cpu/arm/olpc/1.75/fw.bth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/olpc/1.75/fw.bth Wed Nov 3 10:40:59 2010 (r2004)
@@ -260,6 +260,19 @@
quit
;
+: newrom
+ " flash! http:\\10.20.0.14\new.rom" eval
+\ " wifi media lab 802.11" eval
+\ " flash http:\\18.85.46.172\new.rom" eval
+;
+: urom " flash! u:\new.rom" eval ;
+: erom " flash! ext:\new.rom" eval ;
+: no-usb-delay " dev /usb false to delay? dend" evaluate ;
+: null-fsdisk
+ " dev /null : write-blocks-start 3drop ; : write-blocks-finish ; dend" evaluate
+ " devalias fsdisk //null" evaluate
+;
+
\ tag-file @ fclose tag-file off
.( --- Saving fw.dic ...)
Modified: cpu/arm/olpc/1.75/olpc.bth
==============================================================================
--- cpu/arm/olpc/1.75/olpc.bth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/olpc/1.75/olpc.bth Wed Nov 3 10:40:59 2010 (r2004)
@@ -2,6 +2,7 @@
command: &builder &this
in: ${BP}/cpu/arm/olpc/1.75/build/fw.img
+in: sd8686.bin
build-now
fload ${BP}/cpu/arm/olpc/1.75/fw-version.fth
@@ -76,10 +77,8 @@
" ${BP}/dev/mmc/sdhci/mv8686/build/mv8686.fc" " mv8686" $add-deflated-dropin
[then]
-0 [if]
" sd8686_helper.bin" " helper_sd.bin" $add-deflated-dropin
" sd8686.bin" " sd8686.bin" $add-deflated-dropin
-[then]
" builton.fth" " probe-" $add-dropin
Modified: cpu/arm/olpc/1.75/prefw.bth
==============================================================================
--- cpu/arm/olpc/1.75/prefw.bth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/olpc/1.75/prefw.bth Wed Nov 3 10:40:59 2010 (r2004)
@@ -173,18 +173,38 @@
fload ${BP}/ofw/inet/http.fth \ HTTP client
end-support-package
+support-package: cifs
+ fload ${BP}/ofw/fs/cifs/loadpkg.fth
+end-support-package
+devalias smb tcp//cifs
+devalias cifs tcp//cifs
+: op " select smb:\\test:testxxx at 10.20.0.14\XTest\hello.txt" eval ;
+: dsmb " dir smb:\\test:testxxx at 10.20.0.14\XTest\" eval ;
+
[ifdef] notyet
-fload ${BP}/cpu/x86/pc/olpc/memtest.fth
+fload ${BP}/cpu/arm/olpc/1.75/memtest.fth
[then]
-[ifdef] notyet
+fload ${BP}/cpu/arm/mmp2/hash.fth \ Hashes - SHA1, SHA-256, MD5
+
fload ${BP}/ofw/wifi/wifi-cfg.fth
support-package: supplicant
fload ${BP}/ofw/wifi/loadpkg.fth
end-support-package
-: ofw-ssids ( -- $ ) " OFWSSID" ;
-' ofw-ssids to default-ssids
+: olpc-ssids ( -- $ ) " OLPCOFW" ;
+' olpc-ssids to default-ssids
+
+[ifdef] notyet
+create use-thinmac
+fload ${BP}/cpu/x86/bootascall.fth
+fload ${BP}/cpu/x86/pc/olpc/wifichannel.fth
+fload ${BP}/cpu/x86/pc/olpc/via/nbtx.fth
+fload ${BP}/cpu/x86/pc/olpc/via/nbrx.fth
+fload ${BP}/cpu/x86/pc/olpc/via/blockfifo.fth
+fload ${BP}/cpu/x86/pc/olpc/via/fsupdate.fth
+fload ${BP}/cpu/x86/pc/olpc/via/fsverify.fth
+devalias fsdisk int:0
[then]
fload ${BP}/ofw/inet/sntp.fth
@@ -219,7 +239,6 @@
support-package: nfs
fload ${BP}/ofw/fs/nfs/loadpkg.fth
end-support-package
-
[then]
devalias nfs net//obp-tftp:last//nfs
Added: cpu/arm/olpc/1.75/sd8686.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/arm/olpc/1.75/sd8686.bth Wed Nov 3 10:40:59 2010 (r2004)
@@ -0,0 +1,31 @@
+purpose: Fetch the firmware for the Marvell 8686 wireless LAN module
+
+command: &builder &this
+build-now
+
+fload ${BP}/cpu/arm/olpc/1.75/wlan-version.fth
+
+" macro: WLAN_FILE lbtf_sdio-${WLAN_VERSION}" expand$ eval
+
+" ${GET_WLAN}" expand$ nip [if]
+ " ${GET_WLAN}" expand$ $sh
+[else]
+" rm -f sd8686.bin sd8686_helper.bin" expand$ $sh
+
+" wget -q http://dev.laptop.org/pub/firmware/libertas/thinfirm/${WLAN_FILE}.bin" expand$ $sh
+" wget -q http://dev.laptop.org/pub/firmware/libertas/thinfirm/${WLAN_FILE}.bin.md5" expand$ $sh
+" md5sum ${WLAN_FILE}.bin | cmp - ${WLAN_FILE}.bin.md5" expand$ $sh
+
+" mv ${WLAN_FILE}.bin sd8686.bin" expand$ $sh
+
+" wget -q http://dev.laptop.org/pub/firmware/libertas/sd8686_helper.bin" expand$ $sh
+" wget -q http://dev.laptop.org/pub/firmware/libertas/sd8686_helper.bin.md5" expand$ $sh
+" md5sum -b sd8686_helper.bin | cmp - sd8686_helper.bin.md5" expand$ $sh
+
+" rm ${WLAN_FILE}.bin.md5 sd8686_helper.bin.md5" expand$ $sh
+[then]
+
+\ This forces the creation of a .log file, so we don't re-fetch
+writing sd8686.version
+" ${WLAN_VERSION}"n" expand$ ofd @ fputs
+ofd @ fclose
Modified: cpu/arm/olpc/1.75/sdhci.fth
==============================================================================
--- cpu/arm/olpc/1.75/sdhci.fth Wed Nov 3 10:28:30 2010 (r2003)
+++ cpu/arm/olpc/1.75/sdhci.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -24,11 +24,6 @@
: gpio-power-off ( -- ) d# 35 gpio-clr sdhci-card-power-off ;
' gpio-power-off to card-power-off
-\ new-device
-\ 2 encode-int " reg" property
-\ " mv8686" " $load-driver" eval drop
-\ finish-device
-
new-device
1 encode-int " reg" property
fload ${BP}/dev/mmc/sdhci/sdmmc.fth
@@ -38,6 +33,36 @@
end-package
+0 0 " d4280800" " /" begin-package
+
+ fload ${BP}/cpu/arm/olpc/1.75/sdregs.fth
+ fload ${BP}/dev/mmc/sdhci/sdhci.fth
+
+ true to avoid-high-speed?
+
+ hex
+ \ The new clock divisor layout is low 8 bits in [15:8] and high 2 bits in [7:6]
+ \ The resulting 10-bit value is multiplied by 2 to form the divisor for the
+ \ 200 MHz base clock.
+ patch 403 103 card-clock-25 \ n is 4, divisor is 8, clk is 25 MHz
+ patch 203 003 card-clock-50 \ n is 2, divisor is 4, clk is 50 MHz
+ patch 043 8003 card-clock-slow \ n is h# 100 (high 2 bits in [7:6], for divisor of 512 from 200 MHz clock
+
+ ' true to card-inserted?
+
+ : gpio-power-on ( -- ) sdhci-card-power-on d# 34 gpio-set ;
+ ' gpio-power-on to card-power-on
+
+ : gpio-power-off ( -- ) d# 34 gpio-clr sdhci-card-power-off ;
+ ' gpio-power-off to card-power-off
+
+ new-device
+ 1 encode-int " reg" property
+ fload ${BP}/dev/mmc/sdhci/mv8686/loadpkg.fth
+ finish-device
+
+end-package
+
0 0 " d4281000" " /" begin-package
fload ${BP}/cpu/arm/olpc/1.75/sdregs.fth
@@ -73,6 +98,7 @@
stand-init: \ SDHC clocks
h# 41b h# d4282854 l! \ SD0 (external SD) clocks, plus set master clock divisor
+ h# 1b h# d4282858 l! \ SD1 (WLAN) clocks
h# 1b h# d42828e8 l! \ SD2 (internal microSD) clocks
h# 70a h# d4200104 l! \ Clock gating
h# 70a h# d4201104 l! \ Clock gating
Added: dev/mmc/sdhci/mv8686/loadpkg.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/mmc/sdhci/mv8686/loadpkg.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -0,0 +1,7 @@
+fload ${BP}/dev/mmc/sdhci/mv8686/common.fth \ Ethernet common variables and routines
+fload ${BP}/dev/mmc/sdhci/mv8686/ring.fth \ Receive ring management
+fload ${BP}/dev/mmc/sdhci/mv8686/sdio.fth \ SDIO interface routines
+fload ${BP}/dev/mmc/sdhci/mv8686/mv8686.fth \ SDIO I/O interface for Marvell 8686
+fload ${BP}/dev/libertas.fth \ Marvell "Libertas" common code
+fload ${BP}/dev/mmc/sdhci/mv8686/fw8686.fth \ Marvell firmware download for SDIO
+\ fload ${BP}/dev/mmc/sdhci/mv8686/wlan.fth \ External interface methods
Modified: dev/mmc/sdhci/mv8686/mv8686.bth
==============================================================================
--- dev/mmc/sdhci/mv8686/mv8686.bth Wed Nov 3 10:28:30 2010 (r2003)
+++ dev/mmc/sdhci/mv8686/mv8686.bth Wed Nov 3 10:40:59 2010 (r2004)
@@ -10,13 +10,7 @@
FCode-version2
-fload ${BP}/dev/mmc/sdhci/mv8686/common.fth \ Ethernet common variables and routines
-fload ${BP}/dev/mmc/sdhci/mv8686/ring.fth \ Receive ring management
-fload ${BP}/dev/mmc/sdhci/mv8686/sdio.fth \ SDIO interface routines
-fload ${BP}/dev/mmc/sdhci/mv8686/mv8686.fth \ SDIO I/O interface for Marvell 8686
-fload ${BP}/dev/libertas.fth \ Marvell "Libertas" common code
-fload ${BP}/dev/mmc/sdhci/mv8686/fw8686.fth \ Marvell firmware download for SDIO
-\ fload ${BP}/dev/mmc/sdhci/mv8686/wlan.fth \ External interface methods
+fload ${BP}/dev/mmc/sdhci/mv8686/loadpkg.fth
end0
Added: ofw/wifi/hmacsha1.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ ofw/wifi/hmacsha1.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -0,0 +1,139 @@
+purpose: HMAC-SHA1 used for WPA-PSK
+\ See license at end of file
+
+\ ----------------------------------------------------------------------------
+\ HMAC-SHA1 over data vector (RFC 2104)
+
+d# 64 constant /keypad
+/keypad buffer: keypad
+
+: xor-keypad ( adr c -- )
+ swap /keypad bounds do i c@ over xor i c! loop drop
+;
+: xor-digest ( src dst -- )
+ /sha1-digest bounds do ( src )
+ dup c@ i c@ xor i c! 1+ ( src' )
+ loop drop
+;
+
+: key>keypad ( key$ -- )
+ keypad /keypad erase
+ keypad swap move
+;
+
+\ sha1-digest = SHA1 (K XOR opad, SHA1(K XOR ipad, text))
+\ where K is an n byte key
+\ ipad is 64 0x36
+\ opad is 64 0x5c
+\ text is the data being protected
+\
+/sha1-digest buffer: sha1-idigest \ sha1-idigest = SHA1(K XOR ipad, text))
+/sha1-digest buffer: sha1-tkey
+: ?sha1-reset-key ( passphrase$ -- key$ )
+ dup d# 64 > if \ if len>64, key = SHA1(key)
+ sha1
+ sha1-tkey swap move \ Save new key
+ sha1-tkey /sha1-digest ( key$ )
+ 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-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$ )
+
+ \ sha1-digest = SHA1(K XOR opad, sha1-idigest)
+ r> r> 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-based key derivation function (PBKDF2) for IEEE 802.11i.
+\ This function is used to derive PSK for WPA-PSK, described in IEEE
+\ Std 802.11-2004, clause H.4. The main contruction is from PKCS#5 v 2.0.
+
+0 value pbkdf2-cnt
+4 buffer: pbkdf2-cnt-buf
+: pbkdf2-cnt++ ( -- )
+ pbkdf2-cnt 1+ dup to pbkdf2-cnt
+ pbkdf2-cnt-buf be-l!
+;
+
+/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$ )
+ temp2 swap move ( passphrase$ )
+ d# 4096 1 do
+ sha1-digest temp /sha1-digest move ( passphrase$ )
+ temp /sha1-digest 1 4 pick 4 pick hmac-sha1 ( passphrase$ digest$ )
+ drop temp2 xor-digest ( passphrase$ )
+ loop 2drop ( )
+ temp2 sha1-digest /sha1-digest move
+;
+
+: pbkdf2-sha1 ( passphrase$ ssid$ psk$ -- )
+ 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$ )
+ /sha1-digest /string ( passphrase$ ssid$ psk$' )
+ repeat 2drop 2drop 2drop ( )
+;
+
+create zero 0 c,
+create prf-cnt 0 c,
+: zero$ ( -- adr len ) zero 1 ;
+: 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$ )
+ 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$ )
+ /sha1-digest /string ( key$ label$ data$ result$' )
+ prf-cnt c@ 1+ prf-cnt c! ( key$ label$ data$ result$ )
+ repeat 2drop 2drop 2drop 2drop ( )
+
+;
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2007 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: ofw/wifi/loadpkg.fth
==============================================================================
--- ofw/wifi/loadpkg.fth Wed Nov 3 10:28:30 2010 (r2003)
+++ ofw/wifi/loadpkg.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -4,6 +4,7 @@
[ifdef] 386-assembler
fload ${BP}/ofw/wifi/sha1.fth
[then]
+fload ${BP}/ofw/wifi/hmacsha1.fth
fload ${BP}/ofw/wifi/aes.fth
fload ${BP}/ofw/wifi/md5.fth
fload ${BP}/ofw/wifi/rc4.fth
Modified: ofw/wifi/sha1.fth
==============================================================================
--- ofw/wifi/sha1.fth Wed Nov 3 10:28:30 2010 (r2003)
+++ ofw/wifi/sha1.fth Wed Nov 3 10:40:59 2010 (r2004)
@@ -309,117 +309,6 @@
init-'sha1
-\ ----------------------------------------------------------------------------
-\ HMAC-SHA1 over data vector (RFC 2104)
-
-d# 64 constant /keypad
-/keypad buffer: keypad
-
-: xor-keypad ( adr c -- )
- swap /keypad bounds do i c@ over xor i c! loop drop
-;
-: xor-digest ( src dst -- )
- /sha1-digest bounds do ( src )
- dup c@ i c@ xor i c! 1+ ( src' )
- loop drop
-;
-
-: key>keypad ( key$ -- )
- keypad /keypad erase
- keypad swap move
-;
-
-\ sha1-digest = SHA1 (K XOR opad, SHA1(K XOR ipad, text))
-\ where K is an n byte key
-\ ipad is 64 0x36
-\ opad is 64 0x5c
-\ text is the data being protected
-\
-/sha1-digest buffer: sha1-idigest \ sha1-idigest = SHA1(K XOR ipad, text))
-/sha1-digest buffer: sha1-tkey
-: ?sha1-reset-key ( passphrase$ -- key$ )
- dup d# 64 > if \ if len>64, key = SHA1(key)
- sha1
- sha1-tkey swap move \ Save new key
- sha1-tkey /sha1-digest ( key$ )
- 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-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$ )
-
- \ sha1-digest = SHA1(K XOR opad, sha1-idigest)
- r> r> 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-based key derivation function (PBKDF2) for IEEE 802.11i.
-\ This function is used to derive PSK for WPA-PSK, described in IEEE
-\ Std 802.11-2004, clause H.4. The main contruction is from PKCS#5 v 2.0.
-
-0 value pbkdf2-cnt
-4 buffer: pbkdf2-cnt-buf
-: pbkdf2-cnt++ ( -- )
- pbkdf2-cnt 1+ dup to pbkdf2-cnt
- pbkdf2-cnt-buf be-l!
-;
-
-/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$ )
- temp2 swap move ( passphrase$ )
- d# 4096 1 do
- sha1-digest temp /sha1-digest move ( passphrase$ )
- temp /sha1-digest 1 4 pick 4 pick hmac-sha1 ( passphrase$ digest$ )
- drop temp2 xor-digest ( passphrase$ )
- loop 2drop ( )
- temp2 sha1-digest /sha1-digest move
-;
-
-: pbkdf2-sha1 ( passphrase$ ssid$ psk$ -- )
- 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$ )
- /sha1-digest /string ( passphrase$ ssid$ psk$' )
- repeat 2drop 2drop 2drop ( )
-;
-
-create zero 0 c,
-create prf-cnt 0 c,
-: zero$ ( -- adr len ) zero 1 ;
-: 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$ )
- 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> 2tuck 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 ( )
-
-;
-
\ LICENSE_BEGIN
\ Copyright (c) 2007 FirmWorks
More information about the openfirmware
mailing list