maint: update copyright
[gnulib.git] / lib / des.c
index e2c7986..002d9ba 100644 (file)
--- a/lib/des.c
+++ b/lib/des.c
@@ -1,6 +1,5 @@
 /* des.c --- DES and Triple-DES encryption/decryption Algorithm
- * Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007
- *    Free Software Foundation, Inc.
+ * Copyright (C) 1998-1999, 2001-2007, 2009-2014 Free Software Foundation, Inc.
  *
  * This file is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
@@ -13,9 +12,7 @@
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this file; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * along with this file; if not, see <http://www.gnu.org/licenses/>.
  *
  */
 
@@ -65,7 +62,7 @@
  *     // Encrypt the plaintext
  *     des_ecb_encrypt(&context, plaintext, ciphertext);
  *
- *     // To recover the orginal plaintext from ciphertext use:
+ *     // To recover the original plaintext from ciphertext use:
  *     des_ecb_decrypt(&context, ciphertext, recoverd);
  *
  *
@@ -99,7 +96,7 @@
 #include "des.h"
 
 #include <stdio.h>
-#include <string.h>            /* memcpy, memcmp */
+#include <string.h>             /* memcpy, memcmp */
 
 /*
  * The s-box values are permuted according to the 'primitive function P'
@@ -253,70 +250,70 @@ static const unsigned char encrypt_rotate_tab[16] = {
  * bits cleared.
  */
 static const unsigned char weak_keys[64][8] = {
-  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},    /*w */
+  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},     /*w */
   {0x00, 0x00, 0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e},
   {0x00, 0x00, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0},
   {0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe},
-  {0x00, 0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e},    /*sw */
+  {0x00, 0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e},     /*sw */
   {0x00, 0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e, 0x00},
   {0x00, 0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0, 0xfe},
   {0x00, 0x1e, 0xfe, 0xe0, 0x00, 0x0e, 0xfe, 0xf0},
-  {0x00, 0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0},    /*sw */
+  {0x00, 0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0},     /*sw */
   {0x00, 0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e, 0xfe},
   {0x00, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0, 0x00},
   {0x00, 0xe0, 0xfe, 0x1e, 0x00, 0xf0, 0xfe, 0x0e},
-  {0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe},    /*sw */
+  {0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe},     /*sw */
   {0x00, 0xfe, 0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0},
   {0x00, 0xfe, 0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e},
   {0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00},
   {0x1e, 0x00, 0x00, 0x1e, 0x0e, 0x00, 0x00, 0x0e},
-  {0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e, 0x00},    /*sw */
+  {0x1e, 0x00, 0x1e, 0x00, 0x0e, 0x00, 0x0e, 0x00},     /*sw */
   {0x1e, 0x00, 0xe0, 0xfe, 0x0e, 0x00, 0xf0, 0xfe},
   {0x1e, 0x00, 0xfe, 0xe0, 0x0e, 0x00, 0xfe, 0xf0},
   {0x1e, 0x1e, 0x00, 0x00, 0x0e, 0x0e, 0x00, 0x00},
-  {0x1e, 0x1e, 0x1e, 0x1e, 0x0e, 0x0e, 0x0e, 0x0e},    /*w */
+  {0x1e, 0x1e, 0x1e, 0x1e, 0x0e, 0x0e, 0x0e, 0x0e},     /*w */
   {0x1e, 0x1e, 0xe0, 0xe0, 0x0e, 0x0e, 0xf0, 0xf0},
   {0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e, 0xfe, 0xfe},
   {0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0, 0x00, 0xfe},
-  {0x1e, 0xe0, 0x1e, 0xe0, 0x0e, 0xf0, 0x0e, 0xf0},    /*sw */
+  {0x1e, 0xe0, 0x1e, 0xe0, 0x0e, 0xf0, 0x0e, 0xf0},     /*sw */
   {0x1e, 0xe0, 0xe0, 0x1e, 0x0e, 0xf0, 0xf0, 0x0e},
   {0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0, 0xfe, 0x00},
   {0x1e, 0xfe, 0x00, 0xe0, 0x0e, 0xfe, 0x00, 0xf0},
-  {0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e, 0xfe},    /*sw */
+  {0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e, 0xfe},     /*sw */
   {0x1e, 0xfe, 0xe0, 0x00, 0x0e, 0xfe, 0xf0, 0x00},
   {0x1e, 0xfe, 0xfe, 0x1e, 0x0e, 0xfe, 0xfe, 0x0e},
   {0xe0, 0x00, 0x00, 0xe0, 0xf0, 0x00, 0x00, 0xf0},
   {0xe0, 0x00, 0x1e, 0xfe, 0xf0, 0x00, 0x0e, 0xfe},
