blob: bf80508799dd5c4e7683b2c8e1760d6d80780ad6 [file] [log] [blame]
#!/usr/bin/env python3
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
"""
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from amcl import core_utils, factoring_zk
seed_hex = "78d0fb6705ce77dee47d03eb5b9c5d30"
p_hex = "e008507e09c24d756280f3d94912fb9ac16c0a8a1757ee01a350736acfc7f65880f87eca55d6680253383fc546d03fd9ebab7d8fa746455180888cb7c17edf58d3327296468e5ab736374bc9a0fa02606ed5d3a4a5fb1677891f87fbf3c655c3e0549a86b17b7ddce07c8f73e253105e59f5d3ed2c7ba5bdf8495df40ae71a7f"
q_hex = "dbffe278edd44c2655714e5a4cc82e66e46063f9ab69df9d0ed20eb3d7f2d8c7d985df71c28707f32b961d160ca938e9cf909cd77c4f8c630aec34b67714cbfd4942d7147c509db131bc2d6a667eb30df146f64b710f8f5247848b0a75738a38772e31014fd63f0b769209928d586499616dcc90700b393156e12eea7e15a835"
n_hex = "c0870b552afb6c8c09f79e39ad6ca17ca93085c2cd7a726ade69574961ff9ce8ad33c7dda2e0703a3b0010c2e5bb7552c74164ce8dd011d85e5969090df53fe10e39cbe530704da32ff07228a6b6da34a5929e8a231c3080d812dc6e93affd81682339a6aee192927c582da8941bebf46e13c4ea3918a1477951fa66d367e70d8551b1869316d48317e0702d7bce242a326000f3dc763c44eba2044a1df713a94c1339edd464b145dcadf94e6e61be73dc270c878e1a28be720df2209202d00e101c3b255b757eaf547acd863d51eb676b851511b3dadeda926714719dceddd3af7908893ae65f2b95ee5c4d36cc6862cbe6886a62d7c1e2d0db48c399a6d44b"
uid = b"unique_user_identifier"
if __name__ == "__main__":
seed = bytes.fromhex(seed_hex)
rng = core_utils.create_csprng(seed)
p = bytes.fromhex(p_hex)
q = bytes.fromhex(q_hex)
n = bytes.fromhex(n_hex)
ad = core_utils.generate_random(rng, 32)
print("Example ZK Proof of Knowledge of factoring")
print("Parameters")
print(f"\tP = {p.hex()}")
print(f"\tQ = {q.hex()}")
print(f"\tN = {n.hex()}")
print(f"\tID = {uid.decode('utf-8')}")
print(f"\tAD = {ad.hex()}")
# Prove
e, y = factoring_zk.prove(rng, p, q, uid, ad=ad)
print("\nGenerate proof")
print(f"\tE = {e.hex()}")
print(f"\tY = {y.hex()}")
# Verify
ec = factoring_zk.verify(n, e, y, uid, ad=ad)
print("\nVerify proof")
if ec == factoring_zk.OK:
print("\tSuccess")
else:
print("\tFailure")