simple-crypto / SCALib

Side-Channel Analysis Library
GNU Affero General Public License v3.0
74 stars 19 forks source link

NOT Factors do not work on Public Variables #140

Closed F-Lehmann closed 3 months ago

F-Lehmann commented 9 months ago

Describe the bug When having a property 'not_A = !A' and A is a PUBLIC the resulting not_A is always equal to NC-1

To Reproduce

import numpy as np
import scalib.attacks 

nc = 2
fg = scalib.attacks.FactorGraph(f'''
NC {nc}
PUB SINGLE A
VAR SINGLE NOT_A
PROPERTY NOT_A = !A
''')

A = 1
bp = scalib.attacks.BPState(fg,1,public_values={'A':A})
bp.bp_acyclic('NOT_A')
result = bp.get_distribution('NOT_A')
print(result)
assert(np.argmax(result) == ~A)

Observed behavior

[0. 1.]

and AssertionError as the result is wrong

Expected behavior [1. 0.] is the correct negation of 1 if Pbulics are respected

Environment (please complete the following information):

Additional context Applys for any choice of NC