Confusion about 'value' and 'guess' in PA_CPA_4-Hardware_Crypto_Attack

Can anyone help me understand where ‘value’ and ‘guess’ parameters originate from in the function, ‘selection_with_guess’, in PA_CPA_4-Hardware_Crypto_Attack?

    # selection_with_guess function must take 2 arguments: value and guess
def selection_function_lastroundHD(byte):
  def selection_with_guess(value, guess):
          INVSHIFT_undo = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]
          st10 = value[INVSHIFT_undo[byte]]
          st9 = inv_sbox[value[byte] ^ guess]
          return hamming(st9 ^ st10)
      return selection_with_guess

In the context of this code, I’m unsure about the origins of ‘value’ and ‘guess’. It seems they are passed into the internal function ‘selection_with_guess’, but it’s unclear to me where they would be defined or passed in from the surrounding context. Any clarification on the matter would be appreciated. Thanks!


value is the plaintext/ciphertext (depending on which your attack uses), while guess is a guess for the key byte.


Thank you for the explanation. I understand the meanings of value and guess. However, what really confused me is that how these two variables, value and guess, are inputted into the selection_with_guess function. This function in nested within selection_function_lastroundHD and it’s unclear to me where and how these variables are introduced or passed into selection_with_guess. I could not find out the clue in this tutorial.