Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions siphash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class SipHash_2_4(object):
>>> SipHash_2_4(b'FEDCBA9876543210').update(b'').update(b'a').hash()
6581475155582014123

>> SipHash_2_4.fromkeyparts(506097522914230528, 1084818905618843912).hash()
8246050544436514353
>> SipHash_2_4.fromkeyparts(506097522914230528, 1084818905618843912, b'a').hash()
3144613055062689994

>>> a = SipHash_2_4(b'FEDCBA9876543210').update(b'a')
>>> a.hash()
6581475155582014123
Expand All @@ -133,6 +138,17 @@ def __init__(self, secret, s=b''):
0x7465646279746573 ^ k1)
self.update(s)

@classmethod
def fromkeyparts(cls, k0, k1, s=b''):
"""
Create a SipHash instance using two 64-bit integers as first (k0)
and second (k1) parts of the resultant 128-bit key.

>> SipHash_2_4.fromkeyparts(506097522914230528, 1084818905618843912).hash()
8246050544436514353
"""
return cls(_twoQ.pack(k0, k1), s=s)

def update(self, s):
s = self.s + s
lim = (len(s)//8)*8
Expand Down