File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,27 @@ 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
+ length (S) != k && error (" invalid signature" ) |> throw
204
+ s = OS2IP (S)
205
+ m = RSAVP1 (pkcs1_v1_5, s, key)
206
+ modBits = Base. GMP. MPZ. sizeinbase (key. modulus, 2 )
207
+ emLen = ceil ((modBits - 1 )/ 8 ) |> Integer
208
+ EM = I2OSP (m, emLen)
209
+ result = emsa_pss_verify (M, EM, modBits - 1 )
210
+ return result
211
+ end
212
+
192
213
"""
193
214
encrypt(::pkcs1_v1_5_t,
194
215
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