10
10
[ ![ Carthage compatible] ( https://img.shields.io/badge/Carthage-compatible-4BC51D.svg )] ( https://github.com/Carthage/Carthage )
11
11
[ ![ CocoaPod Version] ( https://img.shields.io/cocoapods/v/SipHash.svg )] ( http://cocoapods.org/pods/SipHash )
12
12
13
- ` SipHash ` is a pure Swift implementation of the [ SipHash] hashing algorithm designed by
13
+ ` SipHash ` is a pure Swift implementation of the [ SipHash] hashing algorithm designed by
14
14
Jean-Philippe Aumasson and Daniel J. Bernstein in 2012:
15
15
16
16
[ SipHash ] : https://131002.net/siphash
17
17
18
- > SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions) optimized for speed on short messages.
18
+ > SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions) optimized for speed on short messages.
19
19
>
20
- > Target applications include network traffic authentication and defense against hash-flooding DoS attacks.
20
+ > Target applications include network traffic authentication and defense against hash-flooding DoS attacks.
21
21
>
22
22
> SipHash is secure, fast, and simple (for real):
23
23
> - SipHash is simpler and faster than previous cryptographic algorithms (e.g. MACs based on universal hashing)
@@ -35,7 +35,7 @@ independent implementation that's available for use in third-party code.
35
35
36
36
The current release of SipHash requires Swift 4.
37
37
38
- ## Sample Code
38
+ ## Sample Code
39
39
40
40
``` swift
41
41
import SipHash
@@ -45,7 +45,7 @@ struct Book: SipHashable {
45
45
let title: String
46
46
let pageCount: Int
47
47
48
- // You need to implement this method instead of `hashValue`.
48
+ // You need to implement this method instead of `hashValue`.
49
49
func appendHashes (to hasher : inout SipHasher) {
50
50
// Simply append the fields you want to include in the hash.
51
51
hasher.append (title)
@@ -67,39 +67,39 @@ var hasher = SipHasher()
67
67
hasher.add (book)
68
68
hasher.add (42 )
69
69
// Finalizing the hasher extracts the hash value and invalidates it.
70
- let hash = hasher.finalize ()
70
+ let hash = hasher.finalize ()
71
71
```
72
72
73
73
## Why Would I Use SipHash?
74
74
75
75
Writing a good implementation of ` hashValue ` is hard, even if we just need to combine the values of a couple of fields.
76
76
We need to come up with a deterministic function that blends the field values well, producing a fixed-width
77
77
result without too many collisions on typical inputs. But how many collisions are "too many"? Do we even know what
78
- our "typical inputs" look like? For me, the answer to both of these questions is usually "I have absolutely no idea",
78
+ our "typical inputs" look like? For me, the answer to both of these questions is usually "I have absolutely no idea",
79
79
and I bet you have the same problem.
80
80
81
81
Thus, verifying that our ` hashValue ` implementations work well is an exercise in frustration.
82
82
83
83
We need to somehow check the properties of the hash function by looking at its behavior given various inputs.
84
- It is easy enough to write tests for the requirement that equal values have equal ` hashValues ` .
85
- But verifying that the hash has few collisions requires making some assumptions on the
84
+ It is easy enough to write tests for the requirement that equal values have equal ` hashValues ` .
85
+ But verifying that the hash has few collisions requires making some assumptions on the
86
86
statistical properties of "typical" inputs -- and even if we'd be somehow confident enough to do that, writing the code
87
87
to do it is way too complicated.
88
88
89
- Instead of rolling your own ad-hoc hash function, why not just use an algorithm designed specifically to blend data
90
- into a hash? Using a standardized algorithm means we don't need to worry about collision behavior any more: if the
89
+ Instead of rolling your own ad-hoc hash function, why not just use an algorithm designed specifically to blend data
90
+ into a hash? Using a standardized algorithm means we don't need to worry about collision behavior any more: if the
91
91
algorithm was designed well, we'll always have good results.
92
92
93
- The SipHash algorithm is a particularly good choice for hashing. It implements a 64-bit cryptographic
94
- message-authentication code (MAC) with a 256-bit internal state initialized from a 128-bit secret key that's (typically)
95
- randomly generated for each execution of the binary.
93
+ The SipHash algorithm is a particularly good choice for hashing. It implements a 64-bit cryptographic
94
+ message-authentication code (MAC) with a 256-bit internal state initialized from a 128-bit secret key that's (typically)
95
+ randomly generated for each execution of the binary.
96
96
SipHash is designed to protect against hash collision attacks, while remaining simple to use and fast.
97
- It is already used by Perl, Python, Ruby, Rust, and even Swift itself -- which is why the documentation of ` Hashable `
97
+ It is already used by Perl, Python, Ruby, Rust, and even Swift itself -- which is why the documentation of ` Hashable `
98
98
explicitly warns that the value returned by ` hashValue ` may be different across executions.
99
99
100
- The standard library already implements SipHash, but the implementation is private. (It is technically available
100
+ The standard library already implements SipHash, but the implementation is private. (It is technically available
101
101
for use, but it is not formally part of the stdlib API, and it is subject to change/removal across even point releases.)
102
- I expect a refactored version of stdlib's SipHash will become available as public API in a future Swift release.
102
+ I expect a refactored version of stdlib's SipHash will become available as public API in a future Swift release.
103
103
But while we're waiting for that, this package provides an alternative implementation that is available today.
104
104
105
105
## Is this code full of bugs?
@@ -108,8 +108,8 @@ Indubitably. Please report all bugs you find!
108
108
109
109
The package has 100% unit test coverage. Unfortunately this doesn't tell you much about its reliability in practice.
110
110
111
- The test suite verifies that the package generates values that match the test vectors supplied by SipHash's original
112
- authors, which makes me reasonably confident that this package implements SipHash correctly.
111
+ The test suite verifies that the package generates values that match the test vectors supplied by SipHash's original
112
+ authors, which makes me reasonably confident that this package implements SipHash correctly.
113
113
Obviously, your mileage may vary.
114
114
115
115
## Reference docs
@@ -147,7 +147,7 @@ import PackageDescription
147
147
let package = Package(
148
148
name: "MyPackage",
149
149
dependencies: [
150
- .Package(url: "https://github.com/attaswift/SipHash.git", from: "1.2.0 ")
150
+ .Package(url: "https://github.com/attaswift/SipHash.git", from: "1.2.1 ")
151
151
]
152
152
)
153
153
```
@@ -159,4 +159,3 @@ If you don't use a dependency manager, you need to clone this repo somewhere nea
159
159
To link your application binary with SipHash, just add ` SipHash.framework ` from the SipHash project to the Embedded Binaries section of your app target's General page in Xcode. As long as the SipHash project file is referenced in your workspace, this framework will be listed in the "Choose items to add" sheet that opens when you click on the "+" button of your target's Embedded Binaries list.
160
160
161
161
There is no need to do any additional setup beyond adding the framework targets to Embedded Binaries.
162
-
0 commit comments