问题描述
例如,仅使用7个字母的US-ASCII字母字符,我们就会知道,知道可以使用26个可能的序列。知道计算机每分钟可以产生多少这些数据,可以让我了解产生所有可能的哈希以及破解某个7个字符的哈希(生日攻击除了)需要多长时间。例如,考虑到上面的数字,如果现代四核可以每分钟产生100万次散列,则需要 8031810176/1000000/60 = 133.86
小时,以找到该范围内的所有可能的散列。
我使用OpenSSL SHA256实现在C中编写了这个测试。
#include< stdio.h>
#include< string.h>
#includeopenssl / sha.h
// http://stackoverflow.com/questions/4764608/generate-all-strings-under-length-n-in-c / 4764686#4764686
int(char * str){
if(!str [0])return 0;
if(str [0] =='z'){
str [0] ='a';
return inc(str + sizeof(char));
}
str [0] ++;
返回1;
}
unsigned char buffer [65];
char * hashstring(char * str,int len){$ b $ char char [SHA256_DIGEST_LENGTH]; // openssl hash
SHA256_CTX sha256;
int i; // counter
SHA256_Init(& sha256);
SHA256_Update(& sha256,str,len);
SHA256_Final(hash,& sha256); (i = 0; i< SHA256_DIGEST_LENGTH; i ++){
sprintf(buffer +(i * 2),%02x,hash [i])的
; //将openssl hash转换为凡人字符串
}
return buffer;
int main(int argc,char * argv []){
int N = 4; //最大长度字符串
char str [N + 1]; //字符串持有者
int i; // counter
unsigned int tot = 0; //计算
的散列数(i = 0; i str [N] = 0;
do {
hashstring(str,N);
tot ++;
} while(inc(str));
printf(%d\\\
,tot);
编译:
gcc -lcrypto -O3 -o test test.c
结果(我知道,我对计算机游戏不是很有创意):
nightcracker @ nightcracker-pc:〜/ c / sha256 $ time ./test
11881376
real 3m2.431s
user 3m2.335s
sys 0m0.008s
因此,这是 11881376 / 182.4 = 65139
每秒散列值。然后它是 26 ^ 7/101821/3600 = 34
小时来计算所有哈希值。请注意,所有这些都是在单线程应用程序中的Q6600四核CPU上完成的,并且不包括将哈希写入文件。
编辑
Woops,我计算了所有N个字符和以下字符串的哈希值。更正并更新数据。
I want to know the mathematical time required for cracking hashes based off different sets of characters.
For example, using only 7 letter, US-ASCII alphabetic characters we know that there are 26 possible sequences that could be used. Knowing how many of these could be generated by a computer each minute would give me an idea of how long it would take to generate all possible hashes and crack a certain 7 character hash (birthday attacks aside).
For example, taking the number above, if a modern quad core could generate 1 million hashes each minute it would take 8031810176 / 1000000 / 60 = 133.86
hours to find all possible hashes in that range.
Also, how does the new Sandy Bridge Intel chips with native AES play into this?
I wrote this test in C using the OpenSSL SHA256 implementation.
#include <stdio.h>
#include <string.h>
#include "openssl/sha.h"
// http://stackoverflow.com/questions/4764608/generate-all-strings-under-length-n-in-c/4764686#4764686
int inc(char *str) {
if (!str[0]) return 0;
if (str[0] == 'z') {
str[0] = 'a';
return inc(str + sizeof(char));
}
str[0]++;
return 1;
}
unsigned char buffer[65];
char* hashstring(char *str, int len) {
char hash[SHA256_DIGEST_LENGTH]; // the openssl hash
SHA256_CTX sha256;
int i; // counter
SHA256_Init(&sha256);
SHA256_Update(&sha256, str, len);
SHA256_Final(hash, &sha256);
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
sprintf(buffer + (i * 2), "%02x", hash[i]); // convert openssl hash to mortal human string
}
return buffer;
}
int main(int argc, char *argv[]) {
int N = 4; // max length string
char str[N+1]; // the string holder
int i; // counter
unsigned int tot = 0; // number of hashes calculated
for (i = 0; i < N; i++) str[i] = 'a';
str[N] = 0;
do {
hashstring(str, N);
tot++;
} while(inc(str));
printf("%d\n", tot);
}
Compile:
gcc -lcrypto -O3 -o test test.c
And results (I know, I'm not very creative with computernames):
nightcracker@nightcracker-pc:~/c/sha256$ time ./test
11881376
real 3m2.431s
user 3m2.335s
sys 0m0.008s
So that's 11881376 / 182.4 = 65139
hashes per second. Then it's 26^7/101821/3600 = 34
hours to compute all the hashes. Please note, all of this was done on a Q6600 quad-core CPU in a single-threaded application and excluded writing the hashes to file.
EDIT
Woops, I was calculating all the hashes of strings with N characters and below. Corrected and data updated.
这篇关于现代计算机可以计算多少个SHA256哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!