8月 10th, 2010

Java暗号化の鍵長と暗号化・? 合化処理時間

Posted in Java by admin

 以前、SunJava暗号化強度の制限解除の話題を挙げましたが、具? 的に暗号化強度を強化する鍵長を変更することによって処理時間に影響しないか確? してみました。使用したのは以下のような単純なコードで、暗号化方? ぜ AES, Blowfishを使っています。なお、処理時間には、暗号化したデータをBASE64で可読化する時間も含まれています。(暗号化後複合化後の? 果を出力で確認する? )

//enc
cipher  = Cipher.getInstance( "AES/CBC/PKCS5Padding" );
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(128);
SecretKey skey = keyGen.generateKey();
cipher.init( Cipher.ENCRYPT_MODE, skey );
encParam = cipher.getParameters().getEncoded(); //Blowfishは? 要

//dec
AlgorithmParameters saprm = AlgorithmParameters.getInstance("AES"); //Blowfishは? 要
saParam.init( encParam ); //Blowfishは? 要
cipher.init( Cipher.DECRYPT_MODE, skeySpec, saParam );

 3行盜 keyGen.initのところで、ビット数を指定します。ちなみに制限解除しないぜ AESぜ 192bit以? の場合では、以? のようぜ Exceptionが出力されます。

# /usr/jdk/bin/java Cipher enc hogehoge
Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters
	at javax.crypto.Cipher.a(DashoA13*..)
	at javax.crypto.Cipher.a(DashoA13*..)
	at javax.crypto.Cipher.a(DashoA13*..)
	at javax.crypto.Cipher.init(DashoA13*..)
	at javax.crypto.Cipher.init(DashoA13*..)
	at Cipher.EncryptData(Cipher.java:76)
	at Cipher.main(Cipher.java:125)

 結果は以下のように、処理時間は鍵長によっては左右されないようになりました。hpprof(-agentlib:hprof=cpu=times)によるメソッドのプロファイル? 果でも、javax.crypto.*, com.sun.crypto.*クラスは合計しても全? ぜ 1%に机 たない軽い処理のように? えます。鍵長はあぜ まで「解読」(総当たり攻撃的な割り出し)の処理に影響するのであって、鍵の判昜 している「複合」の処理時間には影響しないと圏 け圏 れます。当たり前といえば確かにそうですが。

暗号化のぜ 
AES 128bit: 0.306sec
AES 192bit: 0.304sec
AES 256bit: 0.304sec
Blowfish  32bit: 0.252sec
Blowfish 128bit: 0.253sec
Blowfish 192bit: 0.253sec
Blowfish 256bit: 0.252sec
Blowfish 448bit: 0.253sec
暗号化+複合化
AES 128bit: 0.303sec
AES 192bit: 0.304sec
AES 256bit: 0.304sec
Blowfish  32bit: 0.254sec
Blowfish 128bit: 0.253sec
Blowfish 192bit: 0.253sec
Blowfish 256bit: 0.253sec
Blowfish 448bit: 0.254sec
hpprof例 AES 256bit enc
rank   self  accum   count trace method
  40  0.49% 46.80%    3072 309746 com.sun.crypto.provider.SunJCE_c.a
  85  0.21% 60.39%       1 309747 com.sun.crypto.provider.SunJCE_c.<clinit>
 236  0.07% 75.60%       1 307666 javax.crypto.SunJCE_b.j
 248  0.07% 76.45%       1 309329 javax.crypto.SunJCE_c.b
 253  0.07% 76.80%       1 309726 com.sun.crypto.provider.SunJCE_b.a
 424  0.05% 84.81%       1 309750 com.sun.crypto.provider.AESKeyGenerator.engineInit
 425  0.05% 84.86%       1 309877 com.sun.crypto.provider.AESCipher.<init>
 929  0.02% 96.67%       1 306911 com.sun.crypto.provider.SunJCE.<init>
1009  0.02% 98.55%       2 308876 javax.crypto.SunJCE_k.newPermissionCollection
1010  0.02% 98.57%       2 308887 javax.crypto.SunJCE_d.a
1013  0.02% 98.64%       1 308929 javax.crypto.SunJCE_d.a
1014  0.02% 98.66%       1 308932 javax.crypto.SunJCE_b$1.run
1037  0.02% 99.20%       1 309431 javax.crypto.Cipher.getInstance
1063  0.02% 99.81%       1 309731 com.sun.crypto.provider.AESKeyGenerator.<init>
1065  0.02% 99.86%       1 309936 com.sun.crypto.provider.SunJCE_k.a
hpprof例 AES 256bit enc&dec
rank   self  accum   count trace method
  36  0.46% 44.87%    3072 309756 com.sun.crypto.provider.SunJCE_c.a
  77  0.23% 57.76%       1 309757 com.sun.crypto.provider.SunJCE_c.<clinit>
  94  0.19% 61.12%       1 309736 com.sun.crypto.provider.SunJCE_b.a
 103  0.16% 62.58%       1 309329 javax.crypto.SunJCE_c.b
 428  0.05% 84.17%       1 309739 com.sun.crypto.provider.SunJCE.c
 429  0.05% 84.22%       1 309760 com.sun.crypto.provider.AESKeyGenerator.engineInit
 430  0.05% 84.26%       1 309887 com.sun.crypto.provider.AESCipher.<init>
 956  0.02% 96.44%       1 306911 com.sun.crypto.provider.SunJCE.<init>
1037  0.02% 98.31%       2 308839 javax.crypto.SunJCE_e.b
1038  0.02% 98.33%       2 308844 javax.crypto.SunJCE_e.a
1039  0.02% 98.36%       2 308851 javax.crypto.SunJCE_e.a
1042  0.02% 98.43%       2 308923 javax.crypto.SunJCE_b.a
1043  0.02% 98.45%       1 308932 javax.crypto.SunJCE_b$1.run
1047  0.02% 98.54%       1 309101 javax.crypto.SunJCE_c$1.run
1075  0.02% 99.19%     108 309246 javax.crypto.SunJCE_c.a
1079  0.02% 99.28%       2 309411 javax.crypto.Cipher$r.a
1098  0.02% 99.72%     108 309723 com.sun.crypto.provider.SunJCE_b.a
1099  0.02% 99.75%      95 309755 com.sun.crypto.provider.SunJCE_c.a
1100  0.02% 99.77%       1 309926 com.sun.crypto.provider.SunJCE_f.a
1102  0.02% 99.81%       2 310006 com.sun.crypto.provider.AESParameters.<init>
1103  0.02% 99.84%       1 310056 com.sun.crypto.provider.SunJCE_k.a
hpprof例 Blowfish 448bit enc
rank   self  accum   count trace method
  40  0.44% 45.98%     521 309917 com.sun.crypto.provider.SunJCE_u.a
  70  0.26% 55.88%    8336 309916 com.sun.crypto.provider.SunJCE_u.a
 241  0.07% 74.93%       1 307666 javax.crypto.SunJCE_b.j
 255  0.07% 75.91%       1 309871 com.sun.crypto.provider.BlowfishCipher.<init>
 421  0.05% 83.63%       1 309728 com.sun.crypto.provider.SunJCE_b.a
 961  0.02% 96.19%       1 306911 com.sun.crypto.provider.SunJCE.<init>
1030  0.02% 97.79%       2 308449 javax.crypto.SunJCE_e.b
1031  0.02% 97.81%       2 308454 javax.crypto.SunJCE_e.a
1033  0.02% 97.86%       2 308502 javax.crypto.SunJCE_d.a
1080  0.02% 98.95%     108 309246 javax.crypto.SunJCE_c.a
1088  0.02% 99.14%       1 309414 javax.crypto.Cipher$r.a
1089  0.02% 99.16%       1 309433 javax.crypto.Cipher.getInstance
1116  0.02% 99.79%       1 309731 com.sun.crypto.provider.SunJCE.c
1120  0.02% 99.88%       1 309918 com.sun.crypto.provider.SunJCE_u.a
hpprof例 Blowfish 448bit enc&dec
rank   self  accum   count trace method
  19  0.77% 34.45%    1042 309927 com.sun.crypto.provider.SunJCE_u.a
  29  0.58% 40.76%   16672 309926 com.sun.crypto.provider.SunJCE_u.a
 183  0.09% 71.41%       1 309329 javax.crypto.SunJCE_c.b
 184  0.09% 71.50%       1 309738 com.sun.crypto.provider.SunJCE_b.a
 423  0.05% 84.03%     108 309725 com.sun.crypto.provider.SunJCE_b.a
 424  0.05% 84.07%       1 309881 com.sun.crypto.provider.BlowfishCipher.<init>
 425  0.05% 84.12%       2 309928 com.sun.crypto.provider.SunJCE_u.a
 475  0.02% 85.28%       1 301015 javax.crypto.Cipher.b
 950  0.02% 96.29%       1 306911 com.sun.crypto.provider.SunJCE.<init>
1029  0.02% 98.12%       2 308461 javax.crypto.SunJCE_e.a
1030  0.02% 98.15%       2 308491 javax.crypto.SunJCE_k.newPermissionCollection
1044  0.02% 98.47%       1 308925 javax.crypto.SunJCE_b.i
1045  0.02% 98.49%       1 308927 javax.crypto.SunJCE_b$1.run
1048  0.02% 98.56%       1 309045 javax.crypto.SunJCE_c.<init>
1102  0.02% 99.81%       1 309741 com.sun.crypto.provider.SunJCE.c
1103  0.02% 99.84%       1 309743 com.sun.crypto.provider.BlowfishKeyGenerator.<init>
1106  0.02% 99.91%       2 309951 com.sun.crypto.provider.SunJCE_f.b
You can leave a comment, or trackback from your own site. RSS 2.0

Leave a comment