RC4-based password hashing function
UNLICENSE License
The goal of RC4HASH is to specify and implement the simplest possible, reasonably secure password hashing function. Being based on RC4, it's small and simple enough that it can be implemented entirely from memory. The C implementation is 115 lines of code and uses no external libraries.
RC4HASH is a 208-bit hash, containing a 32-bit salt and an 8-bit variable difficulty setting. On a modern computer, this difficulty scales between a few microseconds per hash (0) all the way to the heat death of the universe (255).
foobar 0a628b131266d08803c72feca08918ea1cee3d1c3711b78974dd
testpass 3aea29920099e47a1acb45978ec97bf0a5b0375eb0f667e2bbe1
naïve b74f02b80a762a0763b3df0099e3f1575699a35dff138b05d314
long ef73a67418f736f2f82c32c397380d42bd7d3925339817da9851
blank 0000000000a7e8ed1ca21214219626a234c3db4299b22bea54be
Each of these should validate on any implementation. The last is a special case where the salt and difficulty are 0.
RC4 follows the specification as listed in the RC4 Wikipedia article. There are three specific algorithms, the second one (KSA) being run multiple times. Unlike KSA, the counters in PRGA are never reset.
for i from 0 to 255
S[i] := i
endfor
j := 0
for i from 0 to 255
j := (j + S[i] + key[i mod keylength]) mod 256
swap values of S[i] and S[j]
endfor
i := 0
j := 0
while GeneratingOutput:
i := (i + 1) mod 256
j := (j + S[i]) mod 256
swap values of S[i] and S[j]
K := S[(S[i] + S[j]) mod 256]
output K
endwhile
1 << difficulty
((1 << difficulty) - 1) * 64
bytes of