📄 sha1prog.psm
字号:
; KCPSM3 Program - Implementation of the SHA-1 algorithm for use with the
; DS2432 secure memory on the Spartan-3E Starter Kit.
;
; Ken Chapman - Xilinx Ltd
;
; Version v1.00 - 19th April 2006
;
;
; IMPORTANT - This design builds on the reference design called "PicoBlaze
; DS2432 communicator". It is highly recommend that you look at that
; design before proceeding with this one.
;
;
; This program uses a 9600 baud UART connection to allow communication with the
; 1-wire interface of the DS2432 memory device from Dallas Semiconductor.
;
; The program only supports a limited number of the DS2432 commands to focus on
; those aspects which use the SHA-1 algorithm.
;
; Note that the code performing the SHA-1 algorithm interacts with the hardware of
; this complete reference design. The hardware provides a 16 word (32-bit) buffer
; combined used in the initialisation of the algorithm and subsequent computation
; of the Wt words.
;
;
; The DS2432 should be programmed with a 64-bit secret. The following constants
; define the secret which will be used. Obviously this would be be changed in a
; real application and further measures taken to prevent it easily being found.
; The secret is 64-bits formed of 8 bytes. 'secret0' would be stored at address
; 0080 of the DS2432 and 'secret7' at address 0087. The write buffer and load
; first secret commands allow you to set any secret into the DS2432 device but
; this program always uses the secret defined in these constants such that you can
; experiment with secrets which do and do not match.
;
;
CONSTANT secret0, 01
CONSTANT secret1, 23
CONSTANT secret2, 45
CONSTANT secret3, 67
CONSTANT secret4, 89
CONSTANT secret5, AB
CONSTANT secret6, CD
CONSTANT secret7, EF
;
;
; Bytes 4, 5 and 6 of the DS2432 scratch pad memory are used in the SHA-1 algorithm.
; These should be set using the write scratchpad memory command before using the
; read authenticated page command. HOWEVER, it is also important that you also use
; the read scratchpad command BEFORE using the read authenticated page command. This
; is because this program only copies the bytes 4, 5 and 6 during a read such that
; they are can be used by the PicoBlaze SHA-1 algorithm. This limitation is deliberate
; so that you can experiment and prove that the SHA-1 results will not match if
; the same 'challenge' bytes are not used.
;
;
;**************************************************************************************
; Port definitions
;**************************************************************************************
;
;
CONSTANT status_port, 40 ;UART status input
CONSTANT tx_half_full, 01 ; Transmitter half full - bit0
CONSTANT tx_full, 02 ; FIFO full - bit1
CONSTANT rx_data_present, 04 ; Receiver data present - bit2
CONSTANT rx_half_full, 08 ; FIFO half full - bit3
CONSTANT rx_full, 10 ; full - bit4
CONSTANT spare1, 20 ; spare '0' - bit5
CONSTANT spare2, 40 ; spare '0' - bit6
CONSTANT spare3, 80 ; spare '0' - bit7
;
CONSTANT UART_read_port, 80 ;UART Rx data input
;
CONSTANT UART_write_port, 04 ;UART Tx data output
;
;
CONSTANT DS_wire_in_port, C0 ;Read signal from DS2432 device
CONSTANT DS_wire_out_port, 08 ;Drive signal to DS2432 device (open collector)
CONSTANT DS_wire, 01 ; Signal is bit0 in both cases
;
;
;
; The following ports access the 'Wt' word buffer. This buffer holds 16 words
; of 32-bits organised as a 64-byte shift register. Hence each word is stored
; by writing 4 bytes. As each byte is written, all bytes shift along such that
; older Wt values can be read from consistent port addresses.
;
CONSTANT W_word_write_port, 10 ;Write byte to Wt buffer
;
CONSTANT Wt_minus3_byte0_read_port, 08 ;Read of Wt-3
CONSTANT Wt_minus3_byte1_read_port, 09
CONSTANT Wt_minus3_byte2_read_port, 0A
CONSTANT Wt_minus3_byte3_read_port, 0B
;
CONSTANT Wt_minus8_byte0_read_port, 1C ;Read of Wt-8
CONSTANT Wt_minus8_byte1_read_port, 1D
CONSTANT Wt_minus8_byte2_read_port, 1E
CONSTANT Wt_minus8_byte3_read_port, 1F
;
CONSTANT Wt_minus14_byte0_read_port, 34 ;Read of Wt-14
CONSTANT Wt_minus14_byte1_read_port, 35
CONSTANT Wt_minus14_byte2_read_port, 36
CONSTANT Wt_minus14_byte3_read_port, 37
;
CONSTANT Wt_minus16_byte0_read_port, 3C ;Read of Wt-16
CONSTANT Wt_minus16_byte1_read_port, 3D
CONSTANT Wt_minus16_byte2_read_port, 3E
CONSTANT Wt_minus16_byte3_read_port, 3F
;
;
;**************************************************************************************
; Special Register usage
;**************************************************************************************
;
NAMEREG sF, UART_data ;used to pass data to and from the UART
;
;
;**************************************************************************************
; Scratch Pad Memory Locations
;**************************************************************************************
;
; Scratch pad memory provides 64 bytes in the address range 00 to 3F hex.
;
;
; Locations for device family code, serial number and 8-bit CRC value
;
CONSTANT family_code, 00
CONSTANT serial_number0, 01 ;48-bit serial number LS-Byte first
CONSTANT serial_number1, 02
CONSTANT serial_number2, 03
CONSTANT serial_number3, 04
CONSTANT serial_number4, 05
CONSTANT serial_number5, 06
CONSTANT read_ROM_CRC, 07 ;8-bit CRC
;
;
; Locations for variables used in SHA-1 algorithm.
; Each variable is 32-bits and requires 4 bytes to store.
; '0' indicates the least significant byte and '3' the most significant byte.
;
; Note that the concatenation of 'A', 'B', 'C', 'D' and 'E' will be the 160-bit MAC.
;
CONSTANT var_A0, 08 ;Variable 'A'
CONSTANT var_A1, 09
CONSTANT var_A2, 0A
CONSTANT var_A3, 0B
;
CONSTANT var_B0, 0C ;Variable 'B'
CONSTANT var_B1, 0D
CONSTANT var_B2, 0E
CONSTANT var_B3, 0F
;
CONSTANT var_C0, 10 ;Variable 'C'
CONSTANT var_C1, 11
CONSTANT var_C2, 12
CONSTANT var_C3, 13
;
CONSTANT var_D0, 14 ;Variable 'D'
CONSTANT var_D1, 15
CONSTANT var_D2, 16
CONSTANT var_D3, 17
;
CONSTANT var_E0, 18 ;Variable 'E'
CONSTANT var_E1, 19
CONSTANT var_E2, 1A
CONSTANT var_E3, 1B
;
;
; Copy of data in the scratchpad memory of the DS2432.
; This is only updated by the read scratchpad memory command.
; '0' indicates the data in the least significant location.
;
CONSTANT scratchpad0, 1C
CONSTANT scratchpad1, 1D
CONSTANT scratchpad2, 1E
CONSTANT scratchpad3, 1F
CONSTANT scratchpad4, 20
CONSTANT scratchpad5, 21
CONSTANT scratchpad6, 22
CONSTANT scratchpad7, 23
;
;
;
;**************************************************************************************
; Useful data constants
;**************************************************************************************
;
; Constant to define a software delay of 1us. This must be adjusted to reflect the
; clock applied to KCPSM3. Every instruction executes in 2 clock cycles making the
; calculation highly predictable. The '6' in the following equation even allows for
; 'CALL delay_1us' instruction in the initiating code.
;
; delay_1us_constant = (clock_rate - 6)/4 Where 'clock_rate' is in MHz
;
; Example: For a 50MHz clock the constant value is (10-6)/4 = 11 (0B Hex).
; For clock rates below 10MHz the value of 1 must be used and the operation will
; become lower than intended.
;
CONSTANT delay_1us_constant, 0B
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -