材料
材料の入手
ソース・コードを入手しないと話になりませんので、誰かにもらうかお買い物に行きましょう。
でも、 DES ライブラリは輸出規制の対象品目のようなので、国内のサイトから見つけるようにしてください。
ftp site で ftp://ftp.meiji.ac.jp/pub/security/Crypto/DES/ から libdes-4.04b.tar.gz を持ってきました。
下拵え
まず材料を解凍します。
./configure という優れものを利用して Makefile を作成します。
この時、 ./configure のオプションはいっぱいありますが、基本的にデフォルトでお料理をしましょう。
パスは[ /usr/bin /usr/sbin /usr/ccs /usr/ccs/bin /usr/openwin/bin /usr/openwin/bin/xview /usr/local/bin . ]で、 LD_LIBRARY_PATH は[ /usr/openwin/lib /usr/local/lib ]に張ってあります。
# cd /usr/local/compile
# gzip -dc libdes-4.04b.tar.gz | tar xvf -
# cd des
さてコンパイル
INSTALL に書かれている手順でコンパイルしましょう。
gcc で make するなら make gcc ね。
# make gcc
INSTALL に書かれている手順でチェックしてパフォーマンスをしらべましょ。
# ./destest
Doing ecb
Doing ede ecb
Doing cbc
Doing desx cbc
Doing ede cbc
Doing pcbc
Doing cfb8 cfb16 cfb32 cfb48 cfb64 cfb64() ede_cfb64() done
Doing ofb
Doing ofb64
Doing ede_ofb64
Doing cbc_cksum
Doing quad_cksum
input word alignment test 0 1 2 3
output word alignment test 0 1 2 3
fast crypt test
# ./rpw
read passwd
Enter password:
password = ce 20 6b c8 2a 04 16 b3
read 2passwds and verify
Enter verified password:
Verifying password - Enter verified password:
password1 = ce 20 6b c8 2a 04 16 b3
password2 = ce 20 6b c8 2a 04 16 b3
# ./speed
Doing set_key for 10 seconds
1068056 set_key's in 10.00 seconds
Doing des_encrypt's for 10 seconds
2591758 des_encrypt's in 9.93 second
Doing des_cbc_encrypt on 1024 byte blocks for 10 seconds
19029 des_cbc_encrypt's of 1024 byte blocks in 10.00 second
Doing des_ede_cbc_encrypt on 1024 byte blocks for 10 seconds
7180 des_ede_cbc_encrypt's of 1024 byte blocks in 10.00 second
Doing crypt for 10 seconds
82397 crypts in 9.99 second
set_key per sec = 106805.60 ( 9.363uS)
DES raw ecb bytes per sec = 2088022.56 ( 3.831uS)
DES cbc bytes per sec = 1948569.60 ( 4.106uS)
DES ede cbc bytes per sec = 735232.00 ( 10.881uS)
crypt per sec = 8247.95 ( 121.242uS)
# ./des_opts
Doing des_encrypt_u4_cisc_idx 's for 10 seconds
1986489 des_encrypt_u4_cisc_idx 's in 10.00 second
Doing des_encrypt_u16_cisc_idx 's for 10 seconds
1838815 des_encrypt_u16_cisc_idx 's in 9.93 second
Doing des_encrypt_u4_risc1_idx 's for 10 seconds
1916602 des_encrypt_u4_risc1_idx 's in 9.98 second
Doing des_encrypt_u16_risc1_idx's for 10 seconds
1882804 des_encrypt_u16_risc1_idx's in 10.00 second
Doing des_encrypt_u4_risc2_idx 's for 10 seconds
2108161 des_encrypt_u4_risc2_idx 's in 10.00 second
Doing des_encrypt_u16_risc2_idx's for 10 seconds
1960220 des_encrypt_u16_risc2_idx's in 9.97 second
Doing des_encrypt_u4_cisc_ptr 's for 10 seconds
1980897 des_encrypt_u4_cisc_ptr 's in 9.96 second
Doing des_encrypt_u16_cisc_ptr 's for 10 seconds
1833925 des_encrypt_u16_cisc_ptr 's in 9.94 second
Doing des_encrypt_u4_risc1_ptr 's for 10 seconds
2338450 des_encrypt_u4_risc1_ptr 's in 10.00 second
Doing des_encrypt_u16_risc1_ptr's for 10 seconds
2222957 des_encrypt_u16_risc1_ptr's in 9.99 second
Doing des_encrypt_u4_risc2_ptr 's for 10 seconds
2367065 des_encrypt_u4_risc2_ptr 's in 10.00 second
Doing des_encrypt_u16_risc2_ptr's for 10 seconds
2168135 des_encrypt_u16_risc2_ptr's in 10.00 second
des_encrypt_u4_cisc_idx bytes per sec = 1589191.20 ( 5.0uS)
des_encrypt_u16_cisc_idx bytes per sec = 1481421.95 ( 5.4uS)
des_encrypt_u4_risc1_idx bytes per sec = 1536354.31 ( 5.2uS)
des_encrypt_u16_risc1_idx bytes per sec = 1506243.20 ( 5.3uS)
des_encrypt_u4_risc2_idx bytes per sec = 1686528.80 ( 4.7uS)
des_encrypt_u16_risc2_idx bytes per sec = 1572894.68 ( 5.1uS)
des_encrypt_u4_cisc_ptr bytes per sec = 1591081.93 ( 5.0uS)
des_encrypt_u16_cisc_ptr bytes per sec = 1475995.98 ( 5.4uS)
des_encrypt_u4_risc1_ptr bytes per sec = 1870760.00 ( 4.3uS)
des_encrypt_u16_risc1_ptr bytes per sec = 1780145.75 ( 4.5uS)
des_encrypt_u4_risc2_ptr bytes per sec = 1893652.00 ( 4.2uS)
des_encrypt_u16_risc2_ptr bytes per sec = 1734508.00 ( 4.6uS)
options des ecb/s
4 r2 p 236706.50 100.0%
4 r1 p 233845.00 98.8%
16 r1 p 222518.22 94.0%
16 r2 p 216813.50 91.6%
4 r2 i 210816.10 89.1%
4 c p 198885.24 84.0%
4 c i 198648.90 83.9%
16 r2 i 196611.84 83.1%
4 r1 i 192044.29 81.1%
16 r1 i 188280.40 79.5%
16 c i 185177.74 78.2%
16 c p 184499.50 77.9%
-DDES_RISC2 -DDES_PTR
なんか -DDES_RISC2 -DDES_PTR のオプションを付けた方がいいよ ... と言ってますので、 Makefile を編集してそのオプションを使用してコンパイルしなおしますかね ? 無理矢理しなくてもいいのかも。
64bit computer は -DDES_PTR をしちゃいけないってさ。 Solaris7 ってどうなるんでしょうね。
# vi Makefile
#OPTS2= -DDES_PTR
#OPTS3= -DDES_RISC1 # or DES_RISC2
↓
OPTS2= -DDES_PTR
OPTS3= -DES_RISC2
# make gcc
さぁ、盛り付け
Makefile に install オプションがあるのでこれで盛り付けてしまいましょう。 デフォルトだと /usr/local/bin, /usr/local/lib, /usr/local/include, /usr/local/man にインストールされます。
変更したい時は、 Makefile 内の LIBDIR, BINDIR, INCDIR, MANDIR にパスを変更しましょ。
# make install
後片付け
ソース・コードなどはバックアップしておいて作業した生ごみは必要がなければ消してしまいましょう。
# cd /usr/local/compile
# rm -r libdes-4.04b.tar.gz des