@@ -6,56 +6,82 @@ Constant-time algorithms written in TypeScript.
6
6
[ ![ Linux Build Status] ( https://travis-ci.org/soatok/constant-time-js.svg?branch=master )] ( https://travis-ci.org/soatok/constant-time-js )
7
7
[ ![ npm version] ( https://img.shields.io/npm/v/constant-time-js.svg )] ( https://npm.im/constant-time-js )
8
8
9
- ** Important** : This Github repository is the companion to [ Soatok's Guide to Side-Channel Attacks] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/ ) . Do not use this in production, especially if you don't have the budget for a cryptography audit.
9
+ ** Important** : This Github repository is the companion to [ Soatok's Guide to Side-Channel Attacks] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/ ) .
10
+ Do not use this in production, especially if you don't have the budget for a cryptography audit.
10
11
11
12
![ Mind Blowing, right?] ( https://soatok.files.wordpress.com/2020/08/soatoktelegrams2020-01.png )
12
13
13
14
## Documentation
14
15
16
+ This is just a quick outline of what each function does.
17
+
15
18
* ` compare(a, b) ` - Compare two ` Uint8Array ` objects.
19
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#string-inequality )
16
20
* Returns ` -1 ` if ` a < b `
17
21
* Returns ` 1 ` if ` a > b `
18
22
* Returns ` 0 ` if ` a === b `
19
23
* Throws an ` Error ` if ` a.length !== b.length `
20
24
* ` compare_ints(a, b) ` - Compare two integers.
25
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#string-inequality )
21
26
* Returns ` -1 ` if ` a < b `
22
27
* Returns ` 1 ` if ` a > b `
23
28
* Returns ` 0 ` if ` a === b `
24
29
* ` equals(a, b) ` - Are these ` Uint8Array ` objects equal?
30
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#string-comparison )
25
31
* Returns ` true ` if they are equal.
26
32
* Returns ` false ` if they are not equal.
27
33
* Throws an ` Error ` if ` a.length !== b.length `
28
34
* ` hmac_equals(a, b) ` - Are these ` Uint8Array ` objects equal? (Using HMAC to compare.)
35
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#double-hmac )
29
36
* Returns ` true ` if they are equal.
30
37
* Returns ` false ` if they are not equal.
31
38
* Throws an ` Error ` if ` a.length !== b.length `
32
39
* ` intdiv(N, D) ` - Divide ` N ` into ` D ` , discarding remainder.
40
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#integer-division )
33
41
* Returns an integer.
34
42
* ` modulo(N, D) ` - Divide ` N ` into ` D ` , return the remainder.
43
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#integer-division )
35
44
* Returns an integer.
36
45
* ` resize(buf, size) ` - Return a resized ` Uint8Array ` object (to side-step memory access leakage)
37
46
* ` select(x, a, b) ` - Read it as a ternary. If ` x ` is true, returns ` a ` . Otherwise, returns ` b ` .
47
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#conditional-select )
38
48
* ` x ` must be a ` boolean `
39
49
* ` a ` must be a ` Uint8Array `
40
50
* ` b ` must be a ` Uint8Array `
41
51
* Throws an ` Error ` if ` a.length !== b.length `
42
52
* ` select_ints(x, a, b) ` - Read it as a ternary. If ` x ` is even, returns ` a ` . Otherwise, returns ` b ` .
43
53
(You should pass ` 1 ` or ` 0 ` for ` x ` ).
54
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#conditional-select )
44
55
* ` x ` must be a ` boolean `
45
56
* ` a ` must be a ` number `
46
57
* ` b ` must be a ` number `
47
58
* ` trim_zeroes_left(buf) `
59
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#null-byte-trimming )
48
60
* ` buf ` must be a ` Uint8Array `
49
61
* Returns a ` Uint8Array `
50
62
* ` trim_zeroes_right(buf) `
63
+ * [ Explanation] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/#null-byte-trimming )
51
64
* ` buf ` must be a ` Uint8Array `
52
65
* Returns a ` Uint8Array `
53
66
67
+ ### Not Implemented From the Blog Post Yet
68
+
69
+ * Constant-Time Integer Multiplication
70
+ * Constant-Time Modular Inversion
71
+
54
72
## Limitations
55
73
56
- ### Do not use on 32-bit processes.
74
+ ### Potentially Dangerous on 32-bit Applications
75
+
76
+ 32-bit v8 (and, presumably, a lot of other 32-bit implementations) do things wrong,
77
+ and our implementation might be variable-time on it.
78
+
79
+ Specifically, the most significant bit of a 32-bit integer distinguishes values from pointers.
80
+ As a result, accessing the highest bit of a 32-bit number in 32-bit JavaScript engines (such as v8)
81
+ is potentially variable-time.
57
82
58
- 32-bit v8 (and, presumably, a lot of other implementations) do things wrong, and this will be variable-time on it.
83
+ To mitigate this risk, the [ ` int32 ` class was created] ( https://github.com/soatok/constant-time-js/blob/master/lib/int32.ts )
84
+ which wraps operates on 16-bit limbs (wrapping ` Uint16Array ` ).
59
85
60
86
## Frequently Asked Questions
61
87
@@ -68,6 +94,16 @@ Constant-time algorithms written in TypeScript.
68
94
This is a proof-of-concept library, that will eventually implement
69
95
all of the algorithms described in [ the accompanying blog post] ( https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/ ) .
70
96
97
+ The main purpose of this library is to demonstrate the concepts in a programming
98
+ language widely accessible outside of the cryptography orthodoxy (which today is
99
+ largely C and sometimes Python, and hopefully soon Rust).
100
+
101
+ ### Can I use this in a project?
102
+
103
+ Hold off until v1.0.0 is tagged before you even * think* about relying on it for
104
+ anything. APIs might break until then.
105
+ My fursona is a [ dhole] ( https://soatok.blog/2020/08/10/all-about-dholes-and-dhole-fursonas/ ) , not a wolf.
106
+
71
107
### What's with the blue {fox, wolf}?
72
108
73
109
My fursona is a [ dhole] ( https://soatok.blog/2020/08/10/all-about-dholes-and-dhole-fursonas/ ) , not a wolf.
0 commit comments