def patch_pySalsa20():

    class Testing_pysalsa20( pySalsa20.Salsa20 ):

        def salsa20core( self, input, nRounds ):
            """ Do nRounds Salsa20 rounds on input, a 64-byte string.
                Returns a 64-byte string.  SETS ROUNDS GLOBAL IN LIBSALSA20.
                """
            try:
                libSalsa20.set_rounds( nRounds )
            except:
                msg  = '*** Your libsalsa20 does not support the '  \
                     + 'set_rounds() function; some tests will fail ' \
                     + 'because of this.'
                print(msg)

            assert type( input ) == bytes, 'input must be byte string'
            assert len( input ) == 64, 'input must be 64-byte string'

            NUL_message = c_buffer( 64 ) # to be xored with hash output
            output = c_buffer( 64 )
            # Interpret each four input bytes as a little-endian word,
            # then repack as native-order words for the C routine:
            ctx = native16_i32.pack( *little16_i32.unpack( input ) )
            libSalsa20.ECRYPT_encrypt_bytes( ctx, NUL_message, output, 64 )
            return output.raw[:64]


        def force_nRounds( self, nRounds ):
            """ \
            Set # of rounds bypassing the "in [8,12,20]" check, for testing.
            """
            libSalsa20.set_rounds( nRounds )


    # Return the class:
    return Testing_pysalsa20
Define and return a testing version of pySalsa20's Salsa20 class.
dataset/ETHPy150Open zhansliu/writemdict/testSalsa20.py/patch_pySalsa20