-  {0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0, 0x00},    /*sw */
+  {0xe0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf0, 0x00},     /*sw */
   {0xe0, 0x00, 0xfe, 0x1e, 0xf0, 0x00, 0xfe, 0x0e},
   {0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e, 0x00, 0xfe},
   {0xe0, 0x1e, 0x1e, 0xe0, 0xf0, 0x0e, 0x0e, 0xf0},
-  {0xe0, 0x1e, 0xe0, 0x1e, 0xf0, 0x0e, 0xf0, 0x0e},    /*sw */
+  {0xe0, 0x1e, 0xe0, 0x1e, 0xf0, 0x0e, 0xf0, 0x0e},     /*sw */
   {0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e, 0xfe, 0x00},
   {0xe0, 0xe0, 0x00, 0x00, 0xf0, 0xf0, 0x00, 0x00},
   {0xe0, 0xe0, 0x1e, 0x1e, 0xf0, 0xf0, 0x0e, 0x0e},
-  {0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf0},    /*w */
+  {0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf0},     /*w */
   {0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0, 0xfe, 0xfe},
   {0xe0, 0xfe, 0x00, 0x1e, 0xf0, 0xfe, 0x00, 0x0e},
   {0xe0, 0xfe, 0x1e, 0x00, 0xf0, 0xfe, 0x0e, 0x00},
-  {0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0, 0xfe},    /*sw */
+  {0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0, 0xfe},     /*sw */
   {0xe0, 0xfe, 0xfe, 0xe0, 0xf0, 0xfe, 0xfe, 0xf0},
   {0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, 0xfe},
   {0xfe, 0x00, 0x1e, 0xe0, 0xfe, 0x00, 0x0e, 0xf0},
   {0xfe, 0x00, 0xe0, 0x1e, 0xfe, 0x00, 0xf0, 0x0e},
-  {0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00},    /*sw */
+  {0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00, 0xfe, 0x00},     /*sw */
   {0xfe, 0x1e, 0x00, 0xe0, 0xfe, 0x0e, 0x00, 0xf0},
   {0xfe, 0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e, 0xfe},
   {0xfe, 0x1e, 0xe0, 0x00, 0xfe, 0x0e, 0xf0, 0x00},
-  {0xfe, 0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e},    /*sw */
+  {0xfe, 0x1e, 0xfe, 0x1e, 0xfe, 0x0e, 0xfe, 0x0e},     /*sw */
   {0xfe, 0xe0, 0x00, 0x1e, 0xfe, 0xf0, 0x00, 0x0e},
   {0xfe, 0xe0, 0x1e, 0x00, 0xfe, 0xf0, 0x0e, 0x00},
   {0xfe, 0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0, 0xfe},
-  {0xfe, 0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0},    /*sw */
+  {0xfe, 0xe0, 0xfe, 0xe0, 0xfe, 0xf0, 0xfe, 0xf0},     /*sw */
   {0xfe, 0xfe, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00},
   {0xfe, 0xfe, 0x1e, 0x1e, 0xfe, 0xfe, 0x0e, 0x0e},
   {0xfe, 0xfe, 0xe0, 0xe0, 0xfe, 0xfe, 0xf0, 0xf0},
-  {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}     /*w */
+  {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}      /*w */
 };
 
 bool
@@ -337,12 +334,12 @@ gl_des_is_weak_key (const char * key)
       middle = (left + right) / 2;
 
       if (!(cmp_result = memcmp (work, weak_keys[middle], 8)))
-       return -1;
+        return -1;
 
       if (cmp_result > 0)
-       left = middle + 1;
+        left = middle + 1;
       else
-       right = middle - 1;
+        right = middle - 1;
     }
 
   return 0;
@@ -351,9 +348,9 @@ gl_des_is_weak_key (const char * key)
 /*
  * Macro to swap bits across two words.
  */
-#define DO_PERMUTATION(a, temp, b, offset, mask)       \
-    temp = ((a>>offset) ^ b) & mask;                   \
-    b ^= temp;                                         \
+#define DO_PERMUTATION(a, temp, b, offset, mask)        \
+    temp = ((a>>offset) ^ b) & mask;                    \
+    b ^= temp;                                          \
     a ^= temp<<offset;
 
 
@@ -362,29 +359,29 @@ gl_des_is_weak_key (const char * key)
  * or decrypted. Additionally the resulting two words are rotated one bit
  * to the left.
  */
