sha1prog.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,559 行 · 第 1/5 页
RMH
1,559 行
3001d // @007 #315: CALL(read_ROM_command) ;read ROM command and display results// #316: ;// #317: ; After a valid ROM command the DS2432 specific memory commands and SHA-1// #318: ; functions become accessible. This program assumes that the ROM command did// #319: ; 'Pass' so you will need to check yourself. If this program automatically// #320: ; reset the DS2432 and tried again and there was a fault it would just cause// #321: ; the display to roll continuously and not be very informative!// #322: ;// #323: ; Each of the DS2432 commands selected from the menu will require the master reset// #324: ; and read ROM command to be repeated before being able to proceed with the next// #325: ; memory or SHA-1 function. This is automated by the program.// #326: ;// #327: ;// @008 #328: [DS2432_menu]30344 // @008 #328: CALL(send_DS2432_menu) ;Menu and command selection302ec // @009 #329: CALL(send_CR)// #330: ;// @00a #331: [DS2432_prompt]302ec // @00a #331: CALL(send_CR) ;prompt for user input302ec // @00b #332: CALL(send_CR)00f3e // @00c #333: LOAD(UART_data,character_greater_than) ;prompt for input302a5 // @00d #334: CALL(send_to_UART)302e1 // @00e #335: CALL(read_upper_case)14031 // @00f #336: COMPARE(s0,character_1) ;test for commands and execute as required35053 // @010 #337: JUMP(Z,write_scratchpad_command)14032 // @011 #338: COMPARE(s0,character_2)35079 // @012 #339: JUMP(Z,read_scratchpad_command)14033 // @013 #340: COMPARE(s0,character_3)35040 // @014 #341: JUMP(Z,load_first_secret_command)14034 // @015 #342: COMPARE(s0,character_4)3509d // @016 #343: JUMP(Z,read_auth_page_command)302ec // @017 #344: CALL(send_CR) ;no valid command input00f3f // @018 #345: LOAD(UART_data,character_question) ;display ???302a5 // @019 #346: CALL(send_to_UART)302a5 // @01a #347: CALL(send_to_UART)302a5 // @01b #348: CALL(send_to_UART)3400a // @01c #349: JUMP(DS2432_prompt) ;Try again!// #350: ;// #351: ;// #352: ;// #353: ;// #354: ;**************************************************************************************// #355: ; DS2432 Read ROM Command.// #356: ;**************************************************************************************// #357: ;// #358: ; The read ROM command (33 hex) allows the 8-bit family code, 48-bit unique serial// #359: ; number and 8-bit CRC to be read from the DS2432 device.// #360: ;// #361: ; This routine reads the values and places them in KCPSM3 scratch pad memory// #362: ; locations for future reference. These locations should be defined with constants// #363: ; as follows and MUST be in consecutive ascending locations.// #364: ;// #365: ; family_code// #366: ; Location to store family code which should be 33 hex// #367: ; serial_number0 to serial_number5// #368: ; 6 bytes to hold 48-bit serial number (LS-byte first).// #369: ; read_ROM_CRC// #370: ; 8-bit CRC value for the above data.// #371: ;// #372: ;// #373: ; The routine also displays the values read and performs a verification of the// #374: ; 8-bit CRC displaying a 'Pass' or 'Fail' message as appropriate.// #375: ;// @01d #376: [read_ROM_command]00333 // @01d #376: LOAD(s3,51) ;Read ROM Command3024e // @01e #377: CALL(write_byte_slow) ;transmit command00500 // @01f #378: LOAD(s5,family_code) ;memory pointer// @020 #379: [read_ROM_loop]3026f // @020 #379: CALL(read_byte_slow) ;read response into s32f350 // @021 #380: STORE(s3,s5) ;store value14507 // @022 #381: COMPARE(s5,read_ROM_CRC) ;8-bytes to read35026 // @023 #382: JUMP(Z,display_ROM)18501 // @024 #383: ADD(s5,1)34020 // @025 #384: JUMP(read_ROM_loop)// @026 #385: [display_ROM]302ec // @026 #385: CALL(send_CR)303d6 // @027 #386: CALL(send_code) ;'code=' to display family code06000 // @028 #387: FETCH(s0,family_code)302c2 // @029 #388: CALL(send_hex_byte)302ec // @02a #389: CALL(send_CR)303dc // @02b #390: CALL(send_sn) ;'s/n=' to display family code00506 // @02c #391: LOAD(s5,serial_number5) ;memory pointer starting MS-byte first// @02d #392: [disp_serial_loop]07050 // @02d #392: FETCH(s0,s5)302c2 // @02e #393: CALL(send_hex_byte)14501 // @02f #394: COMPARE(s5,serial_number0)35033 // @030 #395: JUMP(Z,end_serial)1c501 // @031 #396: SUB(s5,1)3402d // @032 #397: JUMP(disp_serial_loop)// @033 #398: [end_serial]302ec // @033 #398: CALL(send_CR)303e2 // @034 #399: CALL(send_crc) ;'CRC=' to display CRC value06007 // @035 #400: FETCH(s0,read_ROM_CRC)302c2 // @036 #401: CALL(send_hex_byte)302ec // @037 #402: CALL(send_CR)301f1 // @038 #403: CALL(compute_CRC8) ;compute CRC value in s006107 // @039 #404: FETCH(s1,read_ROM_CRC) ;compare with received value15010 // @03a #405: COMPARE(s0,s1)3543e // @03b #406: JUMP(NZ,crc8_fail)303ad // @03c #407: CALL(send_Pass)2a000 // @03d #408: RETURN// @03e #409: [crc8_fail]303b4 // @03e #409: CALL(send_Fail)2a000 // @03f #410: RETURN// #411: ;// #412: ;// #413: ;// #414: ;**************************************************************************************// #415: ; DS2432 Load First Secret Command.// #416: ;**************************************************************************************// #417: ;// #418: ; This command will only be valid if the write scratchpad memory command has previously// #419: ; been used to define the new secret to be stored at address 0080.// #420: ;// #421: ; The Load First Secret Command (5A hex) will only copy the scratchpad contents into ;// #422: ; the EEPROM array of the DS2432 if the address was correctly specified in the// #423: ; write scratchpad command. This routine will assume that the address specified// #424: ; was 0080. If everything is OK with the programming of the secret, the DS2432 responds// #425: ; with 'AA' hex after the command and this routine will report 'Pass'. You can further// #426: ; check using a read scratchpad command and look to see if E/S has changed from '5F'// #427: ; to 'DF' which indicates the successful write.// #428: ;// #429: ; Note that this program defines the secret to be used by the PicoBlaze SHA-1 algorithm// #430: ; in the constants 'secret0' through to 'secret7'. Only if you program the DS2432// #431: ; with a matching secret will the read authenticated message command result in a// #432: ; 'Pass' being reported for the MAC. This Load First Secret Command routine deliberately// #433: ; does not update the secret used by the PicoBlaze SHA-1 algorithm so that you can// #434: ; prove that only a DS2432 with the matching secret will generate matching MAC// #435: ; responses.// #436: ;// #437: ;// #438: ;// @040 #439: [load_first_secret_command]0035a // @040 #439: LOAD(s3,90) ;Load First Secret Command3024e // @041 #440: CALL(write_byte_slow) ;transmit command00380 // @042 #441: LOAD(s3,128) ;TA1 value for secret = 80 hex3024e // @043 #442: CALL(write_byte_slow)00300 // @044 #443: LOAD(s3,0) ;TA2 value for secret = 00 hex3024e // @045 #444: CALL(write_byte_slow)0035f // @046 #445: LOAD(s3,95) ;E/S value before writing = 5F hex3024e // @047 #446: CALL(write_byte_slow)30295 // @048 #447: CALL(delay_20ms) ;write takes place in 10ms302ec // @049 #448: CALL(send_CR)30391 // @04a #449: CALL(send_secret)302ef // @04b #450: CALL(send_space)3026f // @04c #451: CALL(read_byte_slow) ;read data into s3143aa // @04d #452: COMPARE(s3,AA) ;test response35051 // @04e #453: JUMP(Z,secret_pass)303b4 // @04f #454: CALL(send_Fail)34003 // @050 #455: JUMP(warm_start)// @051 #456: [secret_pass]303ad // @051 #456: CALL(send_Pass)34003 // @052 #457: JUMP(warm_start)// #458: ;// #459: ;// #460: ;**************************************************************************************// #461: ; DS2432 Write Scratchpad Memory Command.// #462: ;**************************************************************************************// #463: ;// #464: ; The write scratchpad memory command (0F hex) allows 8-bytes of data to be written// #465: ; together with a target address for final storage in the main memory map. The// #466: ; DS2432 scratch pad is also used to define a 3 byte 'challenge' used in the// #467: ; SHA-1 algorithm.// #468: ;// #469: ; The DS2432 provides an initial confirmation of the write by returning a 16-bit CRC// #470: ; value which KCPSM3 tests. The CRC is computed based on the command, address and// #471: ; data transmitted (11 bytes). PicoBlaze also computes the CRC and and tests this// #472: ; against the value received from the DS2432.// #473: ;// #474: ; This routine prompts the user to enter the 16-bit target address is to be loaded// #475: ; into the target address registers TA2 and TA1 in the DS2432 device. Note that only// #476: ; address values below 0090 hex are valid. If the address is too high, then the// #477: ; DS2432 aborts the command and this routine will too.// #478: ;// #479: ; Also note that the address will be forced internally to the DS2432 to match an// #480: ; 8-byte boundary address in which the least significant 3-bits are reset to '000'// #481: ; regardless of the address provided. The CRC still reflects the transmitted address.// #482: ;// #483: ; After providing a valid address, the routine then prompts the user to enter// #484: ; 8 bytes of data which are written to the DS2432.// #485: ;// #486: ;// #487: ;// @053 #488: [write_scratchpad_command]3020b // @053 #488: CALL(clear_CRC16) ;prepare CRC registers [sE,sD]0030f // @054 #489: LOAD(s3,15) ;write scratchpad memory Command3024e // @055 #490: CALL(write_byte_slow) ;transmit command3020e // @056 #491: CALL(compute_CRC16) ;compute CRC for value in 's3'// @057 #492: [wsc_addr_loop]303bd // @057 #492: CALL(send_address) ;obtain 16-bit address 0000 to FFFF in [s5,s4]302e6 // @058 #493: CALL(obtain_8bits)35857 // @059 #494: JUMP(C,wsc_addr_loop) ;bad input address01500 // @05a #495: LOAD(s5,s0)302e6 // @05b #496: CALL(obtain_8bits)35857 // @05c #497: JUMP(C,wsc_addr_loop) ;bad input address01400 // @05d #498: LOAD(s4,s0)01340 // @05e #499: LOAD(s3,s4) ;transmit target address TA1 (LS-Byte)3024e // @05f #500: CALL(write_byte_slow)3020e // @060 #501: CALL(compute_CRC16) ;compute CRC for value in 's3'01350 // @061 #502: LOAD(s3,s5) ;transmit target address TA2 (MS-Byte)3024e // @062 #503: CALL(write_byte_slow)3020e // @063 #504: CALL(compute_CRC16) ;compute CRC for value in 's3'14500 // @064 #505: COMPARE(s5,0) ;check address less than 0090 hex35403 // @065 #506: JUMP(NZ,warm_start) ;DS2432 aborts command and so do we!14490 // @066 #507: COMPARE(s4,144) ;no need to read data bytes.35c03 // @067 #508: JUMP(NC,warm_start)00400 // @068 #509: LOAD(s4,0) ;initialise byte counter// @069 #510: [wsc_data_loop]303c8 // @069 #510: CALL(send_data) ;obtain a byte of data01f40 // @06a #511: LOAD(UART_data,s4) ;display which byte requested18f30 // @06b #512: ADD(UART_data,character_0) ;convert to ASCII302a5 // @06c #513: CALL(send_to_UART)303c5 // @06d #514: CALL(send_equals)302e6 // @06e #515: CALL(obtain_8bits)35869 // @06f #516: JUMP(C,wsc_data_loop) ;bad input data01300 // @070 #517: LOAD(s3,s0) ;transmit byte3024e // @071 #518: CALL(write_byte_slow)3020e // @072 #519: CALL(compute_CRC16) ;compute CRC for value in 's3'18401 // @073 #520: ADD(s4,1) ;count bytes14408 // @074 #521: COMPARE(s4,8)35469 // @075 #522: JUMP(NZ,wsc_data_loop)302ec // @076 #523: CALL(send_CR)3021c // @077 #524: CALL(read_send_test_CRC16) ;read, display and test CRC value34003 // @078 #525: JUMP(warm_start)// #526: ;// #527: ;// #528: ;// #529: ;**************************************************************************************// #530: ; DS2432 Read Scratchpad Memory Command.// #531: ;**************************************************************************************// #532: ;// #533: ; The read scratchpad memory command (AA hex) allows the 8-bytes of data previously// #534: ; to be written into the scratchpad memory to be read back for verification together with// #535: ; the target address, a transfer status register (E/S) and a 16-bit CRC value.// #536: ;// #537: ; The 16-bit CRC is formed of the command byte, address TA1 and TA2, E/S byte and 8 data// #538: ; bytes as transmitted (12 bytes). These may not be the same as the values provided// #539: ; during a previous write to scratchpad memory. PicoBlaze also computes the CRC and// #540: ; and tests this against the value received from the DS2432.// #541: ;// #542: ; The 8 bytes of data are also copied to PicoBlaze memory at locations defined by the// #543: ; constants 'scratchpad0' to 'scratchpad7'. Three bytes are used as a 'challenge'// #544: ; by the SHA-1 algorithm.// #545: ;// #546: ;// #547: ;// @079 #548: [read_scratchpad_command]3020b // @079 #548: CALL(clear_CRC16) ;prepare CRC registers [sE,sD]003aa // @07a #549: LOAD(s3,AA) ;read scratchpad memory Command3024e // @07b #550: CALL(write_byte_slow) ;transmit command3020e // @07c #551: CALL(compute_CRC16) ;compute CRC for value in 's3'303bd // @07d #552: CALL(send_address) ;display 'Address='3026f // @07e #553: CALL(read_byte_slow) ;read address into [s5,s4]3020e // @07f #554: CALL(compute_CRC16) ;compute CRC for value in 's3'01430 // @080 #555: LOAD(s4,s3)3026f // @081 #556: CALL(read_byte_slow)3020e // @082 #557: CALL(compute_CRC16) ;compute CRC for value in 's3'01530 // @083 #558: LOAD(s5,s3)01050 // @084 #559: LOAD(s0,s5) ;display address302c2 // @085 #560: CALL(send_hex_byte)01040 // @086 #561: LOAD(s0,s4)302c2 // @087 #562: CALL(send_hex_byte)303ce // @088 #563: CALL(send_ES) ;display 'E/S='3026f // @089 #564: CALL(read_byte_slow) ;read E/S register3020e // @08a #565: CALL(compute_CRC16) ;compute CRC for value in 's3'01030 // @08b #566: LOAD(s0,s3) ;display value302c2 // @08c #567: CALL(send_hex_byte)303c8 // @08d #568: CALL(send_data) ;display 'Data='303c5 // @08e #569: CALL(send_equals)0041c // @08f #570: LOAD(s4,scratchpad0) ;pointer to memory and byte counter// @090 #571: [rsc_loop]302ef // @090 #571: CALL(send_space)3026f // @091 #572: CALL(read_byte_slow) ;read data byte3020e // @092 #573: CALL(compute_CRC16) ;compute CRC for value in 's3'2f340 // @093 #574: STORE(s3,s4) ;store value in memory01030 // @094 #575: LOAD(s0,s3) ;display value302c2 // @095 #576: CALL(send_hex_byte)14423 // @096 #577: COMPARE(s4,scratchpad7) ;count bytes3509a // @097 #578: JUMP(Z,end_rsc_data_loop)18401 // @098 #579: ADD(s4,1)34090 // @099 #580: JUMP(rsc_loop)// @09a #581: [end_rsc_data_loop]302ec // @09a #581: CALL(send_CR)3021c // @09b #582: CALL(read_send_test_CRC16) ;read, display and test CRC value34003 // @09c #583: JUMP(warm_start)// #584: ;// #585: ;// #586: ;// #587: ;// #588: ;// #589: ;**************************************************************************************// #590: ; DS2432 Read Authenticated Page Command.// #591: ;**************************************************************************************// #592: ;// #593: ; The read authenticated page command (A5 hex) allows the 8-byte secret to be tested// #594: ; without it actually being read (which would obviously give away the secret!).// #595: ;// #596: ; This routine has been written to work with page 0 but could easily be changed and// #597: ; is documented below. During the first part of the command, the 32 bytes// #598: ; contained in the page are read back from the DS2432 and these are used in// #599: ; the preparation of the table required for the for SHA-1 algorithm. Other values// #600: ; stored in the table are the secret, serial number of the DS2432, family code, some// #601: ; constants, 4-bits of the page address and a 3 byte 'challenge' currently set into// #602: ; the DS2432 scratchpad memory.// #603: ;// #604: ; NOTE - The read scratchpad command must be executed before this routine in order// #605: ; that the 3 byte 'challenge' of scratchpad memory is known to PicoBlaze.// #606: ;// #607: ; During this command, two 16-bit CRC values are generated which PicoBlaze also// #608: ; computes and tests. The first is formed of the command byte, address TA1 and TA2,// #609: ; all the bytes of the page read and an 'FF' byte. The second is formed of the 20// #610: ; bytes of the 160-but message authentication code (MAC).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?