Skip to content

Commit

Permalink
feat(group): make Oprf.Group pluggable
Browse files Browse the repository at this point in the history
  • Loading branch information
sublimator authored and armfazh committed Jun 19, 2023
1 parent 0a3826f commit e84b252
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 181 deletions.
6 changes: 3 additions & 3 deletions bench/group.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// at https://opensource.org/licenses/BSD-3-Clause

import Benchmark from 'benchmark'
import { Group } from '../src/index.js'
import { Oprf } from '../src/index.js'

function asyncFn(call: CallableFunction) {
return {
Expand All @@ -21,8 +21,8 @@ export async function benchGroup(bs: Benchmark.Suite) {
const msg = te.encode('msg')
const dst = te.encode('dst')

for (const id of Object.values(Group.ID)) {
const gg = new Group(id)
for (const id of Object.values(Oprf.Group.ID)) {
const gg = new Oprf.Group(id)
const k = await gg.randomScalar()
const P = gg.mulGen(k)
const Q = P.mul(k)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"eslint-plugin-security": "1.5.0",
"jest": "29.3.1",
"prettier": "2.7.1",
"typescript": "4.8.4"
"typescript": "4.8.4",
"sjcl": "1.0.8"
},
"scripts": {
"prepack": "tsc -b",
Expand All @@ -52,8 +53,5 @@
"lint": "eslint .",
"bench": "tsc -b bench && node ./lib/bench/index.js",
"format": "prettier './(src|test|bench|examples)/*.ts' --write"
},
"dependencies": {
"sjcl": "1.0.8"
}
}
6 changes: 3 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the BSD-3-Clause license found in the LICENSE file or
// at https://opensource.org/licenses/BSD-3-Clause

import { Elt, Scalar } from './group.js'
import { Elt, Scalar } from './groupTypes.js'
import { Evaluation, EvaluationRequest, FinalizeData, ModeID, Oprf, SuiteID } from './oprf.js'

import { zip } from './util.js'
Expand Down Expand Up @@ -76,7 +76,7 @@ export class VOPRFClient extends baseClient {
if (!evaluation.proof) {
throw new Error('no proof provided')
}
const pkS = Elt.deserialize(this.gg, this.pubKeyServer)
const pkS = this.gg.desElt(this.pubKeyServer)

const n = finData.inputs.length
if (evaluation.evaluated.length !== n) {
Expand Down Expand Up @@ -104,7 +104,7 @@ export class POPRFClient extends baseClient {
private async pointFromInfo(info: Uint8Array): Promise<Elt> {
const m = await this.scalarFromInfo(info)
const T = this.gg.mulGen(m)
const pkS = Elt.deserialize(this.gg, this.pubKeyServer)
const pkS = this.gg.desElt(this.pubKeyServer)
const tw = pkS.add(T)
if (tw.isIdentity()) {
throw new Error('invalid info')
Expand Down
11 changes: 6 additions & 5 deletions src/dleq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Implementation of batched discrete log equivalents proofs (DLEQ) as
// described in https://www.ietf.org/id/draft-irtf-cfrg-voprf-09.html#name-discrete-log-equivalence-pr.
import { Elt, Group, Scalar } from './group.js'
import { Elt, Group, Scalar } from './groupTypes.js'
import { checkSize, joinAll, to16bits, toU16LenPrefix } from './util.js'

export interface DLEQParams {
Expand Down Expand Up @@ -121,14 +121,15 @@ export class DLEQProof {
}

static size(params: DLEQParams): number {
return 2 * Scalar.size(params.gg)
return 2 * params.gg.scalarSize()
}

static deserialize(params: Required<DLEQParams>, bytes: Uint8Array): DLEQProof {
checkSize(bytes, DLEQProof, params)
const n = Scalar.size(params.gg)
const c = Scalar.deserialize(params.gg, bytes.subarray(0, n))
const s = Scalar.deserialize(params.gg, bytes.subarray(n, 2 * n))
const group = params.gg
const n = group.scalarSize()
const c = group.desScalar(bytes.subarray(0, n))
const s = group.desScalar(bytes.subarray(n, 2 * n))
return new DLEQProof(params, c, s)
}
}
Expand Down
Loading

0 comments on commit e84b252

Please sign in to comment.