Algorithm complexity attack

zhaozj2021-02-08  484

Hashing

We often use such strings of Hash functions:

// Written, unsightly test unsigned long hash (char * str) {assert (null! = Str); unsigned long Hash_val = 0xdeedbeeful; // Hash seed unsigned char * p = (unsigned char *) str; while * p! = '/ 0') {hash_val = 37 * hash_val * p; p;} return.com

The implementation of Markov Chain in Chapter 3 of Program Design Practice uses almost a Hash function. The advantage of this function is that the speed is fast, and the distribution of the HASH value of the English word is also good. However, it is too simple and is easy to attack. Attacks typically have two options: 1) Constructing an input sequence, making each of the character strings in the sequence, but the HASH value is the same; 2) Constructing an input sequence, each character string is different from each other in the sequence, the HASH value is not It must be the same, but these haveh values ​​are the number of buckets used by Hash Table (ie, Hash_Val% bucket_size equivalent). This will allow Hash Table to degenerate into a list. Thereby greatly increase the lookup time. (http://www.cs.rice.edu/~scrosby/hash/)

To solve this problem, you need to use complex Hash functions (MD5, SHA-1) to allow the attacker (almost) unable to construct the same sequence of the HASH value.

2. Regular Expressions

Regular Expression Engine generally has three: DFA (Deterministic Finite Automaton), Traditional NFA (Nondeterministic Finite Automaton), POSIX NFA. These three ENGINES features a stronger than a speed, a speed than a slower. (http://msdn.microsoft.com/library/en-us/cpguide/html/cpconmatchingbehavior.asp) (http://www.oreilly.com/catalog/regex/chapter/ch04.html)

The DFA speed is the fastest and can guarantee linearity (?). NFA requires BACKTRACKING technology to support Backreference, usually NFA is linear time, but its worst case is an index time!

For example, expression (x x ) y can match XXX ... XXXY but cannot match XXX ... XXXX. In some versions of Python, this expression is the index time. (http://mail.python.org/pipermail/python-dev/2003-may/035916.html)

3. Quicksort

转载请注明原文地址:https://www.9cbs.com/read-107.html

New Post(0)