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
#### Oblivious pseudo-random function over an elliptic curve (ED25519)
7
-
6
+
#### Oblivious pseudo-random function over an elliptic curve (Ristretto255)
8
7
9
8
## Installation
10
-
```npm install oprf```
9
+
For node.js, use:
10
+
11
+
```bash
12
+
npm install oprf
13
+
```
14
+
15
+
For the browser, include a script tag targeting either `dist/oprf.js` or `dist/oprf.slim.js`.
16
+
17
+
## Bundle vs slim
18
+
19
+
For browsers, we provide two built files: `dist/oprf.js` and `dist/oprf.slim.js`.
20
+
21
+
The first includes both OPRF bundled with [libsodium-wrappers-sumo](https://github.com/jedisct1/libsodium.js) version 0.7.6. The second includes only OPRF.
22
+
23
+
You can use the slim version for cases where your browser-side code uses a more recent version of libsodium, or if you want
24
+
to load libsodium asynchronously to reduce page load time.
25
+
26
+
The API for both versions is identical, except that the slim OPRF constructor expects a sodium instance to be passed in
27
+
as a parameter, while the bundled constructor does not expect any parameters.
28
+
29
+
In node.js, the slim OPRF is not exposed.
30
+
31
+
```javascript
32
+
constOPRF=require('oprf');
33
+
constoprf=newOPRF(); // will require('libsodium-wrappers-sumo');
34
+
```
11
35
12
36
## Initialization
13
-
The sumo version of libsodium must be used
37
+
OPRF is not safe to use until sodium is done loading.
38
+
14
39
```Typescript
15
-
await_sodium.ready;
16
-
const oprf=newOPRF(_sodium);
40
+
const oprf =newOPRF();
41
+
awaitoprf.ready; // wait for dependencies to load
17
42
```
18
43
19
44
## Security Guarantees
20
45
A client has input _x_ while a server holds key _k_. The client receives the output of *f<sub>k</sub>(x)* for some pseudorandom function family *f<sub>k</sub>*. The server learns nothing.
The implementation uses [Ristretto255](https://libsodium.gitbook.io/doc/advanced/point-arithmetic/ristretto), and does not suffer from small cofactor attacks.
26
48
27
49
## Public Interface
28
50
Contains a masked point and the mask that was applied to it
29
51
```Typescript
30
52
exportinterfaceIMaskedData {
31
-
readonly point:number[];
32
-
readonly mask:BN; // big number
53
+
readonly point:Uint8Array;
54
+
readonly mask:Uint8Array;
33
55
}
34
56
```
35
57
36
58
## Public Functions
59
+
37
60
**hashToPoint**: maps string input to a point on the elliptic curve
38
61
```Typescript
39
-
publichashToPoint(input: string): number[]
62
+
publichashToPoint(input: string): Uint8Array
63
+
```
64
+
65
+
**isValidPoint**: returns whether the given point exists on the elliptic curve
66
+
```Typescript
67
+
publicisValidPoint(point: Uint8Array): boolean
40
68
```
69
+
41
70
**maskInput**: hashes string input as a point on an elliptic curve and applies a random mask to it
42
71
```Typescript
43
72
publicmaskInput(input: string): IMaskedData
44
73
```
45
-
**generateRandomScalar**: generates a random 32-byte array of numbers
74
+
75
+
**maskPoint**: applies a random mask to an elliptic curve point
46
76
```Typescript
47
-
publicgenerateRandomScalar(): BN
77
+
publicmaskPoint(point: Uint8Array): IMaskedData
48
78
```
49
-
**isValidPoint**: returns whether the given point exists on the elliptic curve
79
+
80
+
**unmaskInput**: applies the multiplicative inverse of the mask to the masked point
@@ -69,22 +108,30 @@ public unmaskInput(maskedPoint: number[], mask: BN): number[]
69
108
const input ='hello world';
70
109
const masked =oprf.maskInput(input);
71
110
72
-
// Send masked.point to server. Do not send masked.mask to the server since it can easily unmask your original input.
111
+
// Send masked.point to server,
112
+
// Do not send masked.mask to the server.
113
+
send(oprf.encodePoint(masked.point, 'UTF-8'));
73
114
```
74
115
75
116
2.) **Server**: salt the masked point using a secret key
76
117
```Typescript
77
-
// Note: your actual secret key should be a static 32-byte Uint8Array. Do not generate a new scalar for each OPRF unless you have a specific use case for doing so.
78
-
const secretKey =oprf.generateRandomScalar();
118
+
// Note: your actual secret key should be fixed.
119
+
// Do not generate a new scalar for each OPRF
120
+
// application unless you have a specific use case for doing so.
0 commit comments