勝手にSNOW2.0を実装

http://d.hatena.ne.jp/studiokingyo/20041216#p1
より、SNOW 2.0を勝手に実装します。
その過程をチマチマとレポートでも^^;

  • まずは論文を大まかに読み倒す。*1
  • やっぱり、読んでも分からないので、チマチマとソースを読みこむ。
  • とりあえず、ライセンスの情報を検索してみる http://www.secureprogramming.com/?action=view&feature=links&linkid=134 なんか、フリーらしいが・・・ SNOW2.0はどうなの?
  • ソースを読みこんでいくうちにgoogle:sliding window というテクニックを知った。後で、詳しい理屈を確かめてみる。*2
  • ちょっと、実装していて思ったのだが、私がconvertした暗号プログラムの実装はほとんどEndianの考慮をしていない。「むぅ」だなぁ。しっかりエンディアン考慮もしなくては・・・
  • まぁ、エンディアン系は後でイイか〜 と言うことで実装完了。テストに移るココまでで、約3時間ほど。 この速度は遅いような気もするが・・・
  • テスト終了:switchのbreak抜けとか bit shake部分とかを間違えてた。でも、とりあえず、originalと同じ出力になったのでOKって事で?
  • HC256暗号とSNOW2.0暗号の自己満足をhttp://www33.tok2.com/home/dca/dkutil.htmlにアップロード。


例によって速度テスト
snow2.0 speed test / loop count = 524288 / one process = 64

ranking_tiemr / clock type : RealCPUClock / compile mode : DEBUG
1 / fast impl 256bit / 406220401.000000
2 / fast impl 128bit / 427057497.000000
3 / reference impl 256bit / 2166007616.000000
4 / reference impl 128bit / 2319600222.000000
5 / my impl 256bit / 2619101485.000000
6 / my impl 128bit / 2903814740.000000

ranking_tiemr / clock type : RealCPUClock / compile mode : RELEASE
1 / fast impl 256bit / 213927416.000000
2 / fast impl 128bit / 214124951.000000
3 / reference impl 128bit / 528714749.000000
4 / reference impl 256bit / 538825677.000000
5 / my impl 128bit / 630663432.000000
6 / my impl 256bit / 633829771.000000

泣きたくなりますな (´Д⊂グスン

初期化部のみが思いのかとテスト

ranking_tiemr / clock type : RealCPUClock / compile mode : RELEASE
1 / fast impl 256bit crypt speed / 207184859.000000
2 / fast impl 128bit / 223002223.000000
3 / fast impl 256bit / 233845334.000000
4 / reference impl 256bit / 490756923.000000
5 / reference impl 128bit / 501984354.000000
6 / reference impl 256bit crypt speed / 526352657.000000
7 / my impl 256bit / 626720797.000000
8 / my impl 256bit crypt speed / 630186067.000000
9 / my impl 128bit / 698409627.000000

。゜(゜´Д`゜)゜。
C言語でのオブジェクト指向的実装の場合、やっぱり限界があるわ・・・

CPUクロック(RDTSC)で計っていたのでmilli second clock ( timeGetTime() )に変えてみる。

ranking_tiemr / clock type : MilliSecondClock / compile mode : RELEASE
1 / fast impl 256bit crypt speed / 109.000000
2 / fast impl 256bit / 110.000000
3 / fast impl 128bit / 125.000000
4 / reference impl 128bit / 265.000000
5 / reference impl 256bit / 281.000000
6 / reference impl 256bit crypt speed / 297.000000
7 / my impl 256bit crypt speed / 344.000000
8 / my impl 128bit / 344.000000
9 / my impl 256bit / 375.000000

三倍も違うのか・・・ヽ(`Д´)ノウワァン
仕方ない・・・fast implのアルゴリズムをそのままパクっteオマージュして

snow2.0 speed test / loop count = 524288 / one process = 64

ranking_tiemr / clock type : MilliSecondClock / compile mode : RELEASE
1 / fast impl 128bit / 94.000000
2 / my impl 256bit 512bit step / 94.000000
ranking_tiemr / clock type : RealCPUClock / compile mode : RELEASE
1 / my impl 256bit 512bit step / 179576123.000000
2 / fast impl 256bit / 183024976.000000

と言う事で
どうか、許してください m(_ _)mこの通り

*1:http://www.it.lth.se/cryptology/snow/snow20.pdf

*2:http://bruch.sfc.keio.ac.jp/Ilp/DM_DB/node27.htmlhttp://www.ipa.go.jp/security/enc/CRYPTREC/fy15/documents/57rep.pdfがでてきたが・・・どうも、そのテクニックと合っているような気がしない。暗号大全やセキュア本( http://d.hatena.ne.jp/studiokingyo/20041219#p2 )でも買わんとダメか?  追記:http://d.hatena.ne.jp/studiokingyo/20041011#p1で使うテクニックだったことを思い出した。