2014年4月25日金曜日

OpenSSLでのAES-NI性能チェック

OpenSSLでのAES-NI性能チェック

①対応CPUを確認
インテルCPUの場合CPU情報が検索できる ⇒ http://ark.intel.com/
ざっとみた感じだと 第2、第3世代のCore i5, Core i7, Xeonは第2世代から、Core i3は第4世代から対応してる

②OpenSSLでコマンド実行
AES-NI無効
> openssl speed aes-256-cbc
Doing aes-256 cbc for 3s on16 size blocks14818341 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on64 size blocks4047956 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on256 size blocks1036641 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on1024 size blocks258249 aes-256 cbc's in 2.98s
Doing aes-256 cbc for 3s on8192 size blocks32677 aes-256 cbc's in 3.01s
The 'numbers' are in 1000s of bytes per second processed.
BlockSizeKBytes/sec
16 bytes79157.30k
64 bytes86494.23k
256 bytes88601.23k
1024 bytes88751.94k
8192 bytes88909.35k

AES-NI有効
> openssl speed -evp aes-256-cbc
Doing aes-256 cbc for 3s on16 size blocks74060182 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on64 size blocks22091013 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on256 size blocks5640111 aes-256 cbc's in 3.00s
Doing aes-256 cbc for 3s on1024 size blocks1393281 aes-256 cbc's in 2.98s
Doing aes-256 cbc for 3s on8192 size blocks175337 aes-256 cbc's in 3.01s
The 'numbers' are in 1000s of bytes per second processed.
BlockSizeKBytes/sec
16 bytes395618.09k
64 bytes472027.17k
256 bytes487131.97k
1024 bytes473864.29k
8192 bytes479551.11k

だいたい5倍強の性能になってる

2014年1月23日木曜日

OpenSSL VC2005用のビルド

1.事前準備
 必要なもの
 ①OpenSSL source
 ②ActivePerl
 ③nasm.exe

OpenSSLのsourceを入手
 OpenSSLのサイト(http://www.openssl.org/)からソースコードをDownloadする
 0.9.8 / 1.0.0 / 1.0.1系があるが、今回はとりあえず1.0.1をDL
 >openssl-1.0.1l.tar.gz (2015/03/06 確認)

AcitivePerlをインストール
 http://www.activestate.com/ から windows版インストーラーをDLし、
 ActivePerlをインストール
 (64bitWinは64bit版のみインストールでよい)

nasm.exeを入手
 http://www.nasm.us/ から ZIPファイルを Download
  > nasm-2.11-win32.zip
  Windows用インストーラーもあるが、バイナリファイルが必要なだけなので
 インストーラーを使用する必要はない
 展開後は環境変数でパスを指定しておく

2.OpenSSLのビルド

32bit/64bitビルドは別々に行う

 ①VC2005コマンドプロンプトを管理者権限で起動 (32bitビルドは32bitのコマンドプロンプト64bitは64bitのコマンドプロンプト
 ②opensslを展開したフォルダーへ移動する
    > X:
    > cd X:\openssl\openssl-1.0.1l

 INSTALL.W32 / INSTALL.W64 にそれぞれビルド方法が記載されているので指示に従う
 ③環境指定
    > perl Configure VC-WIN32 --prefix=X:\openssl\openssl-1.0.1l.vc2005\win32

 ④makeファイルの生成
    > ms\do_nasm
 
 ⑤make実施
ダイナミックリンク用とスタティックリンク用でmakeファイルが異なる
nt.mak(スタティックリンク) ntdll.mak(ダイナミックリンク)
   > nmake -f ms\ntdll.mak
    > nmake -f ms\nt.mak

 ⑥テスト
    > cd out32
    > ..\ms\test
    > cd ..\

 ⑦インストール
    > nmake -f ms\nt.mak install
    ③で指定したフォルダーにOpenSSLパッケージがコピーされる


 ⑧一部Windows用のソースファイルが includeフォルダーにないので
  必要に応じてコピーする
   > cd ms
   > cp applink.c "X:\openssl\openssl-1.0.1l.vc2005\win32\include\openssl\"
   > cp tlhelp32.h "X:\openssl\openssl-1.0.1l.vc2005\win32\include\openssl\"
   > cp uplink.h "X:\openssl\openssl-1.0.1l.vc2005\win32\include\openssl\"
   > cp uplink.c "X:\openssl\openssl-1.0.1l.vc2005\win32\include\openssl\"

 ⑨.pdbファイルもコピー
   > cd ..\tmp32
   > cp lib.pdb "X:\openssl\openssl-1.0.1l.vc2005\win32\lib\"

 ⑩ビルド後には tmp32とout32を削除すれば次回リビルドできる
  64bitのnt.makもtmp32/out32を使うので、32bitビルド後に64bitビルドする場合は削除必須

  64bitビルドは③以降のコマンドを下記に変更して行う
  > perl Configure VC-WIN64A --prefix=X:\openssl\openssl-1.0.1l.vc2005\win64
  > ms\do_win64a
  > nmake -f ms\nt.mak
  > cd out32
  > ..\ms\test
  > cd ..\
  > nmake -f ms\nt.mak install


2014年1月22日水曜日

OpenSSLによるRoot証明書作成

1. 秘密鍵の生成
 openssl genrsa 2048 > certkey.pem

2. 証明書要求の作成
 openssl req -new -key certkey.pem > certreq.pem

 configファイルを使用する場合は下記
 openssl req -new -config tmp.cfg -key certkey.pem > certreq.pem

3. 同一の秘密鍵で証明書要求に署名する
 openssl x509 -req -days 366 -signkey certkey.pem < certreq.pem > cert.crt

 configファイルを使用する場合は下記
 openssl req -new -extfile tmp.cfg -extentions v3_ca -key certkey.pem > certreq.pem