<s> '''<STR_LIT>''' <EOL> from parser import stpcommands <EOL> from ciphers . cipher import AbstractCipher <EOL> from parser . stpcommands import getStringLeftRotate as rotl <EOL> from parser . stpcommands import getStringRightRotate as rotr <EOL> class ChasKeyMacHalf ( AbstractCipher ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> num_messages = <NUM_LIT:1> <EOL> def getFormatString ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def createSTP ( self , stp_filename , parameters ) : <EOL> """<STR_LIT>""" <EOL> wordsize = parameters [ "<STR_LIT>" ] <EOL> rounds = parameters [ "<STR_LIT>" ] <EOL> weight = parameters [ "<STR_LIT>" ] <EOL> self . num_messages = parameters [ "<STR_LIT>" ] <EOL> with open ( stp_filename , '<STR_LIT:w>' ) as stp_file : <EOL> stp_file . write ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( wordsize , rounds ) ) <EOL> v0 = [ "<STR_LIT>" . format ( i ) for i in range ( ( rounds + <NUM_LIT:1> ) * self . num_messages ) ] <EOL> v1 = [ "<STR_LIT>" . format ( i ) for i in range ( ( rounds + <NUM_LIT:1> ) * self . num_messages ) ] <EOL> v2 = [ "<STR_LIT>" . format ( i ) for i in range ( ( rounds + <NUM_LIT:1> ) * self . num_messages ) ] <EOL> v3 = [ "<STR_LIT>" . format ( i ) for i in range ( ( rounds + <NUM_LIT:1> ) * self . num_messages ) ] <EOL> w0 = [ "<STR_LIT>" . format ( i ) for i in range ( rounds * self . num_messages ) ] <EOL> w1 = [ "<STR_LIT>" . format ( i ) for i in range ( rounds * self . num_messages ) ] <EOL> stpcommands . setupVariables ( stp_file , v0 , wordsize ) <EOL> stpcommands . setupVariables ( stp_file , v1 , wordsize ) <EOL> stpcommands . setupVariables ( stp_file , v2 , wordsize ) <EOL> stpcommands . setupVariables ( stp_file , v3 , wordsize ) <EOL> stpcommands . setupVariables ( stp_file , w0 , wordsize ) <EOL> stpcommands . setupVariables ( stp_file , w1 , wordsize ) <EOL> stpcommands . setupWeightComputation ( stp_file , weight , w0 + w1 , wordsize , <NUM_LIT:1> ) <EOL> for i in range ( rounds ) : <EOL> self . setupChasKeyRound ( stp_file , i , v0 [ i ] , v1 [ i ] , v2 [ i ] , v3 [ i ] , <EOL> v0 [ i + <NUM_LIT:1> ] , v1 [ i + <NUM_LIT:1> ] , v2 [ i + <NUM_LIT:1> ] , v3 [ i + <NUM_LIT:1> ] , <EOL> w0 [ i ] , w1 [ i ] , wordsize ) <EOL> stpcommands . assertNonZero ( stp_file , v0 + v1 + v2 + v3 , wordsize ) <EOL> for key , value in parameters [ "<STR_LIT>" ] . items ( ) : <EOL> stpcommands . assertVariableValue ( stp_file , key , value ) <EOL> for char in parameters [ "<STR_LIT>" ] : <EOL> stpcommands . blockCharacteristic ( stp_file , char , wordsize ) <EOL> stpcommands . setupQuery ( stp_file ) <EOL> return <EOL> def setupChasKeyRound ( self , stp_file , rnd , v0_in , v1_in , v2_in , v3_in , v0_out , <EOL> v1_out , v2_out , v3_out , w0 , w1 , wordsize ) : <EOL> """<STR_LIT>""" <EOL> command = "<STR_LIT>" <EOL> if ( rnd % <NUM_LIT:2> ) == <NUM_LIT:0> : <EOL> rot_one = <NUM_LIT:5> <EOL> rot_two = <NUM_LIT:8> <EOL> else : <EOL> rot_one = <NUM_LIT:7> <EOL> rot_two = <NUM_LIT> <EOL> command += "<STR_LIT>" <EOL> command += stpcommands . getStringAdd ( v2_in , v3_in , v0_out , wordsize ) <EOL> command += "<STR_LIT>" <EOL> command += "<STR_LIT>" . format ( <EOL> v1_out , rotl ( v1_in , rot_one , wordsize ) , rotr ( v2_out , <NUM_LIT:16> , wordsize ) ) <EOL> command += "<STR_LIT>" <EOL> command += stpcommands . getStringAdd ( <EOL> v1_in , v0_in , rotr ( v2_out , <NUM_LIT:16> , wordsize ) , wordsize ) <EOL> command += "<STR_LIT>" <EOL> command += "<STR_LIT>" . format ( <EOL> v3_out , rotl ( v3_in , rot_two , wordsize ) , v0_out ) <EOL> command += "<STR_LIT>" . format ( w0 ) <EOL> command += stpcommands . getStringEq ( <EOL> v1_in , v0_in , rotr ( v2_out , <NUM_LIT:16> , wordsize ) ) <EOL> command += "<STR_LIT>" <EOL> command += "<STR_LIT>" . format ( w1 ) <EOL> command += stpcommands . getStringEq ( v2_in , v3_in , v0_out ) <EOL> command += "<STR_LIT>" <EOL> stp_file . write ( command ) <EOL> return </s>
