-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds examples of the OPRF protocol execution.
- Loading branch information
Showing
4 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = Evaluate(blindedElement) | ||
evaluated_element = server.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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = Evaluate(blindedElement, info) | ||
evaluated_element, proof, _ = server.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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = Evaluate(blindedElement) | ||
evaluated_element, proof, _ = server.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)) |