Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Blowfish between C++ and Java

843810Aug 1 2004 — edited Aug 2 2004
I am looking for advice from someone experienced with the Blowfish algorithm. I need to be able to exchange encrypted messages with another system that I think has a non-standard implemenation of Blowfish. This other system is written in C++. I think the problem is the mode parameter of the Ciper.getInstance(). The source code for the C++ has three modes "none", ECB and CBC. Although the only one available for this particular integration is the "none" because of existing code that can not be changed. Based on all of the docuementation that I have been able to find on Java implementations ECB is supposed to be the equivalant of no mode. But this does not match the C++ code, hence my statement that it is non-standard.

Listed below is some of the code for the calls to encrypt using the no mode option of the C++ program. What I would like is help from someone to tell me if there is an equivalant mode in Sun's or one of the Java Open Source implementations of Blowfish.

Thanks for taking the time to read my message
Timothy Vogel
/* sample call in client program requesting encryption */
Blowfish.blf_enc(context, data, numBlocks);

/* library source code */
/* Function for Feistel Networks */

#define F(s, x) ((((s)[        (((x)>>24)&0xFF)]  \
		 + (s)[0x100 + (((x)>>16)&0xFF)]) \
		 ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \
		 + (s)[0x300 + ( (x)     &0xFF)])

#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])


void CBlowFish::blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
{
	u_int32_t *d;
	u_int16_t i;

	d = data;
	for (i = 0; i < blocks; i++) {
		Blowfish_encipher(c, d, d + 1);
		d += 2;
	}
}

void CBlowFish::Blowfish_encipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr)
{
	u_int32_t Xl;
	u_int32_t Xr;
	u_int32_t *s = c->S[0];
	u_int32_t *p = c->P;

	Xl = *xl;
	Xr = *xr;

	Xl ^= p[0];
	BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2);
	BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4);
	BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6);
	BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8);
	BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10);
	BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12);
	BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14);
	BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16);

	*xl = Xr ^ p[17];
	*xr = Xl;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2004
Added on Aug 1 2004
1 comment
308 views