oprf module
Oblivious pseudo-random function (OPRF) protocol functionality implementations based on Curve25519 and the Ristretto group.
- class oprf.oprf.data(bs: Optional[bytes] = None)[source]
Bases:
oblivious.ristretto.point
Wrapper class for a bytes-like object that corresponds to a piece of data that can be masked.
- classmethod hash(argument: Union[str, bytes]) oprf.oprf.data [source]
Return data object constructed by hashing the supplied string or bytes-like object.
>>> data.hash('abc').hex() '5a5dbd5c765abf60b2076133482c1ada189c319034ae0b933f4908b3b68d0225' >>> data.hash(bytes([123])).hex() 'be6f2de25b6907d7e07e6a75424c6f4bbed103c2957b9fa9fbe4fd63dfa5575b' >>> data.hash([1, 2, 3]) Traceback (most recent call last): ... TypeError: can only hash a string or bytes-like object to a data object
- classmethod from_base64(s: str) oprf.oprf.data [source]
Convert Base64 UTF-8 string representation of a data instance to a data object.
>>> d = data.hash('abc') >>> data.from_base64(d.to_base64()) == d True
- static __new__(cls, bs: Optional[bytes] = None) oprf.oprf.data [source]
Return data object corresponding to the supplied bytes-like object. No checks are performed to confirm that the bytes-like object is a valid representation of a data object.
>>> d = data.hash('abc') >>> bs = bytes(d) >>> data(bs) == d True
- __truediv__(argument: oprf.oprf.mask) oprf.oprf.data [source]
Unmask this data object (assuming it has previously been masked with the supplied mask).
>>> d = data.hash('abc') >>> m = mask.hash('abc') >>> ((m(d)) / m) == d True
- class oprf.oprf.mask(bs: Optional[bytes] = None)[source]
Bases:
oblivious.ristretto.scalar
Wrapper class for a bytes-like object that corresponds to a mask.
- classmethod random() oprf.oprf.mask [source]
Return random non-zero mask object.
>>> m = mask.random() >>> len(m) == 32 and oblivious.ristretto.scalar(m) == m True
- classmethod hash(argument: Union[str, bytes]) oprf.oprf.mask [source]
Return mask object constructed by hashing the supplied string or bytes-like object.
>>> mask.hash('abc').hex() 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f200150d' >>> mask.hash(bytes([123])).hex() '904ea0ec29650f3b2bcf481e3ea2553488030c865aae2decba8ce7016c4e380c' >>> mask.hash([1, 2, 3]) Traceback (most recent call last): ... TypeError: can only hash a string or bytes-like object to a mask object
- classmethod from_base64(s: str) oprf.oprf.mask [source]
Convert Base64 UTF-8 string representation of a mask instance to a mask object.
>>> m = mask.hash('abc') >>> mask.from_base64(m.to_base64()) == m True
- static __new__(cls, bs: Optional[bytes] = None) oprf.oprf.mask [source]
Return mask object corresponding to the supplied bytes-like object. No checks are performed to confirm that the bytes-like object is a valid representation of a mask object.
>>> m = mask() >>> bs = bytes(m) >>> mask(bs) == m True
- __invert__() oprf.oprf.mask [source]
Return the inverse of this mask instance.
>>> m = mask.hash('abc') >>> (~m).hex() '9d7c69e8dded15ba20544cee233db3148481e713863ddcf0dff9d56470ba8501' >>> d = data.hash('abc') >>> (~m)(m(d)) == d True >>> m((~m)(d)) == d True
- mask(argument: oprf.oprf.data) oprf.oprf.data [source]
Mask a
data
object with this mask and return the masked data object.>>> d = data.hash('abc') >>> m = mask.hash('abc') >>> m.mask(d).hex() 'f47c8267b28ac5100e0e97b36190e16d4533b367262557a5aa7d97b811344d15'
- __call__(argument: oprf.oprf.data) oprf.oprf.data [source]
Mask a
data
object with this mask and return the masked data object.>>> d = data.hash('abc') >>> m = mask.hash('abc') >>> m(d).hex() 'f47c8267b28ac5100e0e97b36190e16d4533b367262557a5aa7d97b811344d15'
- __mul__(argument: oprf.oprf.data) oprf.oprf.data [source]
Mask a
data
object with this mask and return the masked data object.>>> d = data.hash('abc') >>> m = mask.hash('abc') >>> (m * d).hex() 'f47c8267b28ac5100e0e97b36190e16d4533b367262557a5aa7d97b811344d15'
- unmask(argument: oprf.oprf.data) oprf.oprf.data [source]
Unmask a
data
object that has previously been masked with this mask (and return the originaldata
object).>>> d = data.hash('abc') >>> m = mask.hash('abc') >>> m.unmask(m(d)) == d True