/* 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);