Logo Search packages:      
Sourcecode: linux-fsl-imx51 version File versions  Download package

void fsl_shw_permute1_bytes ( const uint8_t *  key,
uint8_t *  permuted_key,
int  key_count 
)

Convert a 3-key 3DES key into the first-permutation 168-bit version.

This is the format of the input key:

   BIT:  |191                                 128|127                                  64|63                                    0|
   BYTE: |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
   KEY:  |                   0                   |                   1                   |                   2                   |
  

This is the format of the output key:

   BIT:  |167                            112|111                             56|55                               0|
   BYTE: |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
   KEY:  |                 1                |                 2                |                 3                |
  

Parameters:
[in] key bytes of 3DES key
[out] permuted_key 21 bytes of permuted key
[in] key_count How many DES keys (2 or 3)

Definition at line 122 of file des_key.c.

{
      int i;
      int j;
      int l;
      int m;

      DUMP_BYTES("Input key", key, 8 * key_count);

      /* For each individual sub-key */
      for (i = 0; i < 3; i++) {
            DUMP_BYTES("(key)", key, 8);
            memset(permuted_key, 0, 7);
            /* For each bit of key */
            for (j = 0; j < 56; j++) {    /* convert pc1 to bits of key */
                  l = pc1[j]; /* integer bit location  */
                  m = l & 07; /* find bit              */
                  permuted_key[j >> 3] |= (((key[l >> 3] &  /* find which key byte l is in */
                                       bytebit[m])    /* and which bit of that byte */
                                      ? 0x80 : 0) >> (j % 8));    /* and store 1-bit result */
            }
            switch (i) {
            case 0:
                  if (key_count != 1)
                        key += 8;   /* move on to second key */
                  break;
            case 1:
                  if (key_count == 2)
                        key -= 8;   /* go back to first key */
                  else if (key_count == 3)
                        key += 8;   /* move on to third key */
                  break;
            default:
                  break;
            }
            permuted_key += 7;
      }
      DUMP_BYTES("Output key (bytes)", permuted_key - 21, 21);
}


Generated by  Doxygen 1.6.0   Back to index