Changeset 21422 for trunk/src/rsaenh/des.c
- Timestamp:
- Aug 17, 2010, 11:51:11 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/rsaenh/des.c
r21363 r21422 6 6 * Based on public domain code by Tom St Denis (tomstdenis@iahu.ca) 7 7 * and Dobes Vandermeer. 8 * 8 * 9 9 * This library is free software; you can redistribute it and/or 10 10 * modify it under the terms of the GNU Lesser General Public … … 23 23 24 24 /* 25 * This file contains code from the LibTomCrypt cryptographic 25 * This file contains code from the LibTomCrypt cryptographic 26 26 * library written by Tom St Denis (tomstdenis@iahu.ca). LibTomCrypt 27 27 * is in the public domain. The code in this file is tailored to 28 28 * special requirements. Take a look at http://libtomcrypt.org for the 29 * original version. 29 * original version. 30 30 */ 31 31 32 32 #include "tomcrypt.h" 33 33 34 #define EN0 0 34 #define EN0 0 35 35 #define DE1 1 36 36 37 37 static const ulong32 bytebit[8] = 38 38 { 39 0200, 0100, 040, 020, 010, 04, 02, 01 39 0200, 0100, 040, 020, 010, 04, 02, 01 40 40 }; 41 41 … … 47 47 0x800UL, 0x400UL, 0x200UL, 0x100UL, 48 48 0x80UL, 0x40UL, 0x20UL, 0x10UL, 49 0x8UL, 0x4UL, 0x2UL, 0x1L 49 0x8UL, 0x4UL, 0x2UL, 0x1L 50 50 }; 51 51 … … 53 53 54 54 static const unsigned char pc1[56] = { 55 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 56 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 55 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 56 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 57 57 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 58 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 58 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 59 59 }; 60 60 61 61 static const unsigned char totrot[16] = { 62 62 1, 2, 4, 6, 63 8, 10, 12, 14, 64 15, 17, 19, 21, 63 8, 10, 12, 14, 64 15, 17, 19, 21, 65 65 23, 25, 27, 28 66 66 }; … … 1279 1279 CONST64(0x40404000,0x00404040), CONST64(0x40404010,0x00404040), CONST64(0x40404000,0x40404040), CONST64(0x40404010,0x40404040) 1280 1280 }}; 1281 1281 1282 1282 1283 1283 static void cookey(const ulong32 *raw1, ulong32 *keyout); … … 1364 1364 right = block[1]; 1365 1365 1366 tmp = des_ip[0][byte(leftt, 0)] ^1367 des_ip[1][byte(leftt, 1)] ^1368 des_ip[2][byte(leftt, 2)] ^1369 des_ip[3][byte(leftt, 3)] ^1370 des_ip[4][byte(right, 0)] ^1371 des_ip[5][byte(right, 1)] ^1372 des_ip[6][byte(right, 2)] ^1373 des_ip[7][byte(right, 3)];1374 leftt = (ulong32)( tmp >> 32);1375 right = (ulong32)( tmp & 0xFFFFFFFFUL);1366 tmp = des_ip[0][byte(leftt, 0)]; 1367 XOR_int64(tmp, des_ip[1][byte(leftt, 1)]); 1368 XOR_int64(tmp, des_ip[2][byte(leftt, 2)]); 1369 XOR_int64(tmp, des_ip[3][byte(leftt, 3)]); 1370 XOR_int64(tmp, des_ip[4][byte(right, 0)]); 1371 XOR_int64(tmp, des_ip[5][byte(right, 1)]); 1372 XOR_int64(tmp, des_ip[6][byte(right, 2)]); 1373 XOR_int64(tmp, des_ip[7][byte(right, 3)]); 1374 leftt = (ulong32)(HI_int64(tmp)); 1375 right = (ulong32)(LO_int64(tmp)); 1376 1376 1377 1377 for (cur_round = 0; cur_round < 8; cur_round++) { … … 1399 1399 } 1400 1400 1401 tmp = des_fp[0][byte(leftt, 0)] ^1402 des_fp[1][byte(leftt, 1)] ^1403 des_fp[2][byte(leftt, 2)] ^1404 des_fp[3][byte(leftt, 3)] ^1405 des_fp[4][byte(right, 0)] ^1406 des_fp[5][byte(right, 1)] ^1407 des_fp[6][byte(right, 2)] ^1408 des_fp[7][byte(right, 3)];1409 leftt = (ulong32)( tmp >> 32);1410 right = (ulong32)( tmp & 0xFFFFFFFFUL);1411 1401 tmp = des_ip[0][byte(leftt, 0)]; 1402 XOR_int64(tmp, des_ip[1][byte(leftt, 1)]); 1403 XOR_int64(tmp, des_ip[2][byte(leftt, 2)]); 1404 XOR_int64(tmp, des_ip[3][byte(leftt, 3)]); 1405 XOR_int64(tmp, des_ip[4][byte(right, 0)]); 1406 XOR_int64(tmp, des_ip[5][byte(right, 1)]); 1407 XOR_int64(tmp, des_ip[6][byte(right, 2)]); 1408 XOR_int64(tmp, des_ip[7][byte(right, 3)]); 1409 leftt = (ulong32)(HI_int64(tmp)); 1410 right = (ulong32)(LO_int64(tmp)); 1411 1412 1412 block[0] = right; 1413 1413 block[1] = leftt;
Note:
See TracChangeset
for help on using the changeset viewer.