공통 blowfish java source

황제낙엽 2010.05.16 06:54 조회 수 : 507 추천:51

sitelink1 http://www.angelfire.com/moon/dmp/ 
sitelink2  
sitelink3 http://1 
sitelink4 http://ko 
extra_vars5  
extra_vars6 sitelink1 

BLOWFISH ENCRYPTION WRITTEN IN JAVA!!!

The Blowfish Encryption Algorithm -- One Year Later

B. Schneier

Dr. Dobb's Journal, September 1995.

DES is the workhorse of cryptography algorithms, and it's long past time to replace the 19-year-old standard. The recent design of a $1M machine that could recover a DES key in 3.5 hours only confirmed what everybody knew: DES's key size is far too small for today.

The world only partly trusted DES because it survived the scrutiny of the NSA. Experts trusted DES because it was a published standard, and because it survived 20 years of intensive cryptanalysis by cryptographers around the world. Cryptography is like that: confidence in an algorithm grows as group after group tries to break it and fails.

Candidates for a replacement are emerging, but none has taken widespread hold. Triple-DES is the conservative approach; IDEA (used in PGP) is the most promising new algorithm. And there is a bevy of unpatented also-rans: RC4 (once a trade secret of RSA Data Security, Inc. but now publicly available on the Internet), SAFER, and my own Blowfish.

