以下のように
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