chiark / gitweb /
New encrypting tunnel seems to work !
[userv-utils.git] / ipif / blowfish.c
index 0f5e679654354787185db0d6a03a73d07e93f7dc..fd7f631a7b136f93bf6c238242dc08ffc393a5f9 100644 (file)
@@ -9,7 +9,6 @@
 
 /* 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 +25,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 +47,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 +69,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 +105,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 +116,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 +126,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 +147,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);