chiark / gitweb /
www-cgi: Add Mark Wooding's copyright notice
[userv-utils.git] / ipif / blowfish.c
index 0f5e679654354787185db0d6a03a73d07e93f7dc..bf62a7e62362a13ed5e38243582c16dd02e4cd89 100644 (file)
@@ -4,12 +4,32 @@
  * Algorithm by Bruce Schneier 1995
  * This implementation adapted from a public domain version by Bruce
  * Schneier (1995) by Ian Jackson in 1997.
- * Copyright (C)1997 Ian Jackson.
+ */
+/*
+ * This file is part of ipif, part of userv-utils
+ *
+ * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
+ * Copyright 1999,2003
+ *    Chancellor Masters and Scholars of the University of Cambridge
+ * Copyright 2010 Tony Finch <fanf@dotat.at>
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with userv-utils; if not, see http://www.gnu.org/licenses/.
  */
 
 /* TODO: test with zero length key */
 /* TODO: test with a through z as key and plain text */
-/* TODO: make this byte order independent */
 
 #include <assert.h>
 #include <string.h>
@@ -26,8 +46,9 @@ static const blowfish__s init_s;
 #define GETWORD(p) (((p)[0]<<24)|((p)[1]<<16)|((p)[2]<<8)|((p)[3]))
 #define PUTWORD(w,p) ((p)[0]=(w)>>24,(p)[1]=(w)>>16,(p)[2]=(w)>>8,(p)[3]=(w))
 
-static void encipher(const struct blowfish_expandedkey *ek, uint32 *xlp, uint32 *xrp) {
-  uint32 xl, xr;
+static void encipher(const struct blowfish_expandedkey *ek,
+                    uint32_t *xlp, uint32_t *xrp) {
+  uint32_t xl, xr;
 
   xl= *xlp;
   xr= *xrp;
@@ -47,8 +68,9 @@ static void encipher(const struct blowfish_expandedkey *ek, uint32 *xlp, uint32
   *xlp= xr;
 }
 
-static void decipher(const struct blowfish_expandedkey *ek, uint32 *xlp, uint32 *xrp) {
-  uint32 xl, xr;
+static void decipher(const struct blowfish_expandedkey *ek,
+                    uint32_t *xlp, uint32_t *xrp) {
+  uint32_t xl, xr;
 
   xl= *xlp;
   xr= *xrp;
@@ -68,9 +90,10 @@ static void decipher(const struct blowfish_expandedkey *ek, uint32 *xlp, uint32
   *xrp= xl;
 }
 
-void blowfish_loadkey(struct blowfish_expandedkey *ek, const uint8 *key, int keybytes) {
+void blowfish_loadkey(struct blowfish_expandedkey *ek,
+                     const uint8_t *key, int keybytes) {
   int i, j;
-  uint32 data, datal, datar;
+  uint32_t data, datal, datar;
 
   assert(keybytes>0 && keybytes<=BLOWFISH_MAXKEYBYTES);
   memcpy(ek->s,init_s,sizeof(ek->s));
@@ -103,8 +126,8 @@ void blowfish_loadkey(struct blowfish_expandedkey *ek, const uint8 *key, int key
 }
 
 void blowfish_encrypt(const struct blowfish_expandedkey *ek,
-                     const uint8 plain[], uint8 cipher[]) {
-  uint32 datal, datar;
+                     const uint8_t plain[], uint8_t cipher[]) {
+  uint32_t datal, datar;
 
   datal= GETWORD(plain);
   datar= GETWORD(plain+4);
@@ -114,8 +137,8 @@ void blowfish_encrypt(const struct blowfish_expandedkey *ek,
 }
 
 void blowfish_decrypt(const struct blowfish_expandedkey *ek,
-                     const uint8 cipher[], uint8 plain[]) {
-  uint32 datal, datar;
+                     const uint8_t cipher[], uint8_t plain[]) {
+  uint32_t datal, datar;
 
   datal= GETWORD(cipher);
   datar= GETWORD(cipher+4);
@@ -124,14 +147,14 @@ void blowfish_decrypt(const struct blowfish_expandedkey *ek,
   PUTWORD(datar,plain+4);
 }
 
-void blowfish_cbc_setiv(struct blowfish_cbc_state *cs, const uint8 iv[]) {
+void blowfish_cbc_setiv(struct blowfish_cbc_state *cs, const uint8_t iv[]) {
   cs->chainl= GETWORD(iv);
   cs->chainr= GETWORD(iv+4);
 }
 
 void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs,
-                         const uint8 plain[], uint8 cipher[]) {
-  uint32 datal, datar;
+                         const uint8_t plain[], uint8_t cipher[]) {
+  uint32_t datal, datar;
 
   datal= GETWORD(plain);
   datar= GETWORD(plain+4);
@@ -145,8 +168,8 @@ void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs,
 }
 
 void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs,
-                         const uint8 cipher[], uint8 plain[]) {
-  uint32 datal, datar, cipherl, cipherr;
+                         const uint8_t cipher[], uint8_t plain[]) {
+  uint32_t datal, datar, cipherl, cipherr;
 
   datal= GETWORD(cipher);
   datar= GETWORD(cipher+4);