X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Farctwo.c;h=27b7c1bd9d027f3858d316a22181badfa1e11819;hb=3ac9b4577c78342bdd022b31cf56de2b12f7297b;hp=baf3c615e5376e4f6a1d1d33b3d1ddc4ab79b156;hpb=ca19d955ebaa690b5580bb8c18ca20ab5daf8fff;p=gnulib.git diff --git a/lib/arctwo.c b/lib/arctwo.c index baf3c615e..27b7c1bd9 100644 --- a/lib/arctwo.c +++ b/lib/arctwo.c @@ -1,5 +1,6 @@ /* arctwo.c --- The RC2 cipher as described in RFC 2268. - * Copyright (C) 2003, 2004, 2005, 2006, 2008 Free Software Foundation, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 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 @@ -77,10 +78,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 +96,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 +133,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 +151,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 +188,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 +217,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. */