線形変換によるHE行列積

algorithm
2022-10-29

Secure Outsourced Matrix Computation and Application to Neural Networks の方法

3.2 Matrix Encoding

  • 長さ のベクトル に対して写像
    • 逆変換もできるよ
  • 線型変換

3.3.1 Tweaks of Permutations


  • (すべて )
    を用いて

写像に対応する定数行列

  • 写像 に対応する定数行列が

を用いて 線形変換 をする

3.3.2 Homomorphic Matrix Multiplication

アルゴリズム:行列積

function matmul1(a::Vector{Float64}, b::Vector{Float64}, d::Int64)::Vector{Float64}
  Uσ, Uτ = gen_U(d)
  as, bs = [lin_trans(a, Uσ)], [lin_trans(b, Uτ)]
 
  for k in 1:d - 1
    V_k, W_k = gen_VW(d, k)
    push!(as, lin_trans(as[1], V_k))
    push!(bs, lin_trans(bs[1], W_k))
  end
 
  ab = mul(as[1], bs[1])
  for k in 2:d
    ab = add(ab, mul(as[k], bs[k]))
  end
  ab
end

n=2

; 0 1  4 5    6  7
; 2 3  6 7 = 26 31
;  [0, 7, 18, 10] + [6, 0, 8, 21]
;= [6, 7, 26, 31]
; lin_trans: d^2, mult: d, add: d-1
(def cipher lintrans (args cipher m vector u)
    (rep + l $SLOTS
        (* (L m l) (ecd (diag u l)))
    )
(let a (enc (ecd (vec 0 1 2 3)))
(let b (enc (ecd (vec 4 5 6 7)))
; [0 1 2 3] [0 1 3 2] -> [0 1 3 2]
(let as0 (app lintrans a (vec 0 1 3 2))
; [4 5 6 7] [0 3 2 1] -> [4 7 6 5]
(let bs0 (app lintrans b (vec 0 3 2 1))
; [0 1 3 2] [1 0 3 2] -> [1 0 2 3]
(let as1 (app lintrans as0 (vec 1 0 3 2))
; [4 7 6 5] [2 3 0 1] -> [6 5 4 7]
(let bs1 (app lintrans bs0 (vec 2 3 0 1))
; [0 7 18 10] + [6 0 8 21] = [6 7 26 31]
(+ (* as0 bs0) (* as1 bs1))
))))))))
; 0 1  4 5    6  7
; 2 3  6 7 = 26 31
 
; Uσ =
; 1 0 0 0
; 0 1 0 0
; 0 0 0 1
; 0 0 1 0
(let as0 (lintrans (0 1 3 2) a)) ; [0 1 3 2]
 
; Uτ =
; 1 0 0 0
; 0 0 0 1
; 0 0 1 0
; 0 1 0 0
(let bs0 (lintrans (0 3 2 1) b)) ; [4 7 6 5]
 
; V_k =
; 0 1 0 0
; 1 0 0 0
; 0 0 0 1
; 0 0 1 0
(let as1 (lintrans (1 0 3 2) as0)) ; [1 0 2 3]
 
; W_k =
; 0 0 1 0
; 0 0 0 1
; 1 0 0 0
; 0 1 0 0
(let bs1 (lintrans (2 3 0 1) bs0)) ; [6 5 4 7]
 
(+ (* as0 bs0) (* as1 bs1))
;  [0, 7, 18, 10] + [6, 0, 8, 21]
;= [6, 7, 26, 31]
; lin_trans: d^2, mult: d, add: d-1