sha1prog.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,559 行 · 第 1/5 页
RMH
1,559 行
// #909: ;Iterations 20 to 39 and iterations 60 to 79 - process type 2// #910: ; ft = B xor C xor D// #911: ; Then the constant Kt=6ED9EBA1 will be added for iterations 20 to 39// #912: ; Then the constant Kt=CA62C1D6 will be added for iterations 60 to 79// #913: ;// #914: ;Iterations 40 to 59 - process type 3// #915: ; ft = (B and C) or (B and D) or (C and D)// #916: ; Then the constant Kt=8F1BBCDC will be added// #917: ;// @13e #918: [next_sha1_iteration]0650f // @13e #918: FETCH(s5,var_B3) ;B in [s5,s4,s3,s2]0640e // @13f #919: FETCH(s4,var_B2)0630d // @140 #920: FETCH(s3,var_B1)0620c // @141 #921: FETCH(s2,var_B0)30176 // @142 #922: CALL(fetch_C) ;C in [s9,s8,s7,s6]06d17 // @143 #923: FETCH(sD,var_D3) ;D in [sD,sC,sB,sA]06c16 // @144 #924: FETCH(sC,var_D2)06b15 // @145 #925: FETCH(sB,var_D1)06a14 // @146 #926: FETCH(sA,var_D0)// #927: ;// #928: ;Determine process type// #929: ;14e14 // @147 #930: COMPARE(sE,20) ;set carry flag for iterations <2035961 // @148 #931: JUMP(C,ft_type1)14e28 // @149 #932: COMPARE(sE,40) ;set carry flag for iterations <403594d // @14a #933: JUMP(C,ft_type2)14e3c // @14b #934: COMPARE(sE,60) ;set carry flag for iterations <603597b // @14c #935: JUMP(C,ft_type3)// #936: ;// #937: ; ft = B xor C xor D// #938: ;// #939: ; B xor C = B xor C// #940: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] xor [s9,s8,s7,s6]// #941: ;// #942: ; B xor C xor D = (B xor C) xor D// #943: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] xor [sD,sC,sB,sA]// #944: ;// #945: ;// @14d #946: [ft_type2]0f590 // @14d #946: XOR(s5,s9) ;B xor C in [s5,s4,s3,s2]0f480 // @14e #947: XOR(s4,s8)0f370 // @14f #948: XOR(s3,s7)0f260 // @150 #949: XOR(s2,s6)0f5d0 // @151 #950: XOR(s5,sD) ;(B xor C) xor D in [s5,s4,s3,s2]0f4c0 // @152 #951: XOR(s4,sC)0f3b0 // @153 #952: XOR(s3,sB)0f2a0 // @154 #953: XOR(s2,sA)14e3c // @155 #954: COMPARE(sE,60) ;set carry flag for iterations <6035d5c // @156 #955: JUMP(NC,Kt_CA62C1D6)182a1 // @157 #956: ADD(s2,A1) ;add Kt=6ED9EBA11a3eb // @158 #957: ADDCY(s3,EB)1a4d9 // @159 #958: ADDCY(s4,D9)1a56e // @15a #959: ADDCY(s5,110)34194 // @15b #960: JUMP(compute_TMP)// @15c #961: [Kt_CA62C1D6]182d6 // @15c #961: ADD(s2,D6) ;add Kt=CA62C1D61a3c1 // @15d #962: ADDCY(s3,C1)1a462 // @15e #963: ADDCY(s4,98)1a5ca // @15f #964: ADDCY(s5,CA)34194 // @160 #965: JUMP(compute_TMP)// #966: ;// #967: ; ft = (B and C) or ((not B) and D)// #968: ;// #969: ; B and C = C and B// #970: ; [s9,s8,s7,s6] = [s9,s8,s7,s6] and [s5,s4,s3,s2]// #971: ;// #972: ; not B = B xor FFFFFFFF// #973: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] xor [FF,FF,FF,FF]// #974: ;// #975: ; (not B) and D = (not B) and D// #976: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] and [sD,sC,sB,sA]// #977: ;// #978: ; ;(B and C) or ((not B) and D) = ((not B) and D) or (B and C)// #979: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] or [s9,s8,s7,s6]// #980: ;// @161 #981: [ft_type1]0b950 // @161 #981: AND(s9,s5) ;B and C in [s9,s8,s7,s6]0b840 // @162 #982: AND(s8,s4)0b730 // @163 #983: AND(s7,s3)0b620 // @164 #984: AND(s6,s2)0e5ff // @165 #985: XOR(s5,FF) ;(not B) in [s5,s4,s3,s2]0e4ff // @166 #986: XOR(s4,FF)0e3ff // @167 #987: XOR(s3,FF)0e2ff // @168 #988: XOR(s2,FF)0b5d0 // @169 #989: AND(s5,sD) ;((not B) and D) in [s5,s4,s3,s2]0b4c0 // @16a #990: AND(s4,sC)0b3b0 // @16b #991: AND(s3,sB)0b2a0 // @16c #992: AND(s2,sA)0d590 // @16d #993: OR(s5,s9) ;(B and C) or ((not B) and D) in [s5,s4,s3,s2]0d480 // @16e #994: OR(s4,s8)0d370 // @16f #995: OR(s3,s7)0d260 // @170 #996: OR(s2,s6)18299 // @171 #997: ADD(s2,153) ;add Kt=5A8279991a379 // @172 #998: ADDCY(s3,121)1a482 // @173 #999: ADDCY(s4,130)1a55a // @174 #1000: ADDCY(s5,90)34194 // @175 #1001: JUMP(compute_TMP)// #1002: ;// #1003: ;Routine to fetch variable 'C' into register set [s9,s8,s7,s6]// #1004: ;// @176 #1005: [fetch_C]06913 // @176 #1005: FETCH(s9,var_C3)06812 // @177 #1006: FETCH(s8,var_C2)06711 // @178 #1007: FETCH(s7,var_C1)06610 // @179 #1008: FETCH(s6,var_C0)2a000 // @17a #1009: RETURN// #1010: ;// #1011: ; ft = (B and C) or (B and D) or (C and D)// #1012: ;// #1013: ; B and C = C and B// #1014: ; [s9,s8,s7,s6] = [s9,s8,s7,s6] and [s5,s4,s3,s2]// #1015: ;// #1016: ; B and D = B and D// #1017: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] and [sD,sC,sB,sA]// #1018: ;// #1019: ; (B and C) or (B and D) = (B and D) or (B and C)// #1020: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] or [s9,s8,s7,s6]// #1021: ;// #1022: ; read C again into [s9,s8,s7,s6]// #1023: ;// #1024: ; C and D = C and D// #1025: ; [s9,s8,s7,s6] = [s9,s8,s7,s6] and [sD,sC,sB,sA]// #1026: ;// #1027: ; ((B and C) or (B and D)) or (C and D) = ((B and C) or (B and D)) or (C and D)// #1028: ; [s5,s4,s3,s2] = [s5,s4,s3,s2] or [s9,s8,s7,s6]// #1029: ;// @17b #1030: [ft_type3]0b950 // @17b #1030: AND(s9,s5) ;(B and C) in [s9,s8,s7,s6]0b840 // @17c #1031: AND(s8,s4)0b730 // @17d #1032: AND(s7,s3)0b620 // @17e #1033: AND(s6,s2)0b5d0 // @17f #1034: AND(s5,sD) ;(B and D) in [s5,s4,s3,s2]0b4c0 // @180 #1035: AND(s4,sC)0b3b0 // @181 #1036: AND(s3,sB)0b2a0 // @182 #1037: AND(s2,sA)0d590 // @183 #1038: OR(s5,s9) ;(B and C) or (B and D) in [s5,s4,s3,s2]0d480 // @184 #1039: OR(s4,s8)0d370 // @185 #1040: OR(s3,s7)0d260 // @186 #1041: OR(s2,s6)30176 // @187 #1042: CALL(fetch_C) ;C in [s9,s8,s7,s6]0b9d0 // @188 #1043: AND(s9,sD) ;(C and D) in [s9,s8,s7,s6]0b8c0 // @189 #1044: AND(s8,sC)0b7b0 // @18a #1045: AND(s7,sB)0b6a0 // @18b #1046: AND(s6,sA)0d590 // @18c #1047: OR(s5,s9) ;(B and C) or (B and D) or (C and D) in [s5,s4,s3,s2]0d480 // @18d #1048: OR(s4,s8)0d370 // @18e #1049: OR(s3,s7)0d260 // @18f #1050: OR(s2,s6)182dc // @190 #1051: ADD(s2,DC) ;add Kt=8F1BBCDC1a3bc // @191 #1052: ADDCY(s3,BC)1a41b // @192 #1053: ADDCY(s4,27)1a58f // @193 #1054: ADDCY(s5,143)// #1055: ;// #1056: ;Add variable 'E' to [s5,s4,s3,s2]// #1057: ;// @194 #1058: [compute_TMP]06018 // @194 #1058: FETCH(s0,var_E0)19200 // @195 #1059: ADD(s2,s0)06019 // @196 #1060: FETCH(s0,var_E1)1b300 // @197 #1061: ADDCY(s3,s0)0601a // @198 #1062: FETCH(s0,var_E2)1b400 // @199 #1063: ADDCY(s4,s0)0601b // @19a #1064: FETCH(s0,var_E3)1b500 // @19b #1065: ADDCY(s5,s0)// #1066: ;// #1067: ;Add variable 'A' rotated left 5 places// #1068: ;0690b // @19c #1069: FETCH(s9,var_A3) ;A in [s9,s8,s7,s6]0680a // @19d #1070: FETCH(s8,var_A2)06709 // @19e #1071: FETCH(s7,var_A1)06608 // @19f #1072: FETCH(s6,var_A0)00005 // @1a0 #1073: LOAD(s0,5) ;rotate left 5 places301e7 // @1a1 #1074: CALL(rotate_word_left_N_places)19260 // @1a2 #1075: ADD(s2,s6) ;add to TMP1b370 // @1a3 #1076: ADDCY(s3,s7)1b480 // @1a4 #1077: ADDCY(s4,s8)1b590 // @1a5 #1078: ADDCY(s5,s9)// #1079: ;// #1080: ;// #1081: ;Compute Wt in register set [s9,s8,s7,s6]// #1082: ; Value computed is also stored back in the external buffer for// #1083: ; use in later iterations as well as being added to TMP.// #1084: ;// #1085: ;Iterations 0 to 15// #1086: ; Wt = Mt// #1087: ; This only requires Wt-16 to be read and then shifted back into the buffer again.// #1088: ;// #1089: ;Iterations 0 to 15// #1090: ; Wt = rotate_left_1_place(Wt-3 xor Wt-8 xor Wt-14 xor Wt-16)// #1091: ; This requires all data values to be read first. Then XORed and rotated before// #1092: ; shifting the new Wt word into the buffer.// #1093: ;// #1094: ;0493f // @1a6 #1095: INPUT(s9,Wt_minus16_byte3_read_port) ;Read Wt-16 value0483e // @1a7 #1096: INPUT(s8,Wt_minus16_byte2_read_port)0473d // @1a8 #1097: INPUT(s7,Wt_minus16_byte1_read_port)0463c // @1a9 #1098: INPUT(s6,Wt_minus16_byte0_read_port)14e10 // @1aa #1099: COMPARE(sE,16) ;set carry flag for iterations 0 to 15359c5 // @1ab #1100: JUMP(C,store_Wt)// #1101: ;// #1102: ;Read other Wt words and perform XOR// #1103: ;04037 // @1ac #1104: INPUT(s0,Wt_minus14_byte3_read_port) ;XOR with Wt-14 value0f900 // @1ad #1105: XOR(s9,s0)04036 // @1ae #1106: INPUT(s0,Wt_minus14_byte2_read_port)0f800 // @1af #1107: XOR(s8,s0)04035 // @1b0 #1108: INPUT(s0,Wt_minus14_byte1_read_port)0f700 // @1b1 #1109: XOR(s7,s0)04034 // @1b2 #1110: INPUT(s0,Wt_minus14_byte0_read_port)0f600 // @1b3 #1111: XOR(s6,s0)0401f // @1b4 #1112: INPUT(s0,Wt_minus8_byte3_read_port) ;XOR with Wt-8 value0f900 // @1b5 #1113: XOR(s9,s0)0401e // @1b6 #1114: INPUT(s0,Wt_minus8_byte2_read_port)0f800 // @1b7 #1115: XOR(s8,s0)0401d // @1b8 #1116: INPUT(s0,Wt_minus8_byte1_read_port)0f700 // @1b9 #1117: XOR(s7,s0)0401c // @1ba #1118: INPUT(s0,Wt_minus8_byte0_read_port)0f600 // @1bb #1119: XOR(s6,s0)0400b // @1bc #1120: INPUT(s0,Wt_minus3_byte3_read_port) ;XOR with Wt-3 value0f900 // @1bd #1121: XOR(s9,s0)0400a // @1be #1122: INPUT(s0,Wt_minus3_byte2_read_port)0f800 // @1bf #1123: XOR(s8,s0)04009 // @1c0 #1124: INPUT(s0,Wt_minus3_byte1_read_port)0f700 // @1c1 #1125: XOR(s7,s0)04008 // @1c2 #1126: INPUT(s0,Wt_minus3_byte0_read_port)0f600 // @1c3 #1127: XOR(s6,s0)301eb // @1c4 #1128: CALL(rotate_word_left) ;rotate XORed word left by one place// #1129: ;// #1130: ;Store new Wt value in external buffer// #1131: ;// @1c5 #1132: [store_Wt]2c910 // @1c5 #1132: OUTPUT(s9,W_word_write_port)2c810 // @1c6 #1133: OUTPUT(s8,W_word_write_port)2c710 // @1c7 #1134: OUTPUT(s7,W_word_write_port)2c610 // @1c8 #1135: OUTPUT(s6,W_word_write_port)// #1136: ;// #1137: ;Add new computed Wt value to TMP in [s5,s4,s3,s2]// #1138: ;19260 // @1c9 #1139: ADD(s2,s6)1b370 // @1ca #1140: ADDCY(s3,s7)1b480 // @1cb #1141: ADDCY(s4,s8)1b590 // @1cc #1142: ADDCY(s5,s9)// #1143: ;// #1144: ;TMP is now complete in [s5,s4,s3,s2]// #1145: ;// #1146: ;// #1147: ;copy values// #1148: ; E <= D// #1149: ; D <= C// #1150: ; C <= B (this will need to be rotated 30 places afterwards)// #1151: ; B <= A// #1152: ;00d04 // @1cd #1153: LOAD(sD,4) ;4 bytes per word to copy// @1ce #1154: [copy_var_loop]00c1b // @1ce #1154: LOAD(sC,var_E3)00b1a // @1cf #1155: LOAD(sB,var_E2)// @1d0 #1156: [move_var_loop]07ab0 // @1d0 #1156: FETCH(sA,sB)2fac0 // @1d1 #1157: STORE(sA,sC)1cc01 // @1d2 #1158: SUB(sC,1)1cb01 // @1d3 #1159: SUB(sB,1)14c08 // @1d4 #1160: COMPARE(sC,var_A0)355d0 // @1d5 #1161: JUMP(NZ,move_var_loop)1cd01 // @1d6 #1162: SUB(sD,1)355ce // @1d7 #1163: JUMP(NZ,copy_var_loop)// #1164: ;// #1165: ;rotate 'C' (the previous 'B') left 30 places// #1166: ;30176 // @1d8 #1167: CALL(fetch_C) ;C in [s9,s8,s7,s6]0001e // @1d9 #1168: LOAD(s0,30) ;rotate left 30 places301e7 // @1da #1169: CALL(rotate_word_left_N_places)2e913 // @1db #1170: STORE(s9,var_C3)2e812 // @1dc #1171: STORE(s8,var_C2)2e711 // @1dd #1172: STORE(s7,var_C1)2e610 // @1de #1173: STORE(s6,var_C0)// #1174: ;// #1175: ; A <= TMP// #1176: ;2e50b // @1df #1177: STORE(s5,var_A3)2e40a // @1e0 #1178: STORE(s4,var_A2)2e309 // @1e1 #1179: STORE(s3,var_A1)2e208 // @1e2 #1180: STORE(s2,var_A0)// #1181: ;// #1182: ;count iterations// #1183: ;14e4f // @1e3 #1184: COMPARE(sE,79) ;test for last iteration = 79 decimal (4F hex)2b000 // @1e4 #1185: RETURN(Z)18e01 // @1e5 #1186: ADD(sE,1)3413e // @1e6 #1187: JUMP(next_sha1_iteration)// #1188: ;// #1189: ; Routine to rotate left the contents of Register set [s9,s8,s7,s6]// #1190: ; by the number of places specified in register 's0'.// #1191: ;// @1e7 #1192: [rotate_word_left_N_places]301eb // @1e7 #1192: CALL(rotate_word_left)1c001 // @1e8 #1193: SUB(s0,1)355e7 // @1e9 #1194: JUMP(NZ,rotate_word_left_N_places)2a000 // @1ea #1195: RETURN// #1196: ;// #1197: ; Routine to rotate left the contents of Register set [s9,s8,s7,s6]// #1198: ; by one place.// #1199: ;// @1eb #1200: [rotate_word_left]12980 // @1eb #1200: TEST(s9,128) ;test MSB of word20600 // @1ec #1201: SLA(s6)20700 // @1ed #1202: SLA(s7)20800 // @1ee #1203: SLA(s8)20900 // @1ef #1204: SLA(s9)2a000 // @1f0 #1205: RETURN// #1206: ;// #1207: ;********************************************************************************
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?