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

Update reference code to match main document #347

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion poc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ setup:
test: pyfiles
sage test_oprf.sage

examples: pyfiles
sage example_oprf.sage
sage example_voprf.sage
sage example_poprf.sage

vectors: pyfiles
@echo "Removing vectors folder, if present"
@rm -rf vectors
Expand All @@ -34,4 +39,4 @@ clean:

.PHONY: distclean
distclean: clean
rm -rf vectors ascii
rm -rf vectors ascii
53 changes: 53 additions & 0 deletions poc/example_oprf.sage
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/sage
# vim: syntax=python

"""Exemplifies a run of the OPRF protocol"""

import os
import sys

try:
from sagelib.test_drng import TestDRNG
from sagelib.oprf \
import DeriveKeyPair, SetupOPRFServer, SetupOPRFClient, MODE_OPRF, \
oprf_ciphersuites, ciphersuite_p256_sha256

except ImportError as err:
sys.exit("Try running `make setup && make clean pyfiles`. Full error: " + err)

to_hex = lambda x: "".join(["{:02x}".format(i) for i in x])

if __name__ == "__main__":
# Offline Setup
rng = TestDRNG('prng-seed'.encode('utf-8'))
suite = oprf_ciphersuites[ciphersuite_p256_sha256]
Ns = suite.group.scalar_byte_length()
info = b'info specific for this key'
seed = os.urandom(Ns)
skS, _ = DeriveKeyPair(MODE_OPRF, suite, seed, info)

client = SetupOPRFClient(suite)
server = SetupOPRFServer(suite, skS)

# Online Protocol
#
# Client Server(skS)
# -------------------------------------------------------------------
# blind, blindedElement = Blind(input)
input = b'alice in wonderland'
blind, blinded_element = client.blind(input, rng)
# blindedElement
# ---------->
#
# evaluatedElement = BlindEvaluate(skS, blindedElement)
evaluated_element = server.blind_evaluate(blinded_element, rng)
#
# evaluatedElement
# <----------
#
# output = Finalize(input, blind, evaluatedElement)
output = client.finalize(input, blind, evaluated_element)
print("mode:", "OPRF")
print("suite:", suite.name)
print("input:", to_hex(input))
print("output:", to_hex(output))
55 changes: 55 additions & 0 deletions poc/example_poprf.sage
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/sage
# vim: syntax=python

"""Exemplifies a run of the POPRF protocol"""

import os
import sys

try:
from sagelib.test_drng import TestDRNG
from sagelib.oprf \
import DeriveKeyPair, SetupPOPRFServer, SetupPOPRFClient, MODE_POPRF, \
oprf_ciphersuites, ciphersuite_p256_sha256

except ImportError as err:
sys.exit("Try running `make setup && make clean pyfiles`. Full error: " + err)

to_hex = lambda x: "".join(["{:02x}".format(i) for i in x])

if __name__ == "__main__":
# Offline Setup
rng = TestDRNG('prng-seed'.encode('utf-8'))
suite = oprf_ciphersuites[ciphersuite_p256_sha256]
Ns = suite.group.scalar_byte_length()
info = b'info specific for this key'
seed = os.urandom(Ns)
skS, pkS = DeriveKeyPair(MODE_POPRF, suite, seed, info)

client = SetupPOPRFClient(suite, pkS)
server = SetupPOPRFServer(suite, skS, pkS)

# Online Protocol
#
# Client(pkS, info) <---- pkS ------ Server(skS, info)
# -------------------------------------------------------------------
# blind, blindedElement, tweakedKey = Blind(input, info)
input = b'alice in wonderland'
blind, blinded_element, tweaked_key = client.blind(input, info, rng)
#
# blindedElement
# ---------->
#
# evaluatedElement, proof = BlindEvaluate(blindedElement, info)
evaluated_element, proof, _ = server.blind_evaluate(blinded_element, info, rng)
#
# evaluatedElement, proof
# <----------
#
# output = Finalize(input, blind, evaluatedElement,
# blindedElement, proof, info, tweakedKey)
output = client.finalize(input, blind, evaluated_element, blinded_element, proof, info, tweaked_key)
print("mode:", "POPRF")
print("suite:", suite.name)
print("input:", to_hex(input))
print("output:", to_hex(output))
52 changes: 52 additions & 0 deletions poc/example_voprf.sage
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/sage
# vim: syntax=python

"""Exemplifies a run of the VOPRF protocol"""

import os
import sys

try:
from sagelib.test_drng import TestDRNG
from sagelib.oprf \
import DeriveKeyPair, SetupVOPRFServer, SetupVOPRFClient, MODE_VOPRF, \
oprf_ciphersuites, ciphersuite_p256_sha256

except ImportError as err:
sys.exit("Try running `make setup && make clean pyfiles`. Full error: " + err)

to_hex = lambda x: "".join(["{:02x}".format(i) for i in x])

if __name__ == "__main__":
# Offline Setup
rng = TestDRNG('prng-seed'.encode('utf-8'))
suite = oprf_ciphersuites[ciphersuite_p256_sha256]
Ns = suite.group.scalar_byte_length()
info = b'info specific for this key'
seed = os.urandom(Ns)
skS, pkS = DeriveKeyPair(MODE_VOPRF, suite, seed, info)

client = SetupVOPRFClient(suite, pkS)
server = SetupVOPRFServer(suite, skS, pkS)

# Online Protocol
#
# Client(pkS) Server(skS,pkS)
# -------------------------------------------------------------------
# blind, blindedElement = Blind(input)
input = b'alice in wonderland'
blind, blinded_element = client.blind(input, rng)
# blindedElement
# ---------->
#
# evaluatedElement, proof = BlindEvaluate(blindedElement)
evaluated_element, proof, _ = server.blind_evaluate(blinded_element, rng)
# <----------
#
# output = Finalize(input, blind, evaluatedElement,
# blindedElement, proof)
output = client.finalize(input, blind, evaluated_element, blinded_element, proof)
print("mode:", "VOPRF")
print("suite:", suite.name)
print("input:", to_hex(input))
print("output:", to_hex(output))
Loading