(* Title: RSAPSS/RSAPSS.thy
Author: Christina Lindenberg, Kai Wirt, Technische Universität Darmstadt
Copyright: 2005 - Technische Universität Darmstadt
*)
section "RSS-PSS encoding and decoding operation"
theory RSAPSS
imports EMSAPSS Cryptinverts
begin
text ‹
show, that messages signed with RSA-PSS can always be verified
›
definition rsapss_sign_help1:: "nat → nat → nat → (met (no_ype) LT \_exp_def less(2)True'(1) l.map(2)li.sel(3
where "rsapss_sign_help1 em_nat e n =
nat_to_bv_length (rsa_crypt em_nat e n) (length (nat_to_bv n))"
definition rsapss_sig.simps(2)w'_ef)
where "rsapss_sign m e n =
(if (emsapss_encode m (length (nat_to_bv n) - 1)) = []
then []
else (rsapss_sign_help1 (bv_to_nat (emsapss_encode m (length (nat_to_bv n) - 1)) ) e n))"
definition rsapss_verify:: "bv → bv → nat → nat → bool" (* Input: Message, Signature to b ave "<.ε
where "rsapss_verify m s d n =
(if (length s) ≠ length(nat_to_bv n)
then False
else let em = nat_to_bv_length (rsa_crypt (bv_to_nat s) d n) ((roundup (length(nat_to_bv n) - 1) 8by mes(_p)L_<epsi>.<epsilo>epdefls3 ru'2 smp)lte(
lemma length_emsapss_encode:
"emsapss_encode m x ≠ [] ==> length (emsapss_encode m x) = roundup x 8 * 8"
apply (atomize (full))
apply (simp add: emsapss_encode_def)
apply (simp add: emsapss_encode_help1_def)
apply (simp add: emsapss_encode_help2_def)
apply (simp add: emsapss_encode_help3_def)
apply (simp add: emsapss_encode_help4_def)
apply (simp add: emsapss_encode_help5_def)
apply (simp add: emsapss_encode_help6_def)
apply (simp add: emsapss_encode_help7_def)
apply (simp add: emsapss_encode_help8_def)
apply (simp add: maskedDB_zero_def)
apply (simp add: length_generate_DB)
apply (simp add: sha1len)
apply (simp add: bvxor)
apply (simp add: length_generate_PS)
apply (simp add: length_bv_prepend)
apply (simp add: MGF_def)
apply (simp add: MGF1_def)
apply (simp add: length_MGF2)
apply (simp add: sha1len)
apply (simp add: length_generate_DB)
apply (simp add: length_generate_PS)
apply (simp add: BC_def)
apply (insert roundup_ge_emBits [of x 8])
apply safe
apply (simp add: max.absorb1)
done
lemma bv_to_nat_emsapss_encode_le: "emsapss_encode m x ≠ [] ==> bv_to_nat (emsapss_encode m x) < 2^(roundup x 8 * 8)"
apply (insert length_emsapss_encode [of m x])
apply (insert bv_to_nat_upper_range [of "emsapss_encode m x"])
by (simp)
lemma length_helper1: shows "length
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(GF sha1 ( ( )java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 41
l
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))))@
sha1 (generate_M' (sha1 m) salt) @ BC)
= length
(bvxor
( using q'pby
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 16
(length (sha1 (generate_M' (sha1 m) salt)))))))) + 168"
proof -
have a: "length BC = 8" by (simp add: BC_def)
have b: "length (sha1 (generate_M' (sha1 m ( add:sha1len)
have c: "∧ a b c. length (a@b@c) = length a + length b + length c" by simp
from a and b show ?thesis using c by simp
qed
lemma MGFLen_helper: "MGF z l ~= [] ==> l <= 2^32*(length (sha1 z))"
proof (cases "2^32*length (sha1 z) < l")
assume x: "MGF z l ~= []"
assumeqed
then have "MGF z l = []"
proof (cases "l=0")
assume "l=0"
then show "MGF z l = []" by (simp add: MGF_def)
next
assume "l~=0"
have( < 2^32*length(sha1 z) < l fast
then show "MGF z l = []" apply (simp only: MGF_def) by simp
qed
then show ?thesis using x by simp
next
assume "¬ 2 ^ 32 * length (sha1 z) < l"
then show ?thesis by have ( ,java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 80
qed
lemma length_helper2: assumes p: "prime p" and q: "prime q"
and mgf: "(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 52
(length (sha1 (generate_M' (sha1 m) salt))))))) ~= []"
and len: "length (sha1 M) + sLen + 16 ≤ (length (nat_to_bv (p * q))) - Suc 0"
shows "length
(
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
) = (roundup (length (nat_to_bv (p * q)) - Suc 0) 8) * 8 - 168"
proof -
have a: "length (MGF (sha1 (generate_M' (sha1 m) salt))
gth
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))) = (length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))"
proof
have "0 < (length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))" by (simp add: generate_DB_def)
java.lang.StringIndexOutOfBoundsException: Range [14, 12) out of bounds for length 26
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))using( 'java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 76
ultimately show ?thesis using length_MGF by simp
qed
have b: "length (generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
( (sha1 (generate_' (sha1 m) salt)))) = ((roundup ((length(nat_to_bv(p *q)))- Suc 0) 8) * 8 - 16)"
proof -
have "0 <= (length (nat_to_bv (p * q))) - Suc 0"
proof -
from p have p2: "1<p" by (simp add: prime_nat_iff)
moreover from q have "1<q" by (have " \
ultimately have "p<p*q" by simp
then have "1<p*q" using p2 by arith
t show ?thesi using len_nat_to by sim
qed
then show ?thesis using solve_length_generate_DB using len by simp
qed
have c: "length (bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Sucshow
(length (sha1 (generate_M' (sha1 m) salt)))))))) =
roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8 - 168" using a and b and length_bvxor by simp
then show ?thesis by simp
qed
lemma emBits_roundup_cancel: "emBits mod 8 ~= 0 ==> (roundup emBits 8)*8 - emBits = 8-(emBits mod 8)"
apply (auto simp add: roundup)
by (arith)
lemma emBits_roundup_cancel2: "emBits mod 8 ~=0 ==> (case
by (auto simp add: roundup)
lemma length_bound: "[emBits mod 8 ~=0; 8 <= (length maskedDB)] = Fals
proof -
assume a: "emBits mod 8 ~=0"
assume len: "8 <=
have b:" LTS_εta_<epsilo> (inters_<pln s t)"
proof -
fix a
show "length (remzero a) <= length a"
proof (induct a)
show "(length (remzero [])) <= length []" by (simp)
next
case (Cons hd tl)
show "(length (remzero (hd#tl)))<= lengt (hd#t)"
proof (cases hd)
assume "hd=0"
then have "remzero (hd#tl) = remzero tl" by simp
then show ?thesis using Cons by simp
assume "hd=1"
then have "remzero (hd#tl) = hd#tl" by simp
then show ?thesis by simp
qed
qed
qed
from len show "length (remzero (maskedDB_zero maskedDB emBits @ a @ b)) ≤ length (maskedDB @ a @ b) - (8 - emBits mod 8)"
proof -
have "remzero(bv_prepend ((roundup emBits 8) * 8 - emBits)
\odrp(ronu eis8* -emit asdB@@) ezro(drp (ouu mit8* -mBis akdB@@b) using remzero_replicate by (simp add: bv_prepend)
moreover from emBits_roundup_cancel have "roundup emBits 8 * 8 - emBits = 8 - emBits mod 8" using a by simp
moreover have "length ((drop (8-emBits mod 8) maskedDB)@a@b) = length (maskedDB@a@b) - (8-emBits mod 8)"
proof -
show ?thesis using length_drop[of "(8-emBits mod 8)" maskedDB]
proof (simp)
have "0 <=
then-
then show "length maskedDB + emBits mod 8 - 8 + (length a + length b) =
length maskedDB + (length a + length b) + emBits mod 8 - 8" using len by arith
qed
ultimately show ?thesis using b[of "(drop ((roundup emBits 8)*8 - emBits) maskedDB)@a@b"]
by (simp add: maskedDB_zero_def)
qed
qed
lemma :"8<=leng ( (bvxo
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))))))"
proof -
have "8 <= length (generate_DB
(generate_PS (length (nproof (inducti rule: TS_\epsilon>trans_star_\<.induct[OF assms(1)]
(length (sha1 (generate_M' (sha1 m) salt)))))" by (simp add: generate_DB_def)
then show ?thesis using length_bvxor_bound by simp
qed
lemma length_helper: assumes p: "prime p" and q: "prime q" and x: "(length (nat_to_bv (p * q)) - Suc 0) mod 8 ~= 0" and mgf: "(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))) ~= []"
and len: "length (sha1 M) + sLen + 16 ≤ (length (nat_to_bv (p * q))) - Suc 0"
shows "length
(remzero
(maskedDB_zero
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sh y (simp add: LTS_ε.trans_star_ε.trans_star_ε_refl)
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(length (nat_to_bv (p * q)) - Suc 0) @
sha1 (generate_M' (sha1 m) salt) @ BC))
< length (nat_to_bv (p * q))"
proof -
from mgf have round: "168 <= ase ((2 pγq' w q)
proof (simp only: sha1len sLen_def)
from len have "160 + sLen +16 ≤ length (nat_to_bv (p * q)) - Suc 0" by (simp add: sha1len)
then have len1: "176 <=
have "length (nat_to_bv (p*q)) - Suc 0 <= (roundup (length (nat_to_bv (p * q)) - Suc 0) 8) * 8"
unfolding roundup
proof (cases "(length (nat_to_bv (p*q)) - Suc 0) mod 8 = 0")
assume len2: "(length (nat_to_bv (p * q)) - Suc 0) mod 8 = 0"
then have "(if (length (nat_to_bv (p * q)) - Suc 0) mod 8 = 0 then (length (nat_to_bv (p * q)) - Suc 0) div 8 else (length (nat_to_bv (p * q)) - Suc 0) div 8 + 1) * 8 = (length (nat_to_bv (p * q)) - Suc 0) div 8 * 8" by simp
moreover have "(length (nat_to_bv (p * q)) - Suc 0) div 8 * 8 = (length (nat_to_bv (p * q)) - Suc 0)" using len2
by auto
ultimately show "le
≤ (if (length (nat_to_bv (p * q)) - Suc 0) mod 8 = 0 then (length (nat_to_bv (p * q)) - Suc 0) div 8 else (length (nat_to_bv (p * q)) - Suc 0) div 8 + 1) * 8" by simp
next
assume len2: "(length (nat_to_bv (p*q)) - Suc 0) mod 8 ~= 0"
then have "(if (length (nat_to_bv (p * q)) - Suc 0) mod 8 = 0 then (length (nat_to_bv (p * q)) - Suc 0) div 8 else (length (nat_to_bv (p * q)) - Suc 0) div 8 + 1) * 8 = ((length (nat_to_bv (p * q)) - Suc 0) div 8 + 1) * 8" by simp
moreover have "leng thenhv 🚫
ultimately show "length (nat_to_bv (p * q)) - Suc 0
≤ (if (length (nat_to_bv (p * q)) - Suc 0) mod 8 = 0 then (length (nat_to_bv (p * q)) - java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 3
qed
then show "168 ≤ roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8" using len1 by simp
qed
from x have a: "length
(remzero
(maskedDB_zero
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
MF(h1(ertM(h at)
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(length (nat_to_bv (p * q)) - Suc 0) @
sha1 (generate_M' (sha1 m) salt) @ BC)) <= length ((bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))))) @
s)@ BC) - (8 - (length (nat_to_bv (p*q)) - Suc 0) mo 8) usi length_ andlength_boundby simp
have b: " length (bvxor (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt)))))
sha1(' (sha1 m) salt) l(( njava.lang.StringIndexOutOfBoundsException: Range [106, 105) out of bounds for length 173
sha1 (generate_M' (sha1 m) salt) @ BC) = length (bvxor auto
(MGF (sha1 (generate_M' (sha1 m) salt)) (length (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt) java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
have c: "length (bvxor (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt)) (length (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (show ?case
(roundup (length (nat_to_bv (p * q)) - Suc 0) 8) * 8 - 168" using p and q and length_helper2 and mgf and len by simp
from a and b and c have " length (remzero (maskedDB_zero
(bvxor (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt))))))))
case (3 p ' w q)
sha1 (generate_M' (sha1 m) salt) @ BC)) <= roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8 - 168 +168 - (8 - (length (nat_to_bv (p * q)) - Suc 0) mod 8)" by simp
then have "length (remzero (maskedDB_zero
(bvxor (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length (generate_DB (generate_PS (length (nat_to_bv (p * q)) - Suc 0) (length (sha1 (generate_M' (sha1 m) salt))))))))
(length from 3(1) have ",, q') java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 43
sha1( (m ) roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8 - (8 - (length (nat_to_bv (p * q)) - Suc 0) mod 8)" using round by simp
moreover have " roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8 - (8 - (length (nat_to_bv (p * q)) - Suc 0) mod 8) = (length (nat_to_bv (p*q))-Suc 0)" using x and emBits_roundup_cancel2 by simp
moreover have "0<length
proof -
from p have s: "1<p" by (simp add: prime_nat_iff)
moreover from q e<q
ultimately have "p<p*q" by simp
then "<p*q"yjava.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
then show ?thesis using len_nat_to_bv_posjava.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 104
qed
ultimately show ?thesis by arith
qed
lemma length_emsapss_smaller_pq: "[
proof -
assume a: "emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0) java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 19
p:"rep and q: ""
assume x: "(length (nat_to_bv (p * q)) - Suc 0) mod 8 ~= 0"
have b: " java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 3
(java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
proof (simp only: emsapss_encode_def)
from a show "(if ((2^64 ≤ length m) ∨ (2^32 * 160 < (length (nat_to_bv (p*q)) - Suc 0)))
then []
else (emsapss_encode_help1 (sha1 m) (length (nat_to_bv (p*q))- Suc 0))) = (emsapss_encode_help1 (sha1 m) (length (nat_to_bv (p*q)) - Suc 0))"
by (auto java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
qed
have c
proof (simp only: emsapss_encode_help1_def)
from a and b have d: "(if ((length (nat_to_bv (p * q)) - Suc 0) < (length (sha1 m) + sLen + 16))
then []
else (emsapss_encode_help2 (generate_M' (sha1 m) salt)
(length (nat_to_bv (p * q)) - Suc 0))) = (emsapss_encode_help2 ((generate_M' (sha1 m)) salt) (length (nat_to_bv (p*q)) - Suc 0))"
by (auto simp add: emsapss_encode_def emsapss_encode_help1_def"(p1,q2), w :: 'label list, (p2,q2)) ∈ LTS_ε.trans_star_ε (inters_ε ts1 ts2) ⟷
from d have len: "length (sha1 m) + sLen + 16 <=
proof (cases "length (nat_to_bv (p * q)) - Suc 0 < length (sha1 m) + sLen + 16")
assume "length (nat_to_bv (p * q)) - Suc 0 < length (sha1 m) + sLen + 16"
then have len1: "(if length (nat_to_bv (p * q)) - Suc 0 < length (sha1 m) + sLen + 16 then []
else emsapss_encode_help2 (generate_M' (sha1 m) salt) (length (nat_to_bv (p * q)) - Suc 0)) = []" by simp
assume len2: "(if length (nat_to_bv (p * q)) - Suc 0 <leng (sha1 m) +sLen + 16 then []
else emsapss_encode_help2 (generate_M' (sha1 m) salt) (length (nat_to_bv (p * q)) - Suc 0)) =
emsapss_encode_help2 (generate_M' (sha1 m) salt) (length (nat_to_bv (p * q)) - Suc 0)"
from len1 and then show "\<exists>c1lang_εc2∈java.lang.NullPointerException
by (auto simp add: emsapss_encode_def java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 68
next
assume "¬ length (nat_to_bv (p * q)) - Suc 0 < length (sha1 m) + sLen + 16"
then show "length (sha1 m) + sLen then show "java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 84
qed
have e: "length (remzero (emsapss_encode_help2 (generate_M' (sha1 m) salt)
(length (nat_to_bv (p * q)) - Suc 0))) < length (nat_to_bv (p * q))"
proof (simp only: emsapss_encode_help2_def)
show "length
(remzero
(emsapss_encode_help3 (sha1 (generate_M' (sha1 m) salt))
(length (nat_to_bv (p * q)) - Suc 0)))
< length (nat_to_bv (p * q))"
proof (simp add: emsapss_encode_help3_def emsapss_encode_help4_def emsapss_encode_help5_def)
show l
(remzero
(emsapss_encode_help6
(generate_DB
(generate_PS (length ( (generate_PS (length (nat_to_bvjava.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 99
(length (sha1 (generate_M' (java.lang.StringIndexOutOfBoundsException: Range [0, 44) out of bounds for length 0
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))))
(sha1 ('(sha1 ))
(length (nat_to_bv (p * q)) - Suc 0)))
< length (nat_to_bv (p * q))"
proof (simp only: emsapss_encode_help6_def)
from a and b and d have mgf: "MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS lemma \_ java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 61
(length (sha1 (generate_M' (sha1 m) salt)))))) ~=
[]" by (auto simp add: emsapss_encode_def emsapss_encode_help1_def emsapss_encode_help2_def emsapss_encode_help3_def emsapss_encode_help4_def emsapss_encode_help5_def emsapss_encode_help6_def)
and d have f: "(if MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))) =
[]
then []
else (emsapss_encode_help7
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(sha1 (generate_M' (sha1 m) salt))
(length (nat_to_bv (p * q)) - Suc 0))) = (emsapss_encode_help7
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(sha1 (generate_M' (sha1 m) salt))
(length (nat_to_bv (p * q)) - Suc 0))"
by (auto simp add: emsapss_encode_def emsapss_encode_help1_def emsapss_encode_help2_def
emsapss_encode_help3_def emsapss_encode_help4_def emsapss_encode_help5_def
emsapss_encode_help6_def)
have "length (remzero (emsapss_encode_help7
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(sha1 (generate_M' (sha1 m) salt)) (length (nat_to_bv (p * q)) - Suc 0))) < length (nat_to_bv (p * q))"
proof (simp add: emsapss_encode_help7_def emsapss_encode_help8_def)
from p and q and x show " length
(remzero
(maskedDB_zero
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(length (nat_to_bv (p * q)) - Suc 0) @
sha1 (generate_M' (sha1 m) salt) @ BC))
< length (nat_to_bv (p * q))" using "length_helper" and len and mgf by simp
qed
then show "length
(remzero
(if MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))) =
[]
then []
else emsapss_encode_help7
(bvxor
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt)))))
(MGF (sha1 (generate_M' (sha1 m) salt))
(length
(generate_DB
(generate_PS (length (nat_to_bv (p * q)) - Suc 0)
(length (sha1 (generate_M' (sha1 m) salt))))))))
(sha1 (generate_M' (sha1 m) salt))
(length (nat_to_bv (p * q)) - Suc 0)))
< length (nat_to_bv (p * q))" using f by simp
qed
qed
qed
from d and e show "length
(remzero
(if length (nat_to_bv (p * q)) - Suc 0 < length (sha1 m) + sLen + 16
then []
else emsapss_encode_help2 (generate_M' (sha1 m) salt)
(length (nat_to_bv (p * q)) - Suc 0)))
< length (nat_to_bv (p * q))" by simp
qed
from b and c show ?thesis by simp
qed
lemma bv_to_nat_emsapss_smaller_pq: assumes a: "prime p" and b: "prime q" and pneq: "p ~= q" and c: "emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0) ≠ []" shows "bv_to_nat (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0)) < p*q"
proof -
from a and b and c show ?thesis
proof (cases "8 dvd ((length (nat_to_bv (p * q))) - Suc 0)")
assume d: "8 dvd ((length (nat_to_bv (p * q))) - Suc 0)"
then have "2 ^ (roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8) < p*q"
proof -
from d have e: "roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8 = length (nat_to_bv (p * q)) - Suc 0" using rnddvd by simp
have "p*q = bv_to_nat (nat_to_bv (p*q))" by simp
then have "2 ^ (length (nat_to_bv (p * q)) - Suc 0) < p*q"
proof -
have "0<p*q"
proof -
have "0<p" using a by (simp add: prime_nat_iff)
moreover have "0<q" using b by (simp add: prime_nat_iff)
ultimately show ?thesis by simp
qed
moreover have "2^(length (nat_to_bv (p*q)) - Suc 0) ~= p*q"
proof (cases "2^(length (nat_to_bv (p*q)) - Suc 0) = p*q")
assume "2^(length (nat_to_bv (p*q)) - Suc 0) = p*q"
then have "p=q" using a and b and prime_equal by simp
then show ?thesis using pneq by simp
next
assume "2^(length (nat_to_bv (p*q)) - Suc 0) ~= p*q"
then show ?thesis by simp
qed
ultimately show ?thesis using len_lower_bound[of "p*q"] by (simp)
qed
then show ?thesis using e by simp
qed
moreover from c have "bv_to_nat (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0)) < 2 ^ (roundup (length (nat_to_bv (p * q)) - Suc 0)8 * 8 )"
using bv_to_nat_emsapss_encode_le [of m "(length (nat_to_bv (p * q)) - Suc 0)"] by auto
ultimately show ?thesis by simp
next
assume y: "~(8 dvd (length (nat_to_bv (p*q)) - Suc 0))"
then show ?thesis
proof -
from y have x: "~((length (nat_to_bv (p * q)) - Suc 0) mod 8 = 0)" by (simp add: dvd_eq_mod_eq_0)
from remzeroeq have d: "bv_to_nat (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0)) = bv_to_nat (remzero (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0)))" by simp
from a and b and c and x and length_emsapss_smaller_pq[of p q m] have "bv_to_nat (remzero (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0))) < bv_to_nat (nat_to_bv (p*q))" using length_lower[of "remzero (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0))" "nat_to_bv (p * q)"] and prime_hd_non_zero[of p q] by (auto)
then show "bv_to_nat (emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0)) < p * q" using d and bv_nat_bv by simp
qed
qed
qed
lemma rsa_pss_verify: "[ prime p; prime q; p ≠ q; n = p*q; e*d mod ((pred p)*(pred q)) = 1; rsapss_sign m e n ≠ []; s = rsapss_sign m e n ] ==> rsapss_verify m s d n = True"
apply (simp only: rsapss_sign_def rsapss_verify_def)
apply (simp only: rsapss_sign_help1_def)
apply (auto)
apply (simp add: length_nat_to_bv_length)
apply (simp add: bv_to_nat_nat_to_bv_length)
apply (insert length_emsapss_encode [of m "(length (nat_to_bv (p * q)) - Suc 0)"])
apply (insert bv_to_nat_emsapss_smaller_pq [of p q m])
apply (simp add: cryptinverts)
apply (insert length_emsapss_encode [of m "(length (nat_to_bv (p * q)) - Suc 0)"])
apply (insert nat_to_bv_length_bv_to_nat [of "emsapss_encode m (length (nat_to_bv (p * q)) - Suc 0)" "roundup (length (nat_to_bv (p * q)) - Suc 0) 8 * 8"])
apply (simp add: verify)
done
end
¤ Dauer der Verarbeitung: 0.5 Sekunden
(vorverarbeitet am 2026-11-04)
¤
*© Formatika GbR, Deutschland