-#define INITIAL_PERMUTATION(left, temp, right)         \
-    DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f)   \
-    DO_PERMUTATION(left, temp, right, 16, 0x0000ffff)  \
-    DO_PERMUTATION(right, temp, left, 2, 0x33333333)   \
-    DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff)   \
-    right =  (right << 1) | (right >> 31);             \
-    temp  =  (left ^ right) & 0xaaaaaaaa;              \
-    right ^= temp;                                     \
-    left  ^= temp;                                     \
+#define INITIAL_PERMUTATION(left, temp, right)          \
+    DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f)    \
+    DO_PERMUTATION(left, temp, right, 16, 0x0000ffff)   \
+    DO_PERMUTATION(right, temp, left, 2, 0x33333333)    \
+    DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff)    \
+    right =  (right << 1) | (right >> 31);              \
+    temp  =  (left ^ right) & 0xaaaaaaaa;               \
+    right ^= temp;                                      \
+    left  ^= temp;                                      \
     left  =  (left << 1) | (left >> 31);
 
 /*
  * The 'inverse initial permutation'.
  */
-#define FINAL_PERMUTATION(left, temp, right)           \
-    left  =  (left << 31) | (left >> 1);               \
-    temp  =  (left ^ right) & 0xaaaaaaaa;              \
-    left  ^= temp;                                     \
-    right ^= temp;                                     \
-    right  =  (right << 31) | (right >> 1);            \
-    DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff)   \
-    DO_PERMUTATION(right, temp, left, 2, 0x33333333)   \
-    DO_PERMUTATION(left, temp, right, 16, 0x0000ffff)  \
+#define FINAL_PERMUTATION(left, temp, right)            \
+    left  =  (left << 31) | (left >> 1);                \
+    temp  =  (left ^ right) & 0xaaaaaaaa;               \
+    left  ^= temp;                                      \
+    right ^= temp;                                      \
+    right  =  (right << 31) | (right >> 1);             \
+    DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff)    \
+    DO_PERMUTATION(right, temp, left, 2, 0x33333333)    \
+    DO_PERMUTATION(left, temp, right, 16, 0x0000ffff)   \
     DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f)
 
 
@@ -394,40 +391,40 @@ gl_des_is_weak_key (const char * key)
  * Please note: The data in 'from' and 'to' is already rotated one bit to
  * the left, done in the initial permutation.
  */
-#define DES_ROUND(from, to, work, subkey)              \
-    work = from ^ *subkey++;                           \
-    to ^= sbox8[  work     & 0x3f ];                   \
-    to ^= sbox6[ (work>>8)  & 0x3f ];                  \
-    to ^= sbox4[ (work>>16) & 0x3f ];                  \
-    to ^= sbox2[ (work>>24) & 0x3f ];                  \
-    work = ((from << 28) | (from >> 4)) ^ *subkey++;   \
-    to ^= sbox7[  work     & 0x3f ];                   \
-    to ^= sbox5[ (work>>8)  & 0x3f ];                  \
-    to ^= sbox3[ (work>>16) & 0x3f ];                  \
+#define DES_ROUND(from, to, work, subkey)               \
+    work = from ^ *subkey++;                            \
+    to ^= sbox8[  work      & 0x3f ];                   \
+    to ^= sbox6[ (work>>8)  & 0x3f ];                   \
+    to ^= sbox4[ (work>>16) & 0x3f ];                   \
+    to ^= sbox2[ (work>>24) & 0x3f ];                   \
+    work = ((from << 28) | (from >> 4)) ^ *subkey++;    \
+    to ^= sbox7[  work      & 0x3f ];                   \
+    to ^= sbox5[ (work>>8)  & 0x3f ];                   \
+    to ^= sbox3[ (work>>16) & 0x3f ];                   \
     to ^= sbox1[ (work>>24) & 0x3f ];
 
 /*
  * Macros to convert 8 bytes from/to 32bit words.
  */
-#define READ_64BIT_DATA(data, left, right)                                \
+#define READ_64BIT_DATA(data, left, right)                                 \
     left  = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];  \
     right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
 
