hack のためのネタ帳, etc,,,

rounds パラメーターと総当たり攻撃耐性

Unix crypt with DES や MD5 にはなかった機能として rounds パラメータが新設されている。
Unix crypt with MD5 ではダイジェストの反復計算が 1000 回(?)固定だったのが、Unix crypt with SHA-256/512 では、この rounds パラメータを変更することで反復回数を 1000〜999,999,999 回まで変更出来る仕様になっているようだ。
デフォルトは rounds=5000。
将来的に、コンピュータの演算能力が上がった場合にも rounds パラメータを変更することで、総当たり攻撃への耐性を高める事が可能と言うことらしい。
実際 rounds=999999999 とするとダイジェスト1つ計算するだけなのに実用にならないくらい時間がかかる。

速度比較

以下のように crypt(3) を使って DES, MD5, SHA256, SHA512 の速度比較してみた。

環境:
  • CPU: Core 2 Quad Q6600
  • OS: Ubuntu 12.04.1 64 bit 版

unixcrypttest.c
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  if (argc != 3) {
    printf("Usage: crypttest key salt\n");
    return EXIT_FAILURE;
  }
  char *s;
  for (int i = 0; i < 10000; i++) {
    s = crypt(argv[1], argv[2]);
  }
  printf("%s\n", s);
  return EXIT_SUCCESS;
}
$ gcc -std=c99 unixcrypttest.c -lcrypt && time ./a.out a 'aa'
aafKPWZb/dLAs

real	0m0.077s
user	0m0.068s
sys	0m0.004s

$ gcc -std=c99 unixcrypttest.c -lcrypt && time ./a.out a '$1$'
$1$$Ij31LCAysPM23KuPlm1wA/

real	0m2.615s
user	0m2.604s
sys	0m0.004s

$ gcc -std=c99 unixcrypttest.c -lcrypt && time ./a.out a '$5$'
$5$$QG6CCM7eJAxpUPcBpn0Z2K29NHtaI6Mk1fCpPrpjdj3

real	0m35.769s
user	0m35.746s
sys	0m0.016s

$ gcc -std=c99 unixcrypttest.c -lcrypt && time ./a.out a '$6$'
$6$$ek/ucQg0IM8SQLyD2D66mpoW0vAF26eA0/pqoN95V.F0nZh1IFuENNo0OikacRkDBk5frNqziMYMdVVrQ0o.51

real	0m44.595s
user	0m44.595s
sys	0m0.000s

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます