File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,26 @@ 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
+ S = I2OSP (s, key)
198
+ return S
199
+ end
200
+
201
+ function rsassa_pss_verify (M:: Vector{UInt8} , S:: Vector{UInt8} , key:: RSAPublicKey )
202
+ length (S) != k && error (" invalid signature" ) |> throw
203
+ s = OS2IP (S)
204
+ m = RSAVP1 (pkcs1_v1_5, s, key)
205
+ modBits = Base. GMP. MPZ. sizeinbase (key. modulus, 2 )
206
+ emLen = ceil ((modBits - 1 )/ 8 ) |> Integer
207
+ EM = I2OSP (m, emLen)
208
+ result = emsa_pss_verify (M, EM, modBits - 1 )
209
+ return result
210
+ end
211
+
192
212
"""
193
213
encrypt(::pkcs1_v1_5_t,
194
214
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
+ msg = Vector {UInt8} (" 123" )
134
+ signature = ToyPublicKeys. rsassa_pss_sign (msg, private_key)
135
+ valid = ToyPublicKeys. rsassa_pss_verify (C, public_key)
136
+ @test valid == true
137
+ end
You can’t perform that action at this time.
0 commit comments