Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

SipHash family of pseudo random functions implemented in Crystal

License

NotificationsYou must be signed in to change notification settings

ysbaddaden/siphash.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crystal implementation of SipHash and HalfSipHash, a family of pseudorandomfunctions optimized for short inputs.

Seehttps://131002.net/siphash/ for more information on the algorithms.

SipHash

You may choose how many compression-rounds and finalization-rounds to execute.Be wary about your use cases;SipHash(2, 4) has been verified to becryptographically secure for example, whereasSipHash(1, 3) is faster but notverified, and should only be used when the result is never disclosed (e.g. fortable hashing).

require"secure_random"require"siphash"key= uninitializedSipHash::KeySecureRandom.random_bytes(key.to_slice)# generate a 64-bit hash:hash=SipHash(2,4).siphash("some data", key)# => UInt64# generate a 128-bit hash:hash=Bytes.new(16)SipHash(2,4).siphash("some data", hash, key)

You may alternatively hash a streaming input as you read it. This implies aslight performance hit, and may only generate 64-bit hashes. This is stilluseful when you don't know the complete input beforehand, or the input isscaterred from different places.

require"secure_random"require"siphash/siphash64"key= uninitializedSipHash64::KeySecureRandom.random_bytes(key.to_slice)hasher=SipHash64(2,4).new(key)hasher.update("some data")hash= hasher.final# => UInt64

HalfSipHash

An alternativeSipHash pseudorandom function that uses a 64-bit key andgenerates 32-bit or 64-bit hashes, meant for 32-bit platforms. On 64-bitplatform we advise to useSipHash instead.

WhileSipHash(2, 4) has been analyzed and verified to be cryptographicallysecure,HalfSipHash has not, and isn't expected to be. Results from thehasher should never be disclosed (e.g. use for table hashing on 32-bit).

require"secure_random"require"siphash/halfsiphash"key= uninitializedHalfSipHash::KeySecureRandom.random_bytes(key.to_slice)# generate a 32-bit hash:hash=HalfSipHash(2,4).siphash("some data", key)# => UInt32# generate a 64-bit hash:hash=Bytes.new(8)HalfSipHash(2,4).siphash("some data", hash, key)

A streaming version is also available, limited to 32-bit hashes:

require"secure_random"require"siphash/halfsiphash32"key= uninitializedHalfSipHash32::KeySecureRandom.random_bytes(key.to_slice)hasher=HalfSipHash32(2,4).new(key)hasher.update("some data")hash= hasher.final# => UInt32

License

Distributed under the Apache 2.0 license.

Credits

Created by:

  • Jean-Philippe Aumasson
  • Daniel J. Bernstein

Ported by:

  • Julien Portalier

About

SipHash family of pseudo random functions implemented in Crystal

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp