Annotation of researchv10no/cmd/descrypt/genSP.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     Program to Generate the SP.c File
                      3:  *     D.P.Mitchell  83/06/30.
                      4:  */
                      5: 
                      6: /*
                      7:  * The 8 selection functions.
                      8:  */
                      9: int    S[8][64] = {
                     10:        14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7,
                     11:         0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8,
                     12:         4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0,
                     13:        15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13,
                     14: 
                     15:        15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10,
                     16:         3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5,
                     17:         0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15,
                     18:        13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9,
                     19: 
                     20:        10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8,
                     21:        13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1,
                     22:        13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7,
                     23:         1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12,
                     24: 
                     25:         7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15,
                     26:        13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9,
                     27:        10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4,
                     28:         3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14,
                     29: 
                     30:         2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9,
                     31:        14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6,
                     32:         4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14,
                     33:        11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3,
                     34: 
                     35:        12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11,
                     36:        10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8,
                     37:         9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6,
                     38:         4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13,
                     39: 
                     40:         4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1,
                     41:        13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6,
                     42:         1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2,
                     43:         6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12,
                     44: 
                     45:        13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7,
                     46:         1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2,
                     47:         7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8,
                     48:         2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11,
                     49: };
                     50: 
                     51: /*
                     52:  * P is a permutation on the selected combination
                     53:  * of the current L and key.
                     54:  */
                     55: int    P[] = {
                     56:        16, 7,20,21,
                     57:        29,12,28,17,
                     58:         1,15,23,26,
                     59:         5,18,31,10,
                     60:         2, 8,24,14,
                     61:        32,27, 3, 9,
                     62:        19,13,30, 6,
                     63:        22,11, 4,25,
                     64: };
                     65: 
                     66: SP(bits, box)
                     67: int bits[32];
                     68: int box;
                     69: {
                     70:        int f[32];
                     71:        int t, j, k;
                     72:        for (j = 0; j < 32; j++)
                     73:                f[j] = 0;
                     74:        t = 0;  /* 6*box >> low order */
                     75:        k = S[box][(bits[t+0]<<5)+
                     76:                (bits[t+1]<<3)+
                     77:                (bits[t+2]<<2)+
                     78:                (bits[t+3]<<1)+
                     79:                (bits[t+4]<<0)+
                     80:                (bits[t+5]<<4)];
                     81:        t = 4*box;
                     82:        f[t+0] = (k>>3)&01;
                     83:        f[t+1] = (k>>2)&01;
                     84:        f[t+2] = (k>>1)&01;
                     85:        f[t+3] = (k>>0)&01;
                     86:        for (j=0; j<32; j++)
                     87:                bits[j] = f[P[j]-1];
                     88: }
                     89: 
                     90: main()
                     91: {
                     92:        int box, sixgram;
                     93:        int bits[32];
                     94:        long crypto;
                     95:        int i;
                     96: 
                     97:        for (box = 0; box < 8; box++) {
                     98:                printf("long  s%dp[] = {\n", box);
                     99:                for (sixgram=0; sixgram < 64; sixgram++) {
                    100:                        for (i = 0; i < 32; i++) {
                    101:                                if (sixgram & (1 << i))
                    102:                                        bits[i] = 1;
                    103:                                else
                    104:                                        bits[i] = 0;
                    105:                        }
                    106:                        SP(bits, box);
                    107:                        crypto = 0;
                    108:                        for (i = 0; i < 32; i++)
                    109:                                crypto |= bits[i] << i;
                    110:                        printf("0x%08x,", crypto);
                    111:                        if (sixgram % 8 == 7)
                    112:                                printf("\n");
                    113:                }
                    114:                printf("};\n\n");
                    115:        }
                    116: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.