File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,28 @@ function rsaes_pkvs1_v1_5_decrypt(C::String, key::RSAPrivateKey)
189
189
return m
190
190
end
191
191
192
+ function rsassa_pss_sign (M:: Vector{UInt8} , key:: RSAPrivateKey )
193
+ modBits = Base. GMP. MPZ. sizeinbase (key. modulus, 2 )
194
+ EM = emsa_pss_encode (M, modBits - 1 )
195
+ m = OS2IP (EM)
196
+ s = RSASP1 (pkcs1_v1_5, m, key)
197
+ k = (modBits/ 8 ) |> ceil |> Integer
198
+ S = I2OSP (s, k)
199
+ return S
200
+ end
201
+
202
+ function rsassa_pss_verify (M:: Vector{UInt8} , S:: Vector{UInt8} , key:: RSAPublicKey )
203
+ modBits = Base. GMP. MPZ. sizeinbase (key. modulus, 2 )
204
+ k = (modBits/ 8 ) |> ceil |> Integer
205
+ length (S) != k && error (" invalid signature" ) |> throw
206
+ s = OS2IP (S)
207
+ m = RSAVP1 (pkcs1_v1_5, s, key)
208
+ emLen = ceil ((modBits - 1 )/ 8 ) |> Integer
209
+ EM = I2OSP (m, emLen)
210
+ result = emsa_pss_verify (M, EM, modBits - 1 )
211
+ return result
212
+ end
213
+
192
214
"""
193
215
encrypt(::pkcs1_v1_5_t,
194
216
msg::Union{AbstractString,AbstractVector},
Original file line number Diff line number Diff line change 126
126
ret = ToyPublicKeys. rsaes_oaep_decrypt (C, private_key)
127
127
@test ret == msg
128
128
end
129
+
130
+ @testset " rsassa_pss_verify(rsassa_pss_sign) is true" begin
131
+ Random. seed! (42 )
132
+ private_key, public_key = ToyPublicKeys. generate_rsa_key_pair (ToyPublicKeys. pkcs1_v1_5, 2048 )
133
+ M = Vector {UInt8} (" 123" )
134
+ S = ToyPublicKeys. rsassa_pss_sign (M, private_key)
135
+ valid = ToyPublicKeys. rsassa_pss_verify (M, S, public_key)
136
+ @test valid == true
137
+ end
You can’t perform that action at this time.
0 commit comments