📄 sha1prog.psm
字号:
CALL send_crc ;'CRC=' to display CRC value
FETCH s0, read_ROM_CRC
CALL send_hex_byte
CALL send_CR
CALL compute_CRC8 ;compute CRC value in s0
FETCH s1, read_ROM_CRC ;compare with received value
COMPARE s0, s1
JUMP NZ, crc8_fail
CALL send_Pass
RETURN
crc8_fail: CALL send_Fail
RETURN
;
;
;
;**************************************************************************************
; DS2432 Load First Secret Command.
;**************************************************************************************
;
; This command will only be valid if the write scratchpad memory command has previously
; been used to define the new secret to be stored at address 0080.
;
; The Load First Secret Command (5A hex) will only copy the scratchpad contents into ;
; the EEPROM array of the DS2432 if the address was correctly specified in the
; write scratchpad command. This routine will assume that the address specified
; was 0080. If everything is OK with the programming of the secret, the DS2432 responds
; with 'AA' hex after the command and this routine will report 'Pass'. You can further
; check using a read scratchpad command and look to see if E/S has changed from '5F'
; to 'DF' which indicates the successful write.
;
; Note that this program defines the secret to be used by the PicoBlaze SHA-1 algorithm
; in the constants 'secret0' through to 'secret7'. Only if you program the DS2432
; with a matching secret will the read authenticated message command result in a
; 'Pass' being reported for the MAC. This Load First Secret Command routine deliberately
; does not update the secret used by the PicoBlaze SHA-1 algorithm so that you can
; prove that only a DS2432 with the matching secret will generate matching MAC
; responses.
;
;
;
load_first_secret_command: LOAD s3, 5A ;Load First Secret Command
CALL write_byte_slow ;transmit command
LOAD s3, 80 ;TA1 value for secret = 80 hex
CALL write_byte_slow
LOAD s3, 00 ;TA2 value for secret = 00 hex
CALL write_byte_slow
LOAD s3, 5F ;E/S value before writing = 5F hex
CALL write_byte_slow
CALL delay_20ms ;write takes place in 10ms
CALL send_CR
CALL send_secret
CALL send_space
CALL read_byte_slow ;read data into s3
COMPARE s3, AA ;test response
JUMP Z, secret_pass
CALL send_Fail
JUMP warm_start
secret_pass: CALL send_Pass
JUMP warm_start
;
;
;**************************************************************************************
; DS2432 Write Scratchpad Memory Command.
;**************************************************************************************
;
; The write scratchpad memory command (0F hex) allows 8-bytes of data to be written
; together with a target address for final storage in the main memory map. The
; DS2432 scratch pad is also used to define a 3 byte 'challenge' used in the
; SHA-1 algorithm.
;
; The DS2432 provides an initial confirmation of the write by returning a 16-bit CRC
; value which KCPSM3 tests. The CRC is computed based on the command, address and
; data transmitted (11 bytes). PicoBlaze also computes the CRC and and tests this
; against the value received from the DS2432.
;
; This routine prompts the user to enter the 16-bit target address is to be loaded
; into the target address registers TA2 and TA1 in the DS2432 device. Note that only
; address values below 0090 hex are valid. If the address is too high, then the
; DS2432 aborts the command and this routine will too.
;
; Also note that the address will be forced internally to the DS2432 to match an
; 8-byte boundary address in which the least significant 3-bits are reset to '000'
; regardless of the address provided. The CRC still reflects the transmitted address.
;
; After providing a valid address, the routine then prompts the user to enter
; 8 bytes of data which are written to the DS2432.
;
;
;
write_scratchpad_command: CALL clear_CRC16 ;prepare CRC registers [sE,sD]
LOAD s3, 0F ;write scratchpad memory Command
CALL write_byte_slow ;transmit command
CALL compute_CRC16 ;compute CRC for value in 's3'
wsc_addr_loop: CALL send_address ;obtain 16-bit address 0000 to FFFF in [s5,s4]
CALL obtain_8bits
JUMP C, wsc_addr_loop ;bad input address
LOAD s5, s0
CALL obtain_8bits
JUMP C, wsc_addr_loop ;bad input address
LOAD s4, s0
LOAD s3, s4 ;transmit target address TA1 (LS-Byte)
CALL write_byte_slow
CALL compute_CRC16 ;compute CRC for value in 's3'
LOAD s3, s5 ;transmit target address TA2 (MS-Byte)
CALL write_byte_slow
CALL compute_CRC16 ;compute CRC for value in 's3'
COMPARE s5, 00 ;check address less than 0090 hex
JUMP NZ, warm_start ;DS2432 aborts command and so do we!
COMPARE s4, 90 ;no need to read data bytes.
JUMP NC, warm_start
LOAD s4, 00 ;initialise byte counter
wsc_data_loop: CALL send_data ;obtain a byte of data
LOAD UART_data, s4 ;display which byte requested
ADD UART_data, character_0 ;convert to ASCII
CALL send_to_UART
CALL send_equals
CALL obtain_8bits
JUMP C, wsc_data_loop ;bad input data
LOAD s3, s0 ;transmit byte
CALL write_byte_slow
CALL compute_CRC16 ;compute CRC for value in 's3'
ADD s4, 01 ;count bytes
COMPARE s4, 08
JUMP NZ, wsc_data_loop
CALL send_CR
CALL read_send_test_CRC16 ;read, display and test CRC value
JUMP warm_start
;
;
;
;**************************************************************************************
; DS2432 Read Scratchpad Memory Command.
;**************************************************************************************
;
; The read scratchpad memory command (AA hex) allows the 8-bytes of data previously
; to be written into the scratchpad memory to be read back for verification together with
; the target address, a transfer status register (E/S) and a 16-bit CRC value.
;
; The 16-bit CRC is formed of the command byte, address TA1 and TA2, E/S byte and 8 data
; bytes as transmitted (12 bytes). These may not be the same as the values provided
; during a previous write to scratchpad memory. PicoBlaze also computes the CRC and
; and tests this against the value received from the DS2432.
;
; The 8 bytes of data are also copied to PicoBlaze memory at locations defined by the
; constants 'scratchpad0' to 'scratchpad7'. Three bytes are used as a 'challenge'
; by the SHA-1 algorithm.
;
;
;
read_scratchpad_command: CALL clear_CRC16 ;prepare CRC registers [sE,sD]
LOAD s3, AA ;read scratchpad memory Command
CALL write_byte_slow ;transmit command
CALL compute_CRC16 ;compute CRC for value in 's3'
CALL send_address ;display 'Address='
CALL read_byte_slow ;read address into [s5,s4]
CALL compute_CRC16 ;compute CRC for value in 's3'
LOAD s4, s3
CALL read_byte_slow
CALL compute_CRC16 ;compute CRC for value in 's3'
LOAD s5, s3
LOAD s0, s5 ;display address
CALL send_hex_byte
LOAD s0, s4
CALL send_hex_byte
CALL send_ES ;display 'E/S='
CALL read_byte_slow ;read E/S register
CALL compute_CRC16 ;compute CRC for value in 's3'
LOAD s0, s3 ;display value
CALL send_hex_byte
CALL send_data ;display 'Data='
CALL send_equals
LOAD s4, scratchpad0 ;pointer to memory and byte counter
rsc_loop: CALL send_space
CALL read_byte_slow ;read data byte
CALL compute_CRC16 ;compute CRC for value in 's3'
STORE s3, (s4) ;store value in memory
LOAD s0, s3 ;display value
CALL send_hex_byte
COMPARE s4, scratchpad7 ;count bytes
JUMP Z, end_rsc_data_loop
ADD s4, 01
JUMP rsc_loop
end_rsc_data_loop: CALL send_CR
CALL read_send_test_CRC16 ;read, display and test CRC value
JUMP warm_start
;
;
;
;
;
;**************************************************************************************
; DS2432 Read Authenticated Page Command.
;**************************************************************************************
;
; The read authenticated page command (A5 hex) allows the 8-byte secret to be tested
; without it actually being read (which would obviously give away the secret!).
;
; This routine has been written to work with page 0 but could easily be changed and
; is documented below. During the first part of the command, the 32 bytes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -