Annotation of researchv10dc/cmd/descrypt/keysetup.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     DES Key Setup
        !             3:  *     D.P.Mitchell  83/06/30.
        !             4:  */
        !             5: 
        !             6: #include "crypt.h"
        !             7: 
        !             8: int subkeys[128];
        !             9: 
        !            10: int    pc1_c[] = {
        !            11:        57,49,41,33,25,17, 9,
        !            12:         1,58,50,42,34,26,18,
        !            13:        10, 2,59,51,43,35,27,
        !            14:        19,11, 3,60,52,44,36,
        !            15: };
        !            16: 
        !            17: int    pc1_d[] = {
        !            18:        63,55,47,39,31,23,15,
        !            19:         7,62,54,46,38,30,22,
        !            20:        14, 6,61,53,45,37,29,
        !            21:        21,13, 5,28,20,12, 4,
        !            22: };
        !            23: 
        !            24: int    shifts[] = {
        !            25:        1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1,
        !            26: };
        !            27: 
        !            28: int    pc2_c[] = {
        !            29:        14,17,11,24, 1, 5,
        !            30:         3,28,15, 6,21,10,
        !            31:        23,19,12, 4,26, 8,
        !            32:        16, 7,27,20,13, 2,
        !            33: };
        !            34: 
        !            35: int    pc2_d[] = {
        !            36:        41,52,31,37,47,55,
        !            37:        30,40,51,45,33,48,
        !            38:        44,49,39,56,34,53,
        !            39:        46,42,50,36,29,32,
        !            40: };
        !            41: 
        !            42: key_setup(key, decrypting)
        !            43: Block *key;
        !            44: int decrypting;
        !            45: {
        !            46:        register round, j, k;
        !            47:        register int *kl, *kh;
        !            48:        int temp;
        !            49:        int c[28], d[28];
        !            50:        int keybits[64];
        !            51: 
        !            52:        /*
        !            53:         *      unpack 64-bit key block
        !            54:         */
        !            55:        for (j = 0; j < 64; j++)
        !            56:                if (j > 31)
        !            57:                        keybits[j] = ((key->right & (1 << (j - 32))) != 0);
        !            58:                else
        !            59:                        keybits[j] = ((key->left & (1 << j)) != 0);
        !            60:        /*
        !            61:         *      first permuted choice of 56 bits
        !            62:         */
        !            63:        for (j = 0; j < 28; j++) {
        !            64:                c[j] = keybits[pc1_c[j]-1];
        !            65:                d[j] = keybits[pc1_d[j]-1];
        !            66:        }
        !            67:        /*
        !            68:         *      funny rotation of the 28-bit halves
        !            69:         */
        !            70:        for (round = 0; round < 16; round++) {
        !            71:                for (k = 0; k < shifts[round]; k++) {
        !            72:                        temp = c[0];
        !            73:                        for (j = 0; j < 27; j++)
        !            74:                                c[j] = c[j + 1];
        !            75:                        c[27] = temp;
        !            76:                        temp = d[0];
        !            77:                        for (j = 0; j < 27; j++)
        !            78:                                d[j] = d[j + 1];
        !            79:                        d[27] = temp;
        !            80:                }
        !            81:                /*
        !            82:                 *      second permuted choice of 48 bits
        !            83:                 */
        !            84:                if (decrypting) {
        !            85:                        kl = &subkeys[8 * (15 - round)];
        !            86:                        kh = &subkeys[8 * (15 - round) + 4];
        !            87:                } else {
        !            88:                        kl = &subkeys[8 * round];
        !            89:                        kh = &subkeys[8 * round + 4];
        !            90:                }
        !            91:                for (j = 0; j < 24; j += 6) {
        !            92:                        *kl++ =  c[pc2_c[j + 0] - 1]
        !            93:                              + (c[pc2_c[j + 1] - 1] << 1)
        !            94:                              + (c[pc2_c[j + 2] - 1] << 2)
        !            95:                              + (c[pc2_c[j + 3] - 1] << 3)
        !            96:                              + (c[pc2_c[j + 4] - 1] << 4)
        !            97:                              + (c[pc2_c[j + 5] - 1] << 5);
        !            98:                        *kh++ =  d[pc2_d[j + 0] - 29]
        !            99:                              + (d[pc2_d[j + 1] - 29] << 1)
        !           100:                              + (d[pc2_d[j + 2] - 29] << 2)
        !           101:                              + (d[pc2_d[j + 3] - 29] << 3)
        !           102:                              + (d[pc2_d[j + 4] - 29] << 4)
        !           103:                              + (d[pc2_d[j + 5] - 29] << 5);
        !           104:                }
        !           105:        }
        !           106: }

unix.superglobalmegacorp.com

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