* 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 <assert.h>
#include <string.h>
#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;
*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;
*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));
}
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);
}
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);
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);
}
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);