-#define WRITE_64BIT_DATA(data, left, right)                               \
-    data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff;           \
-    data[2] = (left >> 8) &0xff; data[3] = left &0xff;                    \
-    data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff;         \
+#define WRITE_64BIT_DATA(data, left, right)                                \
+    data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff;    \
+    data[2] = (left >> 8) &0xff; data[3] = left &0xff;                     \
+    data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff;          \
     data[6] = (right >> 8) &0xff; data[7] = right &0xff;
 
 /*
- * des_key_schedule():   Calculate 16 subkeys pairs (even/odd) for
- *                       16 encryption rounds.
- *                       To calculate subkeys for decryption the caller
- *                       have to reorder the generated subkeys.
+ * des_key_schedule():    Calculate 16 subkeys pairs (even/odd) for
+ *                        16 encryption rounds.
+ *                        To calculate subkeys for decryption the caller
+ *                        have to reorder the generated subkeys.
  *
- *    rawkey:      8 Bytes of key data
- *    subkey:      Array of at least 32 uint32_ts. Will be filled
- *                 with calculated subkeys.
+ *    rawkey:       8 Bytes of key data
+ *    subkey:       Array of at least 32 uint32_ts. Will be filled
+ *                  with calculated subkeys.
  *
  */
 static void
