Wednesday, January 5, 2011

【 Weak current College 】 use assembly language for DES encryption algorithm 】

Abstract: the DES algorithm is a data encryption algorithms. Published since 1977, has been the international commercial secrets telecommunication and computer communications, the most common encryption standard. DES algorithm implementation in General in a high-level language. Keywords: DES encryption algorithm is currently in the financial sector in Assembly language and non-financial community of secure communication, increasingly with the DES algorithm. DES (Data Encryption Standard) encryption algorithm, the data is IBM research success in 1977 and published. As China's three gold works especially Golden card project startup, DES algorithm in POS, ATM, magnetic cards and smart card (IC card) are widely used in order to achieve critical data confidential. If the cardholder's PIN is encrypted transmission, IC cards and POS two-way authentication, financial transaction password keyboard, are used to the DES algorithm. Because the password is not possible to use advanced keyboard language, assembly language is very practical for DES. 1 DES algorithm simple principle DES is a block cipher. Assuming that the plaintext m is composed by the 0 and 1 as the length of a string of 64 bits, the key k is a 64-bit 0, 1 string. Set: M = m1m2m3 ... m64 K = k1k2k3 ... k64 encryption process can be expressed as follows: DES (m) = IP-1 · T16 · T15 ... · IP · T1 T2 (m) of which: IP (m) is the initial permutation, IP-1 is inverse replacement, T16 ~ T1 is iterated 16 times. (1) the initial permutation IP function is the input plaintext m bitwise combination again, and put the output into L0, R0 two sections, each of the 32-bit long, their replacement rules: 58, 42, 34, 50, 10, 18, 26, 52, 60, 2, 44, 28, 36, 12, 20, 4, 46, 54, 62, 38, 30, 22, 14, 6, 48, 56, 64, 40, 32, 24, 8, 16, 49, 57, 41, 25, 33, 17, 9, 1, 43, 51, 59, 35, 11, 19, 27, 53, 61, 3, 29, 37, 45, 5, 13, 21, 47, 55, 63, 31, 39, 23, 15, 7 (2) inverse replacement IP-1 after 16 iteration operations, L16, R16, obtained as input for inverse replacement. Inverse replacement meet: IP · IP-1 = IP-1 · IP = I inverse replacement is just the inverse of the initial permutation.  (3) T16 ~ T1 iterative calculation iteration algorithm using DES die 2 addition. Both ends of the communication network, the two sides agreed to a consistent key. In communication with a key of the source point on the core data will be encrypted and Redaction, and then to the redaction of form in a public communication network is transferred to the end of the communication network. Data to reach the destinations, with the same key to decrypt the ciphertext data, it depicts the core data in clear text. This ensures that the core data (such as PIN, MAC, etc.) in a public communication network transmissions of security and reliability. 2 assembly language implementation in Assembly language for DES algorithm has its advantages but also has its difficulties. Advantage is a compilation of 51 operation can easily realize the replacement function. But with the Assembly language to implement the iteration operations and circulation function compares the cumbersome. In a compilation with 51 for DES, I wrote several subroutines that are combined to achieve the DES algorithm for encryption.  Here are some ideas to write, there is a need for peer can contact me (E-mail: 8031 16 can bit addressing registers, you can place the 128-bit data, which can realize the transpose function DES. The plaintext m into registers 27H ~ 20H, start address, corresponding m64 00H 3FH corresponding m1. Use flags register C for replacement and inverse replacement program. In the 16 DES iteration process, in order to achieve the formula: Li = Ri-1; Ri = Li-1f (Ri-1, ki) operation process, its key is f (Ri-1, ki) functionality. F is a 32-bit input into 32-bit output. Which included three technology: ① will 32-bit expansion for 48-bit E function.  This feature available is similar to the replacement function subprogram. ② 48 bit key is generated. In order to facilitate the compilation build 51 subkeys, you can use hosts with serial download manner, by the host to 16 sub keys as the core MCU 89C52, then deposited 80H ~ FFH.  If the key is fixed, you can direct the child key in the Flash 89C52-curing. ③ s-box feature is the 48-bit input once again reduced to 32-bit. Specific implementation is the s-box table into the Flash 89C52, each time through the lookup find S output results. Following are several of these subroutines. (1) IP replacement subroutine; entry registers: (MSB) 2726252423222120 (LSB), exit registers: (MSB) 2F2E2D2C2B2A2928 (LSB); function: entry registers as replacement table transposition. IP: MOV C, 06H; will carry flag m58 sent to 7FH, C in MOV; will carry flag sent m1 C, 0EH in MOV; m50 to carry flag in MOV 7EH, C; will carry flag sent m2; repeat, prepared by table
.. MOV C, 31H; m15 to carry flag in MOV 41H, C; will carry flag sent m63 C, 39H in MOV; the m7 to carry flag in MOV 40H, C; will carry flag sent m64 in RET (2) inverse replacement subroutine; entry registers: (MSB) 2726252423222120 (LSB), exit registers: (MSB) 2F2E2D2C2B2A2928 (LSB); Function: entry registers data by inverse replacement table transposition. IPRVS: MOV C, 18H; m40 to carry flag in MOV 7FH, C; will carry flag sent m1 in C, 38H MOV ... RET (3) exclusive or subroutine; entry registers: 272625243F3E3D3C, export register: 2B2A2928; features: contents of the register and the register 27262524 3F3E3D3C content exclusive-or. Results are saved in 2B2A2928 registers. XORLF: MOV A, 3FH; high 8 bit XOR XRL 27HMOV 2BH, A, A, placed in A outlet MOV, 3EHXRL 26HMOV 2AH, A, A, A AMOV 3DHXRL, 25HMOV 29H, AMOV A, A, 24HMOV 28H 3CHXRL, ARET (4) S box procedural; entry registers: (MSB) 2F2E2D2C2B2A2928, export register: (MSB) 27262524; features: 48 bit → 32 bit S6TO4: MOV 20h, remove the upper data 2FH; LCALL S162345; calls for Si (b1b6, b2b3b4b5); function subprogram MOV DPTR, # S1TAB; s-box table first address MOV A, remove the 21H; several s-box LCALL DPTRADDCLR AMOVC A, @ A + DPTR; find the s-box table address and SWAP AMOV 27H S results, A high result; preserve, 2EHLCALL S162345 MOV 20H; repeat RET exploit these subroutine, we successfully developed in core MCU 89C52 keys keyboard, can be used to finance a system of user remote password change, it can also be used for the transport of other commercial redaction.

No comments:

Post a Comment