break script: Print key
This commit is contained in:
@@ -1,28 +1,33 @@
|
|||||||
#!/usr/bin/env julia
|
#!/usr/bin/env julia
|
||||||
|
|
||||||
include("util.jl")
|
include("util.jl")
|
||||||
include("sbox.jl")
|
#include("sbox.jl")
|
||||||
include("plotutils.jl")
|
include("plotutils.jl")
|
||||||
|
|
||||||
|
import CSV
|
||||||
|
using Formatting
|
||||||
|
|
||||||
function parse_csv(filename)
|
function parse_csv(filename)
|
||||||
println("Starting parsing")
|
|
||||||
data = CSV.read(filename, header=0)
|
data = CSV.read(filename, header=0)
|
||||||
println("Parsing done")
|
plaintexts::Matrix{UInt8} = convert(Matrix{UInt8}, data[:, 1:16])#[1:50, :]
|
||||||
plaintexts::Matrix{UInt8} = convert(Matrix{UInt8}, data[:, 1:16])
|
timings::Matrix{UInt32} = convert(Matrix{UInt32}, data[:, 17:17])#[1:50]
|
||||||
timings::Matrix{UInt32} = convert(Matrix{UInt32}, data[:, 17:17])
|
|
||||||
return plaintexts, timings
|
return plaintexts, timings
|
||||||
end
|
end
|
||||||
|
|
||||||
function break_aes()
|
function break_aes()
|
||||||
plaintexts, timings = parse_csv("timing.csv")
|
plaintexts, timings = parse_csv("timing.csv")
|
||||||
t_values = Vector{Float64}(undef, 0x100)
|
t_values = Vector{Float64}(undef, 0x100)
|
||||||
|
for keybyte=1:16
|
||||||
for key=0:0xFF
|
for key=0:0xFF
|
||||||
msb_set = (sbox[(plaintexts[:, 1] .⊻ key) .+ 1] .& 0x80) .!= 0
|
msb_set = (sbox[(plaintexts[:, keybyte] .⊻ key) .+ 1] .& 0x80) .!= 0
|
||||||
group_slow = timings[msb_set]
|
group_slow = timings[msb_set]
|
||||||
group_fast = timings[msb_set.==false]
|
group_fast = timings[msb_set.==false]
|
||||||
t_values[key + 1] = t_val(group_fast, group_slow)
|
t_values[key + 1] = t_val(group_fast, group_slow)
|
||||||
end
|
end
|
||||||
|
print(format("{:02x} ", argmax(t_values) - 1))
|
||||||
|
end
|
||||||
|
println()
|
||||||
plot_discrete_tval(0:0xFF, t_values, "key")
|
plot_discrete_tval(0:0xFF, t_values, "key")
|
||||||
end
|
end
|
||||||
|
|
||||||
@time break_aes()
|
break_aes()
|
||||||
|
|||||||
Reference in New Issue
Block a user