29 lines
819 B
Julia
Executable File
29 lines
819 B
Julia
Executable File
#!/usr/bin/env julia
|
|
|
|
include("util.jl")
|
|
include("sbox.jl")
|
|
include("plotutils.jl")
|
|
|
|
function parse_csv(filename)
|
|
println("Starting parsing")
|
|
data = CSV.read(filename, header=0)
|
|
println("Parsing done")
|
|
plaintexts::Matrix{UInt8} = convert(Matrix{UInt8}, data[:, 1:16])
|
|
timings::Matrix{UInt32} = convert(Matrix{UInt32}, data[:, 17:17])
|
|
return plaintexts, timings
|
|
end
|
|
|
|
function break_aes()
|
|
plaintexts, timings = parse_csv("timing.csv")
|
|
t_values = Vector{Float64}(undef, 0x100)
|
|
for key=0:0xFF
|
|
msb_set = (sbox[(plaintexts[:, 1] .⊻ key) .+ 1] .& 0x80) .!= 0
|
|
group_slow = timings[msb_set]
|
|
group_fast = timings[msb_set.==false]
|
|
t_values[key + 1] = t_val(group_fast, group_slow)
|
|
end
|
|
plot_discrete_tval(0:0xFF, t_values, "key")
|
|
end
|
|
|
|
@time break_aes()
|