-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoprf.js
94 lines (79 loc) · 2.12 KB
/
oprf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2021-2023, Alden Torres
*
* Licensed under the terms of the MIT license.
* Copy of the license at https://opensource.org/licenses/MIT
*/
import {
libecc,
} from "./util.js";
/**
* Evaluates serialized representations of blinded group elements from the
* client as inputs.
*
* @param {Uint8Array} skS private key
* @param {Uint8Array} blindedElement blinded element
* @param {Uint8Array} info
* @return {Uint8Array} evaluated element
*/
export function oprf_Evaluate(skS, blindedElement, info) {
let evaluatedElement = new Uint8Array(32);
libecc.ecc_voprf_ristretto255_sha512_BlindEvaluate(
evaluatedElement,
skS,
blindedElement,
);
return evaluatedElement;
}
/**
* Same as calling `oprf_Blind` with a
* specified scalar blind.
*
* @param {Uint8Array} input message to blind
* @param {Uint8Array} blind scalar to use in the blind operation
* @return {Uint8Array} blinded element
*/
export function oprf_BlindWithScalar(input, blind) {
let blindedElement = new Uint8Array(32);
libecc.ecc_voprf_ristretto255_sha512_BlindWithScalar(
blindedElement,
input, input.length,
blind,
libecc.ecc_voprf_ristretto255_sha512_MODE_OPRF,
);
return blindedElement;
}
/**
*
* @param {Uint8Array} input message to blind
* @return object {blind, blindedElement}
*/
export function oprf_Blind(input) {
let blindedElement = new Uint8Array(32);
let blind = new Uint8Array(32);
libecc.ecc_voprf_ristretto255_sha512_Blind(
blindedElement,
blind,
input, input.length,
libecc.ecc_voprf_ristretto255_sha512_MODE_OPRF,
);
return {blind: blind, blindedElement: blindedElement};
}
/**
*
* @param input the input message
* @param blind
* @param evaluatedElement
* @param {Uint8Array} info
*/
export function oprf_Finalize(input, blind, evaluatedElement, info) {
let output = new Uint8Array(64);
libecc.ecc_voprf_ristretto255_sha512_Finalize(
output,
input, input.length,
blind,
evaluatedElement,
info, info.length,
);
return output;
}