示例#1
0
def test_dpa_on_dpa_v2():

    ths = traces.read_ths_from_ets_file('tests/end_to_end/dpa_v2_sub.ets')
    expected_key = aes.key_schedule(key=ths[0].key)[-1]

    # One byte is not correctly retrieved with this configuration.
    expected_key[13] = 252

    sf = aes.selection_functions.encrypt.DeltaRLastRounds()
    container = scared.Container(ths)

    att = scared.DPAAttack(
        selection_function=sf,
        model=scared.Monobit(7),
        discriminant=scared.maxabs,
    )
    att.run(container)

    bit_list = range(0, 7)
    max_score = np.copy(att.scores)

    for b in bit_list:
        att = scared.DPAAttack(selection_function=sf,
                               model=scared.Monobit(b),
                               discriminant=scared.maxabs)
        att.run(container)
        max_score = np.maximum(max_score, att.scores)
    att.scores = max_score
    last_key = np.argmax(att.scores, axis=0)

    assert np.array_equal(expected_key, last_key)
示例#2
0
def test_nicv_on_dpa_v2():

    ths = traces.read_ths_from_ets_file('tests/end_to_end/dpa_v2_sub.ets')
    expected_key = aes.key_schedule(key=ths[0].key)[-1]
    sf = scared.selection_functions.aes.encrypt.delta_r_last_rounds()
    container = scared.Container(ths[:15000])
    att = scared.NICVAnalysis(
        selection_function=sf,
        model=scared.HammingWeight(),
        discriminant=scared.maxabs,
    )
    att.run(container)
    last_key = np.argmax(att.scores, axis=0)
    assert np.array_equal(expected_key, last_key)
示例#3
0
def test_snr_on_dpa_v2():

    ths = traces.read_ths_from_ets_file('tests/end_to_end/dpa_v2_sub.ets')
    expected_key = aes.key_schedule(key=ths[0].key)[-1]
    # SNR with this configuration doesn't retrieve the good value for the first byte of the key.
    expected_key[0] = 22
    sf = aes.selection_functions.encrypt.DeltaRLastRounds()
    container = scared.Container(ths[:15000])
    att = scared.SNRAttack(
        selection_function=sf,
        model=scared.HammingWeight(),
        discriminant=scared.maxabs,
    )
    att.run(container)
    last_key = np.argmax(att.scores, axis=0)
    assert np.array_equal(expected_key, last_key)