oprf.sage 896 B

12345678910111213141516171819202122232425262728
  1. # Oblivious Pseudo-Random function
  2. # Constructing an OPRF on elliptic curves is possible if the curve is a
  3. # prime-order group.
  4. Fp = GF(0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001)
  5. input_block = Fp(42)
  6. # Alice generates a random blinding factor r, and multiplies her input block
  7. # with this r
  8. r = Fp.random_element()
  9. alpha = input_block * r
  10. # She sends alpha over to Bob, who has the key k and wants to keep it secret,
  11. # so Bob calculates beta from alpha and the key
  12. #k = Fp.random_element()
  13. k = Fp(69420)
  14. beta = alpha * k
  15. # And then sends back beta to Alice, who can then unblind the result, by
  16. # multiplying beta with 1/r
  17. output_block = beta * (1 / r)
  18. # If we expand the last calculation we can see how r is eliminated by 1/r
  19. # output_block = input_block * r * k * (1/r)
  20. # And by cancelling out r and 1/r we get:
  21. #output_block = input_block * k
  22. print(output_block)