maint: update copyright
[gnulib.git] / lib / arctwo.c
index baf3c61..7eae9d7 100644 (file)
@@ -1,5 +1,5 @@
 /* arctwo.c --- The RC2 cipher as described in RFC 2268.
- * Copyright (C) 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
+ * Copyright (C) 2003-2006, 2008-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
@@ -12,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/>.
  */
 
 /* Code from GnuTLS/Libgcrypt adapted for gnulib by Simon Josefsson. */
@@ -69,7 +67,7 @@ static const uint8_t arctwo_sbox[] = {
 };
 
 /* C89 compliant way to cast 'char' to 'unsigned char'. */
-static inline unsigned char
+static unsigned char
 to_uchar (char ch)
 {
   return ch;
@@ -77,10 +75,10 @@ to_uchar (char ch)
 
 void
 arctwo_encrypt (arctwo_context *context, const char *inbuf,
-               char *outbuf, size_t length)
+                char *outbuf, size_t length)
 {
   for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE,
-        inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
+         inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
     {
       size_t i, j;
       uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0;
@@ -95,29 +93,29 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf,
       word3 = (word3 << 8) | to_uchar (inbuf[6]);
 
       for (i = 0; i < 16; i++)
-       {
-         j = i * 4;
-         /* For some reason I cannot combine those steps. */
-         word0 += (word1 & ~word3) + (word2 & word3) + context->S[j];
-         word0 = rotl16 (word0, 1);
-
-         word1 += (word2 & ~word0) + (word3 & word0) + context->S[j + 1];
-         word1 = rotl16 (word1, 2);
-
-         word2 += (word3 & ~word1) + (word0 & word1) + context->S[j + 2];
-         word2 = rotl16 (word2, 3);
-
-         word3 += (word0 & ~word2) + (word1 & word2) + context->S[j + 3];
-         word3 = rotl16 (word3, 5);
-
-         if (i == 4 || i == 10)
-           {
-             word0 += context->S[word3 & 63];
-             word1 += context->S[word0 & 63];
-             word2 += context->S[word1 & 63];
-             word3 += context->S[word2 & 63];
-           }
-       }
+        {
+          j = i * 4;
+          /* For some reason I cannot combine those steps. */
+          word0 += (word1 & ~word3) + (word2 & word3) + context->S[j];
+          word0 = rotl16 (word0, 1);
+
+          word1 += (word2 & ~word0) + (word3 & word0) + context->S[j + 1];
+          word1 = rotl16 (word1, 2);
+
+          word2 += (word3 & ~word1) + (word0 & word1) + context->S[j + 2];
+          word2 = rotl16 (word2, 3);
+
+          word3 += (word0 & ~word2) + (word1 & word2) + context->S[j + 3];
+          word3 = rotl16 (word3, 5);
+
+          if (i == 4 || i == 10)
+            {
+              word0 += context->S[word3 & 63];
+              word1 += context->S[word0 & 63];
+              word2 += context->S[word1 & 63];
+              word3 += context->S[word2 & 63];
+            }
+        }
 
       outbuf[0] = word0 & 255;
       outbuf[1] = word0 >> 8;
@@ -132,10 +130,10 @@ arctwo_encrypt (arctwo_context *context, const char *inbuf,
 
 void
 arctwo_decrypt (arctwo_context *context, const char *inbuf,
-               char *outbuf, size_t length)
+                char *outbuf, size_t length)
 {
   for (; length >= ARCTWO_BLOCK_SIZE; length -= ARCTWO_BLOCK_SIZE,
-        inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
+         inbuf += ARCTWO_BLOCK_SIZE, outbuf += ARCTWO_BLOCK_SIZE)
     {
       size_t i, j;
       uint16_t word0 = 0, word1 = 0, word2 = 0, word3 = 0;
@@ -150,29 +148,29 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf,
       word3 = (word3 << 8) | to_uchar (inbuf[6]);
 
       for (i = 16; i > 0; i--)
-       {
-         j = (i - 1) * 4;
+        {
+          j = (i - 1) * 4;
 
-         word3 = rotr16 (word3, 5);
-         word3 -= (word0 & ~word2) + (word1 & word2) + context->S[j + 3];
+          word3 = rotr16 (word3, 5);
+          word3 -= (word0 & ~word2) + (word1 & word2) + context->S[j + 3];
 
-         word2 = rotr16 (word2, 3);
-         word2 -= (word3 & ~word1) + (word0 & word1) + context->S[j + 2];
+          word2 = rotr16 (word2, 3);
+          word2 -= (word3 & ~word1) + (word0 & word1) + context->S[j + 2];
 
-         word1 = rotr16 (word1, 2);
-         word1 -= (word2 & ~word0) + (word3 & word0) + context->S[j + 1];
+          word1 = rotr16 (word1, 2);
+          word1 -= (word2 & ~word0) + (word3 & word0) + context->S[j + 1];
 
-         word0 = rotr16 (word0, 1);
-         word0 -= (word1 & ~word3) + (word2 & word3) + context->S[j];
+          word0 = rotr16 (word0, 1);
+          word0 -= (word1 & ~word3) + (word2 & word3) + context->S[j];
 
-         if (i == 6 || i == 12)
-           {
-             word3 = word3 - context->S[word2 & 63];
-             word2 = word2 - context->S[word1 & 63];
-         word1 = word1 - context->S[word0 & 63];
-         word0 = word0 - context->S[word3 & 63];
-           }
-       }
+          if (i == 6 || i == 12)
+            {
+              word3 = word3 - context->S[word2 & 63];
+              word2 = word2 - context->S[word1 & 63];
+          word1 = word1 - context->S[word0 & 63];
+          word0 = word0 - context->S[word3 & 63];
+            }
+        }
 
       outbuf[0] = word0 & 255;
       outbuf[1] = word0 >> 8;
@@ -187,7 +185,7 @@ arctwo_decrypt (arctwo_context *context, const char *inbuf,
 
 void
 arctwo_setkey_ekb (arctwo_context *context,
-                  size_t keylen, const char *key, size_t effective_keylen)
+                   size_t keylen, const char *key, size_t effective_keylen)
 {
   size_t i;
   uint8_t *S, x;
@@ -216,10 +214,10 @@ arctwo_setkey_ekb (arctwo_context *context,
       S[i] = x;
 
       while (i--)
-       {
-         x = arctwo_sbox[x ^ S[i + len]];
-         S[i] = x;
-       }
+        {
+          x = arctwo_sbox[x ^ S[i + len]];
+          S[i] = x;
+        }
     }
 
   /* Make the expanded key, endian independent. */