sha1prog.rmh

来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,559 行 · 第 1/5 页

RMH
1,559
字号
// #6: ; Version v1.00 - 19th April 2006// #7: ;// #8: ;// #9: ; IMPORTANT - This design builds on the reference design called "PicoBlaze// #10: ;             DS2432 communicator". It is highly recommend that you look at that// #11: ;             design before proceeding with this one.// #12: ;// #13: ;// #14: ; This program uses a 9600 baud UART connection to allow communication with the// #15: ; 1-wire interface of the DS2432 memory device from Dallas Semiconductor.// #16: ;// #17: ; The program only supports a limited number of the DS2432 commands to focus on// #18: ; those aspects which use the SHA-1 algorithm.// #19: ;// #20: ; Note that the code performing the SHA-1 algorithm interacts with the hardware of// #21: ; this complete reference design. The hardware provides a 16 word (32-bit) buffer// #22: ; combined used in the initialisation of the algorithm and subsequent computation// #23: ; of the Wt words.// #24: ;// #25: ;// #26: ; The DS2432 should be programmed with a 64-bit secret. The following constants// #27: ; define the secret which will be used. Obviously this would be be changed in a// #28: ; real application and further measures taken to prevent it easily being found.// #29: ; The secret is 64-bits formed of 8 bytes. 'secret0' would be stored at address// #30: ; 0080 of the DS2432 and 'secret7' at address 0087. The write buffer and load// #31: ; first secret commands allow you to set any secret into the DS2432 device but// #32: ; this program always uses the secret defined in these constants such that you can// #33: ; experiment with secrets which do and do not match.// #34: ;// #35: ;// #36: CONSTANT(secret0,1)// #37: CONSTANT(secret1,35)// #38: CONSTANT(secret2,69)// #39: CONSTANT(secret3,103)// #40: CONSTANT(secret4,137)// #41: CONSTANT(secret5,AB)// #42: CONSTANT(secret6,CD)// #43: CONSTANT(secret7,EF)// #44: ;// #45: ;// #46: ; Bytes 4, 5 and 6 of the DS2432 scratch pad memory are used in the SHA-1 algorithm.// #47: ; These should be set using the write scratchpad memory command before using the// #48: ; read authenticated page command. HOWEVER, it is also important that you also use// #49: ; the read scratchpad command BEFORE using the read authenticated page command. This// #50: ; is because this program only copies the bytes 4, 5 and 6 during a read such that// #51: ; they are can be used by the PicoBlaze SHA-1 algorithm. This limitation is deliberate// #52: ; so that you can experiment and prove that the SHA-1 results will not match if// #53: ; the same 'challenge' bytes are not used.// #54: ;// #55: ;// #56: ;**************************************************************************************// #57: ; Port definitions// #58: ;**************************************************************************************// #59: ;// #60: ;// #61: CONSTANT(status_port,64) ;UART status input// #62: CONSTANT(tx_half_full,1) ;  Transmitter     half full - bit0// #63: CONSTANT(tx_full,2) ;    FIFO               full - bit1// #64: CONSTANT(rx_data_present,4) ;  Receiver     data present - bit2// #65: CONSTANT(rx_half_full,8) ;    FIFO          half full - bit3// #66: CONSTANT(rx_full,16) ;                   full - bit4// #67: CONSTANT(spare1,32) ;                  spare '0' - bit5// #68: CONSTANT(spare2,64) ;                  spare '0' - bit6// #69: CONSTANT(spare3,128) ;                  spare '0' - bit7// #70: ;// #71: CONSTANT(UART_read_port,128) ;UART Rx data input// #72: ;// #73: CONSTANT(UART_write_port,4) ;UART Tx data output// #74: ;// #75: ;// #76: CONSTANT(DS_wire_in_port,C0) ;Read signal from DS2432 device// #77: CONSTANT(DS_wire_out_port,8) ;Drive signal to DS2432 device (open collector)// #78: CONSTANT(DS_wire,1) ;       Signal is bit0 in both cases// #79: ;// #80: ;// #81: ;// #82: ; The following ports access the 'Wt' word buffer. This buffer holds 16 words// #83: ; of 32-bits organised as a 64-byte shift register. Hence each word is stored// #84: ; by writing 4 bytes. As each byte is written, all bytes shift along such that// #85: ; older Wt values can be read from consistent port addresses.// #86: ;// #87: CONSTANT(W_word_write_port,16) ;Write byte to Wt buffer// #88: ;// #89: CONSTANT(Wt_minus3_byte0_read_port,8) ;Read of Wt-3// #90: CONSTANT(Wt_minus3_byte1_read_port,9)// #91: CONSTANT(Wt_minus3_byte2_read_port,10)// #92: CONSTANT(Wt_minus3_byte3_read_port,11)// #93: ;// #94: CONSTANT(Wt_minus8_byte0_read_port,28) ;Read of Wt-8// #95: CONSTANT(Wt_minus8_byte1_read_port,29)// #96: CONSTANT(Wt_minus8_byte2_read_port,30)// #97: CONSTANT(Wt_minus8_byte3_read_port,31)// #98: ;// #99: CONSTANT(Wt_minus14_byte0_read_port,52) ;Read of Wt-14// #100: CONSTANT(Wt_minus14_byte1_read_port,53)// #101: CONSTANT(Wt_minus14_byte2_read_port,54)// #102: CONSTANT(Wt_minus14_byte3_read_port,55)// #103: ;// #104: CONSTANT(Wt_minus16_byte0_read_port,60) ;Read of Wt-16// #105: CONSTANT(Wt_minus16_byte1_read_port,61)// #106: CONSTANT(Wt_minus16_byte2_read_port,62)// #107: CONSTANT(Wt_minus16_byte3_read_port,63)// #108: ;// #109: ;// #110: ;**************************************************************************************// #111: ; Special Register usage// #112: ;**************************************************************************************// #113: ;// #114: NAMEREG(sF,UART_data) ;used to pass data to and from the UART// #115: ;// #116: ;// #117: ;**************************************************************************************// #118: ; Scratch Pad Memory Locations// #119: ;**************************************************************************************// #120: ;// #121: ; Scratch pad memory provides 64 bytes in the address range 00 to 3F hex.// #122: ;// #123: ;// #124: ; Locations for device family code, serial number and 8-bit CRC value// #125: ;// #126: CONSTANT(family_code,0)// #127: CONSTANT(serial_number0,1) ;48-bit serial number LS-Byte first// #128: CONSTANT(serial_number1,2)// #129: CONSTANT(serial_number2,3)// #130: CONSTANT(serial_number3,4)// #131: CONSTANT(serial_number4,5)// #132: CONSTANT(serial_number5,6)// #133: CONSTANT(read_ROM_CRC,7) ;8-bit CRC// #134: ;// #135: ;// #136: ; Locations for variables used in SHA-1 algorithm.// #137: ; Each variable is 32-bits and requires 4 bytes to store.// #138: ; '0' indicates the least significant byte and '3' the most significant byte.// #139: ;// #140: ; Note that the concatenation of 'A', 'B', 'C', 'D' and 'E' will be the 160-bit MAC.// #141: ;// #142: CONSTANT(var_A0,8) ;Variable 'A'// #143: CONSTANT(var_A1,9)// #144: CONSTANT(var_A2,10)// #145: CONSTANT(var_A3,11)// #146: ;// #147: CONSTANT(var_B0,12) ;Variable 'B'// #148: CONSTANT(var_B1,13)// #149: CONSTANT(var_B2,14)// #150: CONSTANT(var_B3,15)// #151: ;// #152: CONSTANT(var_C0,16) ;Variable 'C'// #153: CONSTANT(var_C1,17)// #154: CONSTANT(var_C2,18)// #155: CONSTANT(var_C3,19)// #156: ;// #157: CONSTANT(var_D0,20) ;Variable 'D'// #158: CONSTANT(var_D1,21)// #159: CONSTANT(var_D2,22)// #160: CONSTANT(var_D3,23)// #161: ;// #162: CONSTANT(var_E0,24) ;Variable 'E'// #163: CONSTANT(var_E1,25)// #164: CONSTANT(var_E2,26)// #165: CONSTANT(var_E3,27)// #166: ;// #167: ;// #168: ; Copy of data in the scratchpad memory of the DS2432.// #169: ; This is only updated by the read scratchpad memory command.// #170: ; '0' indicates the data in the least significant location.// #171: ;// #172: CONSTANT(scratchpad0,28)// #173: CONSTANT(scratchpad1,29)// #174: CONSTANT(scratchpad2,30)// #175: CONSTANT(scratchpad3,31)// #176: CONSTANT(scratchpad4,32)// #177: CONSTANT(scratchpad5,33)// #178: CONSTANT(scratchpad6,34)// #179: CONSTANT(scratchpad7,35)// #180: ;// #181: ;// #182: ;// #183: ;**************************************************************************************// #184: ; Useful data constants// #185: ;**************************************************************************************// #186: ;// #187: ; Constant to define a software delay of 1us. This must be adjusted to reflect the// #188: ; clock applied to KCPSM3. Every instruction executes in 2 clock cycles making the// #189: ; calculation highly predictable. The '6' in the following equation even allows for// #190: ; 'CALL delay_1us' instruction in the initiating code.// #191: ;// #192: ; delay_1us_constant =  (clock_rate - 6)/4       Where 'clock_rate' is in MHz// #193: ;// #194: ; Example: For a 50MHz clock the constant value is (10-6)/4 = 11  (0B Hex).// #195: ; For clock rates below 10MHz the value of 1 must be used and the operation will// #196: ; become lower than intended.// #197: ;// #198: CONSTANT(delay_1us_constant,11)// #199: ;// #200: ;// #201: ;// #202: ;ASCII table// #203: ;// #204: CONSTANT(character_a,97)// #205: CONSTANT(character_b,98)// #206: CONSTANT(character_c,99)// #207: CONSTANT(character_d,100)// #208: CONSTANT(character_e,101)// #209: CONSTANT(character_f,102)// #210: CONSTANT(character_g,103)// #211: CONSTANT(character_h,104)// #212: CONSTANT(character_i,105)// #213: CONSTANT(character_j,106)// #214: CONSTANT(character_k,107)// #215: CONSTANT(character_l,108)// #216: CONSTANT(character_m,109)// #217: CONSTANT(character_n,110)// #218: CONSTANT(character_o,111)// #219: CONSTANT(character_p,112)// #220: CONSTANT(character_q,113)// #221: CONSTANT(character_r,114)// #222: CONSTANT(character_s,115)// #223: CONSTANT(character_t,116)// #224: CONSTANT(character_u,117)// #225: CONSTANT(character_v,118)// #226: CONSTANT(character_w,119)// #227: CONSTANT(character_x,120)// #228: CONSTANT(character_y,121)// #229: CONSTANT(character_z,122)// #230: CONSTANT(character_A,65)// #231: CONSTANT(character_B,66)// #232: CONSTANT(character_C,67)// #233: CONSTANT(character_D,68)// #234: CONSTANT(character_E,69)// #235: CONSTANT(character_F,70)// #236: CONSTANT(character_G,71)// #237: CONSTANT(character_H,72)// #238: CONSTANT(character_I,73)// #239: CONSTANT(character_J,74)// #240: CONSTANT(character_K,75)// #241: CONSTANT(character_L,76)// #242: CONSTANT(character_M,77)// #243: CONSTANT(character_N,78)// #244: CONSTANT(character_O,79)// #245: CONSTANT(character_P,80)// #246: CONSTANT(character_Q,81)// #247: CONSTANT(character_R,82)// #248: CONSTANT(character_S,83)// #249: CONSTANT(character_T,84)// #250: CONSTANT(character_U,85)// #251: CONSTANT(character_V,86)// #252: CONSTANT(character_W,87)// #253: CONSTANT(character_X,88)// #254: CONSTANT(character_Y,89)// #255: CONSTANT(character_Z,90)// #256: CONSTANT(character_0,48)// #257: CONSTANT(character_1,49)// #258: CONSTANT(character_2,50)// #259: CONSTANT(character_3,51)// #260: CONSTANT(character_4,52)// #261: CONSTANT(character_5,53)// #262: CONSTANT(character_6,54)// #263: CONSTANT(character_7,55)// #264: CONSTANT(character_8,56)// #265: CONSTANT(character_9,57)// #266: CONSTANT(character_colon,58)// #267: CONSTANT(character_fullstop,46)// #268: CONSTANT(character_semi_colon,59)// #269: CONSTANT(character_minus,45)// #270: CONSTANT(character_plus,43)// #271: CONSTANT(character_comma,44)// #272: CONSTANT(character_less_than,60) ;'<'// #273: CONSTANT(character_greater_than,62) ;'>'// #274: CONSTANT(character_open,40) ;'('// #275: CONSTANT(character_close,41) ;')'// #276: CONSTANT(character_divide,47) ;'/'// #277: CONSTANT(character_equals,61)// #278: CONSTANT(character_space,32)// #279: CONSTANT(character_CR,13) ;carriage return// #280: CONSTANT(character_LF,10) ;line feed// #281: CONSTANT(character_question,63) ;'?'// #282: CONSTANT(character_dollar,36)// #283: CONSTANT(character_exclaim,33) ;'!'// #284: CONSTANT(character_BS,8) ;Back Space command character// #285: CONSTANT(character_XON,17) ;Flow control ON// #286: CONSTANT(character_XOFF,19) ;Flow control OFF// #287: ;// #288: ;// #289: ;**************************************************************************************// #290: ; Initialise the system and welcome message// #291: ;**************************************************************************************// #292: ;// @000 #293: [cold_start]30230 // @000 #293: CALL(DS_wire_init) ;Ensure DS_wire is not driven (pulled High)3029a // @001 #294: CALL(delay_1s) ;Allow everything to settle!// @002 #295: [welcome_start]3030a // @002 #295: CALL(send_welcome) ;start up message and version number// #296: ;// #297: ;// #298: ;**************************************************************************************// #299: ; Reset Main menu and command selection// #300: ;**************************************************************************************// #301: ;// #302: ; The main program allows you to use four of the DS2432 memory and SHA function// #303: ; commands. A simple menu is displayed and you are guided to enter more information// #304: ; when required. All the communication and protocol required to get the DS2432 ready// #305: ; to receive memory and SHA function commands has been automated although information// #306: ; is displayed to indicate the procedures being executed.// #307: ;// #308: ; Before any memory and function commands are available a master reset and read ROM// #309: ; command must be issued.// #310: ;// @003 #311: [warm_start]302ec // @003 #311: CALL(send_CR)302ec // @004 #312: CALL(send_CR)30233 // @005 #313: CALL(DS_init_regular_mode) ;master reset35803 // @006 #314: JUMP(C,warm_start) ;repeat reset if no presence pulse detected

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?