mirror of
https://github.com/OALabs/hashdb
synced 2026-06-08 12:05:11 +00:00
Added ror8_add_xor variant
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
DESCRIPTION = "Hash based on ror8, add, xor with initial state 0x832E83AB"
|
||||
# Type can be either 'unsigned_int' (32bit) or 'unsigned_long' (64bit)
|
||||
TYPE = 'unsigned_int'
|
||||
# Test must match the exact has of the string 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||
TEST_1 = 0x828E7DBD
|
||||
|
||||
|
||||
ROTATE_BITMASK = {
|
||||
8: 0xff,
|
||||
16: 0xffff,
|
||||
32: 0xffffffff,
|
||||
64: 0xffffffffffffffff,
|
||||
}
|
||||
|
||||
def ror(inVal, numShifts, dataSize=32):
|
||||
'''rotate right instruction emulation'''
|
||||
if numShifts == 0:
|
||||
return inVal
|
||||
if (numShifts < 0) or (numShifts > dataSize):
|
||||
raise ValueError('Bad numShifts')
|
||||
if (dataSize != 8) and (dataSize != 16) and (dataSize != 32) and (dataSize != 64):
|
||||
raise ValueError('Bad dataSize')
|
||||
bitMask = ROTATE_BITMASK[dataSize]
|
||||
return bitMask & ((inVal >> numShifts) | (inVal << (dataSize-numShifts)))
|
||||
|
||||
def hash(data):
|
||||
state = 0x832E83AB
|
||||
for i in range(len(data)):
|
||||
val = ror(state, 8)
|
||||
if i < len(data) - 1:
|
||||
val += data[i] | data[i + 1] << 8
|
||||
else:
|
||||
val += data[i]
|
||||
state ^= val
|
||||
return state
|
||||
|
||||
Reference in New Issue
Block a user