ChangeLog entry for EPILOGUE fix.
[gd/nettle] / des.c
diff --git a/des.c b/des.c
index 7faadd0e52ffb6ad7b8530d63b808ddae267ea7d..ebde9351a91b13adbe7fac10ca27715845a0f5fd 100644 (file)
--- a/des.c
+++ b/des.c
@@ -1,28 +1,36 @@
 /* des.c
- *
- * The des block cipher.
- *
- */
 
-/* nettle, low-level cryptographics library
- *
- * Copyright (C) 2001 Niels Möller
- *  
- * The nettle library is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at your
- * option) any later version.
- * 
- * The nettle library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with the nettle library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
- */
+   The des block cipher.
+
+   Copyright (C) 2001, 2010 Niels Möller
+   Copyright (C) 1992  Dana L. How
+
+   This file is part of GNU Nettle.
+
+   GNU Nettle is free software: you can redistribute it and/or
+   modify it under the terms of either:
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at your
+       option) any later version.
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at your
+       option) any later version.
+
+   or both in parallel, as here.
+
+   GNU Nettle is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see http://www.gnu.org/licenses/.
+*/
 
 /*     des - fast & portable DES encryption & decryption.
  *     Copyright (C) 1992  Dana L. How
@@ -65,9 +73,9 @@ parity_16[16] =
 #define PARITY(x) (parity_16[(x)&0xf] ^ parity_16[((x)>>4) & 0xf])
 
 int
-des_check_parity(unsigned length, const uint8_t *key)
+des_check_parity(size_t length, const uint8_t *key)
 {
-  unsigned i;
+  size_t i;
   for (i = 0; i<length; i++)
     if (!PARITY(key[i]))
       return 0;
@@ -76,10 +84,10 @@ des_check_parity(unsigned length, const uint8_t *key)
 }
 
 void
-des_fix_parity(unsigned length, uint8_t *dst,
+des_fix_parity(size_t length, uint8_t *dst,
               const uint8_t *src)
 {
-  unsigned i;
+  size_t i;
   for (i = 0; i<length; i++)
     dst[i] = src[i] ^ PARITY(src[i]) ^ 1;
 }
@@ -165,10 +173,13 @@ des_weak_p(const uint8_t *key)
   int8_t k1 = key[1] >> 1;
 
   unsigned hash = asso_values[k1 + 1] + asso_values[k0];
-  const int8_t *candidate = weak_key_hash[hash];
+  const int8_t *candidate;
 
   if (hash > 25)
     return 0;
+
+  candidate = weak_key_hash[hash];
+
   if (k0 != candidate[0]
       || k1 != candidate[1])
     return 0;
@@ -265,7 +276,7 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key)
 
 void
 des_encrypt(const struct des_ctx *ctx,
-           unsigned length, uint8_t *dst,
+           size_t length, uint8_t *dst,
            const uint8_t *src)
 {
   assert(!(length % DES_BLOCK_SIZE));
@@ -281,7 +292,7 @@ des_encrypt(const struct des_ctx *ctx,
 
 void
 des_decrypt(const struct des_ctx *ctx,
-           unsigned length, uint8_t *dst,
+           size_t length, uint8_t *dst,
            const uint8_t *src)
 {
   assert(!(length % DES_BLOCK_SIZE));