X-Git-Url: https://git.distorted.org.uk/~mdw/userv-utils/blobdiff_plain/2dc682257fa1bb6a443c69c56ed724ec3b8dffd9..0fe65164e3f6f9ae58e4912dcc19f7e0ab3c41a6:/ipif/blowfish.c diff --git a/ipif/blowfish.c b/ipif/blowfish.c index 0f5e679..6731c8e 100644 --- a/ipif/blowfish.c +++ b/ipif/blowfish.c @@ -4,12 +4,27 @@ * 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. + */ +/* + * Copyright (C) 1997,2000 Ian Jackson + * + * 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 2 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, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* TODO: test with zero length key */ /* TODO: test with a through z as key and plain text */ -/* TODO: make this byte order independent */ #include #include @@ -26,8 +41,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 +63,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 +85,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 +121,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 +132,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 +142,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 +163,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);