|
| 1 | +using SHA |
1 | 2 | @testset "padding/pkcs_1_v1_5" begin
|
2 | 3 | test_vector = Vector{UInt8}([1,2,3])
|
3 | 4 | Random.seed!(42)
|
|
35 | 36 | public_key)
|
36 | 37 | @test unpadded == test_vector
|
37 | 38 | end
|
| 39 | + |
| 40 | +@testset "emsa_pss_encode" begin |
| 41 | + Random.seed!(42) |
| 42 | + M = Vector{UInt8}([3,2,1]) |
| 43 | + sLen = 0 |
| 44 | + hLen = SHA.sha1(UInt8[]) |> length |
| 45 | + emBits = 8 * hLen + 8 * sLen + 9 |
| 46 | + padded = ToyPublicKeys.emsa_pss_encode(M, |
| 47 | + emBits; |
| 48 | + sLen=sLen, |
| 49 | + hash=SHA.sha1) |
| 50 | + @test padded == UInt8[0x00, 0x39, 0xa1, 0xb4, 0x56, 0x60, 0x17, 0xd8, 0x5f, 0xa1, 0x6e, 0xa9, 0xe8, 0xd1, 0xe6, 0x30, 0x5a, 0xbd, 0xa2, 0x75, 0xb9, 0xbc] |
| 51 | +end |
| 52 | + |
| 53 | +@testset "emsa_pss_verify" begin |
| 54 | + Random.seed!(42) |
| 55 | + M = Vector{UInt8}([3,2,1]) |
| 56 | + hLen = SHA.sha1(UInt8[]) |> length |
| 57 | + sLen = 0 |
| 58 | + emBits = 8 * hLen + 8 * sLen + 9 |
| 59 | + emLen = ceil(emBits/8) |> Integer |
| 60 | + EM = UInt8[0x00, 0x39, 0xa1, 0xb4, 0x56, 0x60, 0x17, 0xd8, 0x5f, 0xa1, 0x6e, 0xa9, 0xe8, 0xd1, 0xe6, 0x30, 0x5a, 0xbd, 0xa2, 0x75, 0xb9, 0xbc] |
| 61 | + consistent = ToyPublicKeys.emsa_pss_verify(M, |
| 62 | + EM, |
| 63 | + emBits; |
| 64 | + sLen=sLen, |
| 65 | + hash=SHA.sha1) |
| 66 | + @test consistent == true |
| 67 | +end |
| 68 | + |
| 69 | +@testset "emsa_pss_verify(emsa_pss_encode)" begin |
| 70 | + Random.seed!(42) |
| 71 | + M = Vector{UInt8}([3,2,1]) |
| 72 | + hLen = SHA.sha1(UInt8[]) |> length |
| 73 | + sLen = 0 |
| 74 | + emBits = 8 * hLen + 8 * sLen + 9 |
| 75 | + emLen = ceil(emBits/8) |> Integer |
| 76 | + EM = ToyPublicKeys.emsa_pss_encode(M, |
| 77 | + emBits; |
| 78 | + sLen = sLen, |
| 79 | + hash=SHA.sha1) |
| 80 | + consistent = ToyPublicKeys.emsa_pss_verify(M, |
| 81 | + EM, |
| 82 | + emBits; |
| 83 | + sLen=sLen, |
| 84 | + hash=SHA.sha1) |
| 85 | + @test consistent == true |
| 86 | +end |
0 commit comments