I first presented Blowfish at the Cambridge Algorithms Workshop ("Description of a New Variable-Length Key, 64-bit Block Cipher (Blowfish)," Fast Software Encryption, R. Anderson, ed., Lecture Notes in Computer Science #809, Springer-Verlag, 1994) and in Dr. Dobb's Journal (April 1994). From the start Blowfish was intended to be a completely free--unpatented, unlicensed, and uncopyrighted--alternative to DES. Since then it has been analyzed by some people and has started to see use in some systems, both public and private. This article presents new Blowfish code, as well as updates on the algorithm's security.

Description of Blowfish

Blowfish is a block cipher that encrypts data in 8-byte blocks. The algorithm consists of two parts: a key-expansion part and a data-encryption part. Key expansion converts a variable-length key of at most 56 bytes (448 bits) into several subkey arrays totaling 4168 bytes. (Note: the description in this article differs slightly from the one in the April 1994 issue of Dr. Dobb's Journal; there were typos in steps (5) and (6) of the subkey generation algorithm.)

Blowfish has 16 rounds. Each round consists of a key-dependent permutation, and a key- and data-dependent substitution. All operations are XORs and additions on 32-bit words. The only additional operations are four indexed array data lookups per round.

Subkeys:

Blowfish uses a large number of subkeys. These keys must be precomputed before any data encryption or decryption. The P-array consists of 18 32-bit subkeys: P1, P2,..., P18. There are also four 32-bit S-boxes with 256 entries each: S1,0, S1,1,..., S1,255; S2,0, S2,1,..,, S2,255; S3,0, S3,1,..., S3,255; S4,0, S4,1,..,, S4,255.

Encryption and Decryption:

Blowfish has 16 rounds. The input is a 64-bit data element, x. Divide x into two 32-bit halves: xL, xR. Then, for i = 1 to 16:

xL = xL XOR Pi
xR = F(xL) XOR xR
Swap xL and xR

After the sixteenth round, swap xL and xR again to undo the last swap. Then, xR = xR XOR P17 and xL = xL XOR P18. Finally, recombine xL and xR to get the ciphertext.

Function F looks like this: Divide xL into four eight-bit quarters: a, b, c, and d. Then, F(xL) = ((S1,a + S2,b mod 232) XOR S3,c) + S4,d mod 232.

Decryption is exactly the same as encryption, except that P1, P2,..., P18 are used in the reverse order.

Generating the Subkeys:

The subkeys are calculated using the Blowfish algorithm:

1. Initialize first the P-array and then the four S-boxes, in order, with a fixed string. This string consists of the hexadecimal digits of pi (less the initial 3): P1 = 0x243f6a88, P2 = 0x85a308d3, P3 = 0x13198a2e, P4 = 0x03707344, etc.

2. XOR P1 with the first 32 bits of the key, XOR P2 with the second 32-bits of the key, and so on for all bits of the key (possibly up to P14). Repeatedly cycle through the key bits until the entire P-array has been XORed with key bits. (For every short key, there is at least one equivalent longer key; for example, if A is a 64-bit key, then AA, AAA, etc., are equivalent keys.)

3. Encrypt the all-zero string with the Blowfish algorithm, using the subkeys described in steps (1) and (2).

4. Replace P1 and P2 with the output of step (3).

5. Encrypt the output of step (3) using the Blowfish algorithm with the modified subkeys.

6. Replace P3 and P4 with the output of step (5).

7. Continue the process, replacing all entries of the P array, and then all four S-boxes in order, with the output of the continuously changing Blowfish algorithm.

In total, 521 iterations are required to generate all required subkeys. Applications can store the subkeys rather than execute this derivation process multiple times.

C Code:

C code for Blowfish starts on page xx. This is improved and corrected code; the code in the April 1994 issue had some bugs and was less efficient than this code. The code is also available electronically; see "Availability," page xx.

Cryptanalysis of Blowfish

When I first presented Blowfish last year, Dr. Dobb's Journal sponsored a cryptanalysis contest. There were five submissions in total, and I am pleased to present the most interesting results here.

John Kelsey developed an attack that could break 3-round Blowfish, but was unable to extend it. This attack exploits the F function and the fact that addition mod 232 and XOR do not commute. Vikramjit Singh Chhabra looked at ways of efficiently implementing a brute-force keysearch machine.

Serge Vaudenay examined a simplified variant of Blowfish, with the S-boxes known and not key-dependent. For this variant, a differential attack can recover the P-array with 28r+1 chosen plaintexts (r is the number of rounds). This attack is impossible for 8-round Blowfish and higher, since more plaintext is required than can possibly be generated with a 64-bit block cipher.

For certain weak keys that generate weak S-boxes (the odds of getting them randomly are 1 in 214), the same attack requires only 24r+1 chosen plaintexts to recover the P-array (again, assuming the S-boxes are known). With unknown S-boxes, this attack can detect whether a weak key is being used, but cannot determine what it is (neither the S-boxes, the P-array, nor the key itself). This attack only works against reduced-round variants; it is completely ineffective against 16-round Blowfish.

Even so, the discovery of weak keys in Blowfish is significant. A weak key is one for which two entries for a given S-box are identical. There is no way to check for weak keys before doing the key expansion. If you are worried, you have to do the key expansion and check for identical S-box entries after you generate a Blowfish key. I don't think it's necessary, though.

Conclusion

No one has come close to developing an attack that breaks Blowfish. Even so, more cryptanalysis is required before pronouncing the algorithm secure. I invite others to continue analyzing the algorithm.

 

 

The BlowFish Encryption Tools In Java Programming

 

Screen Shot

The Java Implementation:

Method BF_Encrypt: This method is only called by the makeKey method to generate a session key from user data. It outputs the result to an int array.

 

Method blowfishDecrypt: The normal entry to the decryption process. It is guaranteed to be called with enough bytes in the input to carry on a decryption of one full block. Because the Blowfish cipher engine is designed to handle two 32-bit blocks, this method's purpose is to transform on entry and exit the data to/from 32-bit blocks; ie. Java.int. The input becomes two 32-bit blocks as Left and Right halves onto which the Blowfish cipher function is applied ROUNDS times in reverse order to that of the encryption.

 

Method blowfishEncrypt The normal entry to the encryption process. It is guaranteed to be called with enough bytes in the input to carry on an encryption of one full block. The code of the Blowfish encryption engine, found here, is also             replicated in the BF_encrypt method found later. The reason for            this duplication is performance. This method, outputs the result in a byte array form, suitable for the user data encryption operations, while BF_encrypt outputs its result as an int array suitable for, and used during, the expansion of the user-key into a Blowfish session key.

 

Method engineInitEncrypt  Initializes this cipher for encryption, using the specified key.

 

Method engineInitDecrypt  Initializes this cipher for decryption, using the specified

key.

 

Method engineUpdate  Performs the actual encryption or decryption process

 

 

Method makeKey. Expands a userKey to a working Blowfish session key (P) and generates this session s-boxes data (sKey). The key bytes are fist extracted from the user-key and then used, repetitively if need be, to build the contents of this            session key and S-boxes values.           The method's only exceptions are when the user-key's contents is a null Java object or a byte array of zero length. Otherwise the key data -up to 56 bytes- are used repetitively.

 

DOWNLOAD THE JAVA SOURCE CODE Now !!!

We provide partial of the source code but having the full work functioning program written in java

To get the complete source code, please email us.

tss2004@lycos.co.uk

US 15 for Full Complete Source Code

  • Able to encrypt all kind of file type such as mpeg, mp3 and etc.

  • Able to encrypt largest file type without limited file size



  •  
번호 제목 sitelink1 글쓴이 날짜 조회 수
공지 [계속 추가중] SBOM 용어 정의   황제낙엽 2025.04.10 52
공지 [계속 추가중] Keycloak 용어 및 설정 옵션 정의   황제낙엽 2024.02.02 631
30 OpenSSL 설치   황제낙엽 2024.11.12 115
29 서버의 인증서 파일을 갱신후 브라우저의 인증서 뷰어에서 새 인증서 정보가 조회되지 않을 경우   황제낙엽 2024.08.23 109
28 SSL 인증서 파일 포맷 종류 - crt, cer, csr, pem, der, pfx, p12, jks, key https://www.securesign.kr/guides/kb/54  황제낙엽 2020.07.20 165
27 SNI 기반 HTTPS 사이트 차단 file https://blog.naver.com/aepkoreanet/221465526990  황제낙엽 2020.03.04 170
26 사설인증서 공인인증서 구분 방법 file   황제낙엽 2019.07.16 186
25 Convert Certificate Format SSL 인증서 변환 가이드 https://www.securesign.kr/guides/SSL-Cer...ert-Format  황제낙엽 2019.03.29 199
24 *.key와 *.crt를 PKCS#12(*.pfx, *.p12)로 형식으로 변환하기 https://www.eznbiz.co.kr/help/qna/content/3  황제낙엽 2019.03.29 213
23 HOWTO: DER vs. CRT vs. CER vs. PEM Certificates and How To Convert Them http://info.ssl.com/article.aspx?id=12149  황제낙엽 2019.03.29 869
22 How to convert a certificate file from .crt to .cer? file https://www.sonicwall.com/support/knowle...597576961/  황제낙엽 2019.03.29 661
21 국내(KOREA) IP 사용 대역 file http://www.domain.kr  황제낙엽 2019.02.21 360
20 서버 보안 관리를 위한 백업과 점검 절차   황제낙엽 2017.05.30 201
19 정보 보안 개론 : 네이버 지식백과 http://terms.naver.com/list.nhn?cid=5843...ryId=58437  황제낙엽 2017.05.19 191
18 개발용 tomcat 운용시 tomcat-users.xml 의 관리 주의   황제낙엽 2017.04.07 391
17 윈도우 원격데스크톱(RDP) 접근 이력 조회 file http://skylit.tistory.com/196  황제낙엽 2017.04.06 243
16 SSL, TLS, OpenSSL 관련 http://kin.naver.com/qna/detail.nhn?d1id...K9fw%3D%3D  황제낙엽 2015.12.31 217
15 운영 모드 ( Mode of Operation )   황제낙엽 2013.03.07 347
14 암호화 알고리즘 스크랩   황제낙엽 2012.08.28 3076
13 미연방 표준 암호 알고리즘 http://rustican.com/board/zboard.php?id=paper&no=140  황제낙엽 2010.05.21 285
» blowfish java source file http://www.angelfire.com/moon/dmp/  황제낙엽 2010.05.16 507
11 파일 해쉬 알고리즘 CRC   황제낙엽 2009.12.01 409