You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: improve nonce performance
Introduce Nonce class to maintain both Uint8Array and DataView and uint64 so that we can remove nonceToBytes function
* chore: keep the encrypt() and decrypt() interfaces
* chore: move nonce contants to nonce.ts
* chore: fix MAX_NONCE
// For performance reasons, the nonce is represented as a JS `number`
11
-
// JS `number` can only safely represent integers up to 2 ** 53 - 1
12
-
// This is a slight deviation from the noise spec, which describes the max nonce as 2 ** 64 - 2
13
-
// The effect is that this implementation will need a new handshake to be performed after fewer messages are exchanged than other implementations with full uint64 nonces.
14
-
// 2 ** 53 - 1 is still a large number of messages, so the practical effect of this is negligible.
15
-
exportconstMAX_NONCE=Number.MAX_SAFE_INTEGER
16
-
17
-
constERR_MAX_NONCE='Cipherstate has reached maximum n, a new handshake must be performed'
8
+
import{Nonce}from'../nonce.js'
18
9
19
10
exportabstractclassAbstractHandshake{
20
11
publiccrypto: ICryptoInterface
@@ -25,14 +16,14 @@ export abstract class AbstractHandshake {
// For performance reasons, the nonce is represented as a JS `number`
5
+
// Although JS `number` can safely represent integers up to 2 ** 53 - 1, we choose to only use
6
+
// 4 bytes to store the data for performance reason.
7
+
// This is a slight deviation from the noise spec, which describes the max nonce as 2 ** 64 - 2
8
+
// The effect is that this implementation will need a new handshake to be performed after fewer messages are exchanged than other implementations with full uint64 nonces.
9
+
// this MAX_NONCE is still a large number of messages, so the practical effect of this is negligible.
10
+
exportconstMAX_NONCE=0xffffffff
11
+
12
+
constERR_MAX_NONCE='Cipherstate has reached maximum n, a new handshake must be performed'
13
+
14
+
/**
15
+
* The nonce is an uint that's increased over time.
16
+
* Maintaining different representations help improve performance.
0 commit comments