Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shuffle: Use cryptographic randomness to generate permutation #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/crypto/shuffle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RP, random_bigint } from './curve'
import { pick_random_bigint } from './pick-random-bigint'
import { Shuffle_Proof, generate_shuffle_proof } from './shuffle-proof'

export type Cipher = { encrypted: RP; lock: RP }
Expand Down Expand Up @@ -45,12 +46,12 @@ export async function shuffle(
return { proof, shuffled }
}

/** Generates an array of all integers up to `size`, in a random order */
/** Generates an array of all integers up to `size`, in a random order, using cryptographic randomness */
function build_permutation_array(size: number) {
const array: number[] = []
const options = [...new Array(size).keys()]
while (options.length) {
const i = Math.floor(Math.random() * options.length)
const i = Number(pick_random_bigint(BigInt(options.length + 1))) - 1
array.push(options.splice(i, 1)[0])
}
return array
Expand Down