crypto/weakcrypto/source/symmetric/destables.h
changeset 0 2c201484c85f
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * DES Tables
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file 
       
    24  @internalComponent 
       
    25 */
       
    26  
       
    27 #ifndef __DESTABLES_H__
       
    28 #define __DESTABLES_H__
       
    29 
       
    30 #include <e32std.h>
       
    31 
       
    32 namespace DES_TABLE
       
    33 {
       
    34 /* initial permutation IP */
       
    35 const TUint8 ip[] = {
       
    36 	   58, 50, 42, 34, 26, 18, 10,  2,
       
    37 	   60, 52, 44, 36, 28, 20, 12,  4,
       
    38 	   62, 54, 46, 38, 30, 22, 14,  6,
       
    39 	   64, 56, 48, 40, 32, 24, 16,  8,
       
    40 	   57, 49, 41, 33, 25, 17,  9,  1,
       
    41 	   59, 51, 43, 35, 27, 19, 11,  3,
       
    42 	   61, 53, 45, 37, 29, 21, 13,  5,
       
    43 	   63, 55, 47, 39, 31, 23, 15,  7
       
    44 };
       
    45 
       
    46 /* final permutation IP^-1 */
       
    47 const TUint8 fp[] = {
       
    48 	   40,  8, 48, 16, 56, 24, 64, 32,
       
    49 	   39,  7, 47, 15, 55, 23, 63, 31,
       
    50 	   38,  6, 46, 14, 54, 22, 62, 30,
       
    51 	   37,  5, 45, 13, 53, 21, 61, 29,
       
    52 	   36,  4, 44, 12, 52, 20, 60, 28,
       
    53 	   35,  3, 43, 11, 51, 19, 59, 27,
       
    54 	   34,  2, 42, 10, 50, 18, 58, 26,
       
    55 	   33,  1, 41,  9, 49, 17, 57, 25
       
    56 };
       
    57 
       
    58 /* expansion operation matrix */
       
    59 const TUint8 ei[] = {
       
    60 	   32,  1,  2,  3,  4,  5,
       
    61 		4,  5,  6,  7,  8,  9,
       
    62 		8,  9, 10, 11, 12, 13,
       
    63 	   12, 13, 14, 15, 16, 17,
       
    64 	   16, 17, 18, 19, 20, 21,
       
    65 	   20, 21, 22, 23, 24, 25,
       
    66 	   24, 25, 26, 27, 28, 29,
       
    67 	   28, 29, 30, 31, 32,  1
       
    68 };
       
    69 
       
    70 const TUint32 sbox[8][64] = {
       
    71 {
       
    72 0x01010400,0x00000000,0x00010000,0x01010404, 0x01010004,0x00010404,0x00000004,0x00010000,
       
    73 0x00000400,0x01010400,0x01010404,0x00000400, 0x01000404,0x01010004,0x01000000,0x00000004,
       
    74 0x00000404,0x01000400,0x01000400,0x00010400, 0x00010400,0x01010000,0x01010000,0x01000404,
       
    75 0x00010004,0x01000004,0x01000004,0x00010004, 0x00000000,0x00000404,0x00010404,0x01000000,
       
    76 0x00010000,0x01010404,0x00000004,0x01010000, 0x01010400,0x01000000,0x01000000,0x00000400,
       
    77 0x01010004,0x00010000,0x00010400,0x01000004, 0x00000400,0x00000004,0x01000404,0x00010404,
       
    78 0x01010404,0x00010004,0x01010000,0x01000404, 0x01000004,0x00000404,0x00010404,0x01010400,
       
    79 0x00000404,0x01000400,0x01000400,0x00000000, 0x00010004,0x00010400,0x00000000,0x01010004},
       
    80 {
       
    81 0x80108020,0x80008000,0x00008000,0x00108020, 0x00100000,0x00000020,0x80100020,0x80008020,
       
    82 0x80000020,0x80108020,0x80108000,0x80000000, 0x80008000,0x00100000,0x00000020,0x80100020,
       
    83 0x00108000,0x00100020,0x80008020,0x00000000, 0x80000000,0x00008000,0x00108020,0x80100000,
       
    84 0x00100020,0x80000020,0x00000000,0x00108000, 0x00008020,0x80108000,0x80100000,0x00008020,
       
    85 0x00000000,0x00108020,0x80100020,0x00100000, 0x80008020,0x80100000,0x80108000,0x00008000,
       
    86 0x80100000,0x80008000,0x00000020,0x80108020, 0x00108020,0x00000020,0x00008000,0x80000000,
       
    87 0x00008020,0x80108000,0x00100000,0x80000020, 0x00100020,0x80008020,0x80000020,0x00100020,
       
    88 0x00108000,0x00000000,0x80008000,0x00008020, 0x80000000,0x80100020,0x80108020,0x00108000},
       
    89 {
       
    90 0x00000208,0x08020200,0x00000000,0x08020008, 0x08000200,0x00000000,0x00020208,0x08000200,
       
    91 0x00020008,0x08000008,0x08000008,0x00020000, 0x08020208,0x00020008,0x08020000,0x00000208,
       
    92 0x08000000,0x00000008,0x08020200,0x00000200, 0x00020200,0x08020000,0x08020008,0x00020208,
       
    93 0x08000208,0x00020200,0x00020000,0x08000208, 0x00000008,0x08020208,0x00000200,0x08000000,
       
    94 0x08020200,0x08000000,0x00020008,0x00000208, 0x00020000,0x08020200,0x08000200,0x00000000,
       
    95 0x00000200,0x00020008,0x08020208,0x08000200, 0x08000008,0x00000200,0x00000000,0x08020008,
       
    96 0x08000208,0x00020000,0x08000000,0x08020208, 0x00000008,0x00020208,0x00020200,0x08000008,
       
    97 0x08020000,0x08000208,0x00000208,0x08020000, 0x00020208,0x00000008,0x08020008,0x00020200},
       
    98 {
       
    99 0x00802001,0x00002081,0x00002081,0x00000080, 0x00802080,0x00800081,0x00800001,0x00002001,
       
   100 0x00000000,0x00802000,0x00802000,0x00802081, 0x00000081,0x00000000,0x00800080,0x00800001,
       
   101 0x00000001,0x00002000,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002001,0x00002080,
       
   102 0x00800081,0x00000001,0x00002080,0x00800080, 0x00002000,0x00802080,0x00802081,0x00000081,
       
   103 0x00800080,0x00800001,0x00802000,0x00802081, 0x00000081,0x00000000,0x00000000,0x00802000,
       
   104 0x00002080,0x00800080,0x00800081,0x00000001, 0x00802001,0x00002081,0x00002081,0x00000080,
       
   105 0x00802081,0x00000081,0x00000001,0x00002000, 0x00800001,0x00002001,0x00802080,0x00800081,
       
   106 0x00002001,0x00002080,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002000,0x00802080},
       
   107 {
       
   108 0x00000100,0x02080100,0x02080000,0x42000100, 0x00080000,0x00000100,0x40000000,0x02080000,
       
   109 0x40080100,0x00080000,0x02000100,0x40080100, 0x42000100,0x42080000,0x00080100,0x40000000,
       
   110 0x02000000,0x40080000,0x40080000,0x00000000, 0x40000100,0x42080100,0x42080100,0x02000100,
       
   111 0x42080000,0x40000100,0x00000000,0x42000000, 0x02080100,0x02000000,0x42000000,0x00080100,
       
   112 0x00080000,0x42000100,0x00000100,0x02000000, 0x40000000,0x02080000,0x42000100,0x40080100,
       
   113 0x02000100,0x40000000,0x42080000,0x02080100, 0x40080100,0x00000100,0x02000000,0x42080000,
       
   114 0x42080100,0x00080100,0x42000000,0x42080100, 0x02080000,0x00000000,0x40080000,0x42000000,
       
   115 0x00080100,0x02000100,0x40000100,0x00080000, 0x00000000,0x40080000,0x02080100,0x40000100},
       
   116 {
       
   117 0x20000010,0x20400000,0x00004000,0x20404010, 0x20400000,0x00000010,0x20404010,0x00400000,
       
   118 0x20004000,0x00404010,0x00400000,0x20000010, 0x00400010,0x20004000,0x20000000,0x00004010,
       
   119 0x00000000,0x00400010,0x20004010,0x00004000, 0x00404000,0x20004010,0x00000010,0x20400010,
       
   120 0x20400010,0x00000000,0x00404010,0x20404000, 0x00004010,0x00404000,0x20404000,0x20000000,
       
   121 0x20004000,0x00000010,0x20400010,0x00404000, 0x20404010,0x00400000,0x00004010,0x20000010,
       
   122 0x00400000,0x20004000,0x20000000,0x00004010, 0x20000010,0x20404010,0x00404000,0x20400000,
       
   123 0x00404010,0x20404000,0x00000000,0x20400010, 0x00000010,0x00004000,0x20400000,0x00404010,
       
   124 0x00004000,0x00400010,0x20004010,0x00000000, 0x20404000,0x20000000,0x00400010,0x20004010},
       
   125 {
       
   126 0x00200000,0x04200002,0x04000802,0x00000000, 0x00000800,0x04000802,0x00200802,0x04200800,
       
   127 0x04200802,0x00200000,0x00000000,0x04000002, 0x00000002,0x04000000,0x04200002,0x00000802,
       
   128 0x04000800,0x00200802,0x00200002,0x04000800, 0x04000002,0x04200000,0x04200800,0x00200002,
       
   129 0x04200000,0x00000800,0x00000802,0x04200802, 0x00200800,0x00000002,0x04000000,0x00200800,
       
   130 0x04000000,0x00200800,0x00200000,0x04000802, 0x04000802,0x04200002,0x04200002,0x00000002,
       
   131 0x00200002,0x04000000,0x04000800,0x00200000, 0x04200800,0x00000802,0x00200802,0x04200800,
       
   132 0x00000802,0x04000002,0x04200802,0x04200000, 0x00200800,0x00000000,0x00000002,0x04200802,
       
   133 0x00000000,0x00200802,0x04200000,0x00000800, 0x04000002,0x04000800,0x00000800,0x00200002},
       
   134 {
       
   135 0x10001040,0x00001000,0x00040000,0x10041040, 0x10000000,0x10001040,0x00000040,0x10000000,
       
   136 0x00040040,0x10040000,0x10041040,0x00041000, 0x10041000,0x00041040,0x00001000,0x00000040,
       
   137 0x10040000,0x10000040,0x10001000,0x00001040, 0x00041000,0x00040040,0x10040040,0x10041000,
       
   138 0x00001040,0x00000000,0x00000000,0x10040040, 0x10000040,0x10001000,0x00041040,0x00040000,
       
   139 0x00041040,0x00040000,0x10041000,0x00001000, 0x00000040,0x10040040,0x00001000,0x00041040,
       
   140 0x10001000,0x00000040,0x10000040,0x10040000, 0x10040040,0x10000000,0x00040000,0x10001040,
       
   141 0x00000000,0x10041040,0x00040040,0x10000040, 0x10040000,0x10001000,0x10001040,0x00000000,
       
   142 0x10041040,0x00041000,0x00041000,0x00001040, 0x00001040,0x00040040,0x10000000,0x10041000}
       
   143 };
       
   144 
       
   145 
       
   146 /* 32-bit permutation function P used on the output of the S-boxes */
       
   147 const TUint8 p32i[] = {
       
   148 	   16,  7, 20, 21,
       
   149 	   29, 12, 28, 17,
       
   150 		1, 15, 23, 26,
       
   151 		5, 18, 31, 10,
       
   152 		2,  8, 24, 14,
       
   153 	   32, 27,  3,  9,
       
   154 	   19, 13, 30,  6,
       
   155 	   22, 11,  4, 25
       
   156 };
       
   157 
       
   158 /* permuted choice table (key) */
       
   159 const TUint8 pc1[] = {
       
   160 	   57, 49, 41, 33, 25, 17,  9,
       
   161 		1, 58, 50, 42, 34, 26, 18,
       
   162 	   10,  2, 59, 51, 43, 35, 27,
       
   163 	   19, 11,  3, 60, 52, 44, 36,
       
   164 
       
   165 	   63, 55, 47, 39, 31, 23, 15,
       
   166 		7, 62, 54, 46, 38, 30, 22,
       
   167 	   14,  6, 61, 53, 45, 37, 29,
       
   168 	   21, 13,  5, 28, 20, 12,  4
       
   169 };
       
   170 
       
   171 /* number left rotations of pc1 */
       
   172 const TUint8 totrot[] = {1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28};
       
   173 
       
   174 /* permuted choice key (table) */
       
   175 const TUint8 pc2[] = {
       
   176 	   14, 17, 11, 24,  1,  5,
       
   177 		3, 28, 15,  6, 21, 10,
       
   178 	   23, 19, 12,  4, 26,  8,
       
   179 	   16,  7, 27, 20, 13,  2,
       
   180 	   41, 52, 31, 37, 47, 55,
       
   181 	   30, 40, 51, 45, 33, 48,
       
   182 	   44, 49, 39, 56, 34, 53,
       
   183 	   46, 42, 50, 36, 29, 32
       
   184 };
       
   185 }	//	namespace DES_TABLE
       
   186 #endif	//	__DESTABLES_H__