playcrypt.games package
Submodules
playcrypt.games.game module
- class playcrypt.games.game.Game[source]
Bases:
object
This class is the superclass for all games. This doesn’t do anything functional, but it is meant to define the interfaces that are available to simulators. Here almost all initialize and finalize signatures are defined. This is to help define and enforce common behavior.
In general Game objects are meant to be combined with simulator objects in order to test adversaries.
- finalize(m1=None, m2=None)[source]
Finalize method. As per convention in our framework this method always returns true when the adversary wins and is false otherwise.
- Parameters
m1 – Optional param 1 to finalize.
m2 – Optional param 2 to finalize.
- Returns
Returns anything from init that needs to go to the adversary.
playcrypt.games.game_bind module
- class playcrypt.games.game_bind.GameBIND(p, v)[source]
Bases:
playcrypt.games.game.Game
This game is used to test whether a candidate commitment scheme is binding. Adversaries playing this game do not have access to any oracles. However, they do have access to a public parameter pi.
- finalize(args)[source]
This method determines whether the game was won or lost by checking it to see if the adversary was able to construct two (m, k) pairs with the same commitment. :param args: (c,m0,m1,k0,k1) :param c: Target commitment for (m, k) pairs. :param m0: Message 1 :param m1: Message 2 :param k0: Verification parameter 1 :param k1: Verification parameter 2 :return: True on win, False otherwise.
playcrypt.games.game_cca module
- class playcrypt.games.game_cca.GameCCA(encrypt, decrypt, key_len, block_len)[source]
Bases:
playcrypt.games.game_lr.GameLR
This game is used to test whether or not encryption schemes are secure under a chosen cipher text attack. Adversaries playing this game have acces to an lr(l, r) and dec oracle.
- dec(c)[source]
This is a decryption oracle. The adversary can query to decrypt any cipher text that it did not receive from the lr oracle.
- Parameters
c – Cipher text to decrypt.
- Returns
Decryption of cipher text if valid. None otherwise.
- lr(l, r)[source]
This is an lr oracle. It returns the encryption of either the left or or right message that must be of equal length. A query for a particular pair is only allowed to be made once.
- Parameters
l – Left message.
r – Right message.
- Returns
Encryption of left message in left world and right message in right world. If the messages are not of equal length then
None
is returned.
playcrypt.games.game_cr module
- class playcrypt.games.game_cr.GameCR(hash_f, key_len, key_gen=None)[source]
Bases:
playcrypt.games.game.Game
This game is used to test the collision resistance of hash functions. Adversaries playing this game do not have access to any oracles however they do have access to the key used by the hash function.
playcrypt.games.game_int_ctxt module
- class playcrypt.games.game_int_ctxt.GameINTCTXT(required_queries, encrypt, decrypt, key_len)[source]
Bases:
playcrypt.games.game.Game
This game tests the integrity of a ciphertext. It is to be used to test to see if the decryption algorithm only decrypts authentic messages that have been sent by the sender. The Adversary has access to an encryption oracle (enc) and a decryption oracle (dec) that it uses to see if it won.
- enc(m)[source]
Encryption oracle, you can only query for the same message once.
- Parameters
m – Message to be encrypted.
- Returns
Cipher text if valid,
None
otherwise.
playcrypt.games.game_kr module
- class playcrypt.games.game_kr.GameKR(queries, encrypt, key_len, block_len)[source]
Bases:
playcrypt.games.game.Game
This game tests encryption schemes against key recovery attacks. In order to win in this instantiation of KR you must make at least one oracle query. Adversaries have access to an fn oracle.
playcrypt.games.game_lr module
- class playcrypt.games.game_lr.GameLR(queries, encrypt, key_len, key_gen=None)[source]
Bases:
playcrypt.games.game.Game
This game is used as a base game for games that need to determine between a left and right encryption. It is useful to determine how well a scheme is hiding its data from the adversary.
- finalize(guess)[source]
This method is called automatically by the WorldSim and evaluates a guess that is returned by the adversary.
- Parameters
guess – Which world the adversary thinks it is in, either a 0 or 1.
- Returns
True if guess is correct, false otherwise.
- initialize(b=None)[source]
This method initializes the game, generates a new key, and selects a random world if needed.
- Parameters
b – This is an optional parameter that allows the simulator to control which world the game is in. This allows for more exact simulation measurements.
- lr(l, r)[source]
This is an lr oracle. It returns the encryption of either the left or or right message. The encryption and message must be of equal length. A query for a particular pair is only allowed to be made once.
- Parameters
l – Left message.
r – Right message.
- Returns
Encryption of left message in left world and right message in right world. If the messages are not of equal length then
None
is returned.
playcrypt.games.game_prf module
- class playcrypt.games.game_prf.GamePRF(required_queries, prf, key_len, input_len, output_len=None)[source]
Bases:
playcrypt.games.game.Game
This game is used to test whether a candidate function is a good pseudo-random function or not. Adversaries playing this game have access to an fn oracle.
- finalize(guess)[source]
This method is called automatically by the WorldSim and evaluates a guess that is returned by the adversary.
- Parameters
guess – Which world the adversary thinks it is in, either a 0 or 1.
- Returns
True if guess is correct, false otherwise.
- fn(m)[source]
This is the fn oracle that is exposed to the adversary via the simulator. It takes in a message m of length self.input_len and returns either the encrypted result in the real world and the random result in the random world. 0 = random world, 1 = real world.
- Parameters
m – Message adversary wants to encrypt.
- Returns
Either the encrypted result in the real world or random result in the random world.
- initialize(world=None)[source]
This is the initialize method and is part of GamePRF as defined in the slides. It is called automatically by WorldSim when a game is run.
- Parameters
world – This is an optional parameter that allows the simulator to control which world the game is in. This allows for more exact simulation measurements.
- Returns
playcrypt.games.game_ufcma module
- class playcrypt.games.game_ufcma.GameUFCMA(_max_queries, _tag, _verify, key_len, key_gen=None)[source]
Bases:
playcrypt.games.game.Game
This game is meant to test the security of message authentication schemes. Adversaries playing this game have access to a tag and verify oracle.
- finalize(ct)[source]
This method is usually called automatically by the simulator class to determine whether or not the adversary won the game. :ct: (message, tag) :return: True if successful, False otherwise.