@@ -441,79 +438,79 @@ des_key_schedule (const char * _rawkey, uint32_t * subkey)
     DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f)
     DO_PERMUTATION (right, work, left, 0, 0x10101010)
     left = ((leftkey_swap[(left >> 0) & 0xf] << 3)
-           | (leftkey_swap[(left >> 8) & 0xf] << 2)
-           | (leftkey_swap[(left >> 16) & 0xf] << 1)
-           | (leftkey_swap[(left >> 24) & 0xf])
-           | (leftkey_swap[(left >> 5) & 0xf] << 7)
-           | (leftkey_swap[(left >> 13) & 0xf] << 6)
-           | (leftkey_swap[(left >> 21) & 0xf] << 5)
-           | (leftkey_swap[(left >> 29) & 0xf] << 4));
+            | (leftkey_swap[(left >> 8) & 0xf] << 2)
+            | (leftkey_swap[(left >> 16) & 0xf] << 1)
+            | (leftkey_swap[(left >> 24) & 0xf])
+            | (leftkey_swap[(left >> 5) & 0xf] << 7)
+            | (leftkey_swap[(left >> 13) & 0xf] << 6)
+            | (leftkey_swap[(left >> 21) & 0xf] << 5)
+            | (leftkey_swap[(left >> 29) & 0xf] << 4));
 
   left &= 0x0fffffff;
 
   right = ((rightkey_swap[(right >> 1) & 0xf] << 3)
-          | (rightkey_swap[(right >> 9) & 0xf] << 2)
-          | (rightkey_swap[(right >> 17) & 0xf] << 1)
-          | (rightkey_swap[(right >> 25) & 0xf])
-          | (rightkey_swap[(right >> 4) & 0xf] << 7)
-          | (rightkey_swap[(right >> 12) & 0xf] << 6)
-          | (rightkey_swap[(right >> 20) & 0xf] << 5)
-          | (rightkey_swap[(right >> 28) & 0xf] << 4));
+           | (rightkey_swap[(right >> 9) & 0xf] << 2)
+           | (rightkey_swap[(right >> 17) & 0xf] << 1)
+           | (rightkey_swap[(right >> 25) & 0xf])
+           | (rightkey_swap[(right >> 4) & 0xf] << 7)
+           | (rightkey_swap[(right >> 12) & 0xf] << 6)
+           | (rightkey_swap[(right >> 20) & 0xf] << 5)
+           | (rightkey_swap[(right >> 28) & 0xf] << 4));
 
   right &= 0x0fffffff;
 
   for (round = 0; round < 16; ++round)
     {
       left = ((left << encrypt_rotate_tab[round])
-             | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
+              | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
       right = ((right << encrypt_rotate_tab[round])
-              | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
+               | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
 
       *subkey++ = (((left << 4) & 0x24000000)
-                  | ((left << 28) & 0x10000000)
-                  | ((left << 14) & 0x08000000)
-                  | ((left << 18) & 0x02080000)
-                  | ((left << 6) & 0x01000000)
-                  | ((left << 9) & 0x00200000)
-                  | ((left >> 1) & 0x00100000)
-                  | ((left << 10) & 0x00040000)
-                  | ((left << 2) & 0x00020000)
-                  | ((left >> 10) & 0x00010000)
-                  | ((right >> 13) & 0x00002000)
-                  | ((right >> 4) & 0x00001000)
-                  | ((right << 6) & 0x00000800)
-                  | ((right >> 1) & 0x00000400)
-                  | ((right >> 14) & 0x00000200)
-                  | (right & 0x00000100)
-                  | ((right >> 5) & 0x00000020)
-                  | ((right >> 10) & 0x00000010)
-                  | ((right >> 3) & 0x00000008)
-                  | ((right >> 18) & 0x00000004)
-                  | ((right >> 26) & 0x00000002)
-                  | ((right >> 24) & 0x00000001));
+                   | ((left << 28) & 0x10000000)
+                   | ((left << 14) & 0x08000000)
+                   | ((left << 18) & 0x02080000)
+                   | ((left << 6) & 0x01000000)
+                   | ((left << 9) & 0x00200000)
+                   | ((left >> 1) & 0x00100000)
+                   | ((left << 10) & 0x00040000)
+                   | ((left << 2) & 0x00020000)
+                   | ((left >> 10) & 0x00010000)
+                   | ((right >> 13) & 0x00002000)
+                   | ((right >> 4) & 0x00001000)
+                   | ((right << 6) & 0x00000800)
+                   | ((right >> 1) & 0x00000400)
+                   | ((right >> 14) & 0x00000200)
+                   | (right & 0x00000100)
+                   | ((right >> 5) & 0x00000020)
+                   | ((right >> 10) & 0x00000010)
+                   | ((right >> 3) & 0x00000008)
+                   | ((right >> 18) & 0x00000004)
+                   | ((right >> 26) & 0x00000002)
+                   | ((right >> 24) & 0x00000001));
 
       *subkey++ = (((left << 15) & 0x20000000)
-                  | ((left << 17) & 0x10000000)
-                  | ((left << 10) & 0x08000000)
-                  | ((left << 22) & 0x04000000)
-                  | ((left >> 2) & 0x02000000)
-                  | ((left << 1) & 0x01000000)
-                  | ((left << 16) & 0x00200000)
-                  | ((left << 11) & 0x00100000)
-                  | ((left << 3) & 0x00080000)
-                  | ((left >> 6) & 0x00040000)
-                  | ((left << 15) & 0x00020000)
-                  | ((left >> 4) & 0x00010000)
-                  | ((right >> 2) & 0x00002000)
-                  | ((right << 8) & 0x00001000)
-                  | ((right >> 14) & 0x00000808)
-                  | ((right >> 9) & 0x00000400)
-                  | ((right) & 0x00000200)
-                  | ((right << 7) & 0x00000100)
-                  | ((right >> 7) & 0x00000020)
-                  | ((right >> 3) & 0x00000011)
-                  | ((right << 2) & 0x00000004)
-                  | ((right >> 21) & 0x00000002));
+                   | ((left << 17) & 0x10000000)
+                   | ((left << 10) & 0x08000000)
+                   | ((left << 22) & 0x04000000)
+                   | ((left >> 2) & 0x02000000)
+                   | ((left << 1) & 0x01000000)
+                   | ((left << 16) & 0x00200000)
+                   | ((left << 11) & 0x00100000)
+                   | ((left << 3) & 0x00080000)
+                   | ((left >> 6) & 0x00040000)
+                   | ((left << 15) & 0x00020000)
+                   | ((left >> 4) & 0x00010000)
+                   | ((right >> 2) & 0x00002000)
+                   | ((right << 8) & 0x00001000)
+                   | ((right >> 14) & 0x00000808)
+                   | ((right >> 9) & 0x00000400)
+                   | ((right) & 0x00000200)
+                   | ((right << 7) & 0x00000100)
+                   | ((right >> 7) & 0x00000020)
+                   | ((right >> 3) & 0x00000011)
+                   | ((right << 2) & 0x00000004)
+                   | ((right >> 21) & 0x00000002));
     }
 }
 
@@ -592,7 +589,7 @@ gl_3des_set2keys (gl_3des_ctx *ctx, const char * key1, const char * key2)
 
 void
 gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1,
-                   const char * key2, const char * key3)
+                    const char * key2, const char * key3)
 {
   int i;
 
@@ -615,8 +612,8 @@ gl_3des_set3keys (gl_3des_ctx *ctx, const char * key1,
 
 void
 gl_3des_ecb_crypt (gl_3des_ctx *ctx,
-                  const char * _from,
-                  char * _to, int mode)
+                   const char * _from,
+                   char * _to, int mode)
 {
   const unsigned char *from = (const unsigned char *) _from;
   unsigned char *to = (unsigned char *) _to;
@@ -664,6 +661,6 @@ gl_3des_makekey (gl_3des_ctx *ctx, const char * key, size_t keylen)
   gl_3des_set3keys (ctx, key, key + 8, key + 16);
 
   return !(gl_des_is_weak_key (key)
-          || gl_des_is_weak_key (key + 8)
-          || gl_des_is_weak_key (key + 16));
+           || gl_des_is_weak_key (key + 8)
+           || gl_des_is_weak_key (key + 16));
 }