Skip to content

Commit

Permalink
Add new tests and fix 2 of the existing ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpvgoncalves committed Sep 24, 2023
1 parent 285370e commit 7ae535f
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 2 deletions.
177 changes: 177 additions & 0 deletions tests/testthat/_snaps/key_write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Display sample key

Code
write_key(key, NULL)
Output
-----BEGIN PRIVATE KEY-----
MIIJpQIBADASBg4rBgEEAYOoeAWOQwEBAgUABIIJYAC3S+CnQiQksKYiYn9jshHE
kOk0P1com0rokhFaaVxFOaNRdOkSefRnPkxbbytZk20KrWmiWj51Q2bikOUKOsXR
fyPmZo76PfEjUe7DjwRIrLpAX2SFznx8a9wCUEBbTbW2MNl2JaPSSZwFTB6zRaCg
DWBLJZfcXo48FophFFybu5Ippp/EkXrxmjuVJXXEQOLHCLhmRAx7v1T6MCmLc3FK
ZPzck+hVP6P8Vhr4xtc3h0Acdm5sjxdVu8pHseDxLWUTDCJWFvG4jZ3ReDIZrk0J
HaZMBrujNyiRZMTKZafbeHeMJrchzqYwvaNylWrcWXfUZQxUufSCFNdaczdTlhYy
L9pUB/mJgekSMtUGiv62MVLXP1uqcY9EJ8DBlzmhl/vKq+ZRANsHkaL2bIdrMJwZ
J50cKhxUgZ2GYFd5FRbXL9fcjq7gRkwJzu9bG1CDhhM5XHWBVLQJd2wcSVDRBtzp
mxliNjJkkqrIoPSTMvNTq9jbWzjVlXAoS4dsdo7lhDBczmP6YO3MpRrIlDFxQUkj
hJLIoGq5WLeFNak1r1GFWoD2jGFie/aZGHipTifzbp3WanU1kstsb6xBt0PMNeej
Fs4mYrYihb3qNH1jO+cGCYPFwKUrVIMjqwv8JQawfFW2BnxggH0piFWAVo2Ikh9D
V0GqFPYbb2nbB9bBOzQ1iyvYO753ynFgwETzEQcMQdPbVCjIN15ixmS7eRQJHFvi
gzbKORAgIzvqsmzAziUDRYoHKqToxMrTLCunkRm1v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
tJij+8uTiklyCE9S0EPamYA1qa6QVqPRphSJIMPfVHUBAcgiG882q5gI+8o6kDkv
+nEN8bw/g8dj+sgLnGCSehOlZnCefLSHRIJ7a5cFeiHe0c8wY7W4i2J/9U3/Z6Ho
FYTdIiiC6GL5V6slyIJ3hcGEDHwdWHyD5GEQ8RZCQsj1cA+TIXmV4o+q68O+gygX
ph0j/ABfx5aU46axVgkUFIi8sXhL2Y+XdjCQpiJCaCy7unwu/GMtJTkDMpw7iRAK
VBvT8n81UwXi1c9sIrfk+gtoh4p94ScklDu2lRYZs8ctt8EjmmDZMIVPGybiGq/+
F8/o9x3jOU5YBK8idqVc7Fy4e3TWxVZqqyVQZwInOA78Bc1neUxjmkVgQmAZEyaP
VaZ3NqRNKxwiNjE1Khou1S5xKLDP5MgLiiWxIWTMfJEo8Bsg1UumJn+6uiVYQDvW
fGA1S4lXG4+06UTtvDZvTAXfwJ6VeH89qCLJd8Jz6KPrQnq96r71QYvzZSwtYZ4q
QA5k/JofjHeJslpk5Rz7u4UXF0NV9i4kFaFzKpDdtptfyHta5aCnCWQoRaMSQYBn
QMAoB3BNN1aqEa4Uu8rTxyYqK7cv+bkXnIQEQVBVwxm8rH6EiU4BimSxzAng23NY
MGA/mcYtkgsw0S2POFQGsBGk/M2E2iZtdoQ1dYJw6oTPhAjeZ4mr5c6b8Qz59yyD
kMW4MBna97GMCboFFW9Ohbo32QN1ZyRvhYz9cc5qSTicghPV+++pfZKnMT8zwI8A
DXfoT4V8v7kRk3X+QQ==
-----END PUBLIC KEY-----

6 changes: 6 additions & 0 deletions tests/testthat/test-decap_kyber.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ test_that("kyber-x decapsulation fails on wrong parameter", {
# Bad key
expect_error(decap_kyber(ss$encapsulation, "not_a_key"))

# wrong family
manipulated_key <- key
attr(manipulated_key$private, "algorithm") <- "1.3.6.1.4.1.54392.5.1859.0"
expect_error(decap_kyber(ss$encapsulation, manipulated_key$private))

invalid_key_algo <- keygen_dilithium()
expect_error(decap_kyber(ss$encapsulation, invalid_key_algo$private)) # invalid algorithm

# undefined algorithm, on the right 'family'
manipulated_key <- key
attr(manipulated_key$private, "algorithm") <- "1.3.6.1.4.1.54392.5.1859.1.1.99"
expect_error(decap_kyber(ss$encapsulation, manipulated_key$private))

# Bad encapsulation
bad_encapsulation <- as.integer(runif(768, 0, 256)) # wrong type, right size
expect_error(decap_kyber(bad_encapsulation, key$private))
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-encap_kyber.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ test_that("kyber-x encapsulation fails on wrong parameter", {
attr(manipulated_key$public, "algorithm") <- "1.3.6.1.4.1.54392.5.1859.0"
expect_error(encap_kyber(manipulated_key$public))

# undefined algorithm, on the right 'family'
manipulated_key <- key
attr(manipulated_key$public, "algorithm") <- "1.3.6.1.4.1.54392.5.1859.1.1.99"
expect_error(encap_kyber(manipulated_key$public))

invalid_key_algo <- keygen_dilithium()
expect_error(encap_kyber(invalid_key_algo$public)) # invalid algorithm
})
12 changes: 12 additions & 0 deletions tests/testthat/test-key_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,15 @@ test_that("Write Sphincs+ key-pair", {
expect_error(write_key("not_a_key", path))
expect_error(write_key(key, "not_a_path"))
})

test_that("Display sample key", {

key <- readRDS(test_path("testdata", "key"))

expect_snapshot({
write_key(key, NULL)
write_key(key$private, NULL)
write_key(key$public, NULL)
})

})
2 changes: 1 addition & 1 deletion tests/testthat/test-sign_dillitium.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ test_that("Dilithium digital signature fails on wrong parameters", {

small_key <- key$private[1:25]
class(small_key) <- "pqcrypto_private_key"
attr(small_key, "algorithm") <- "dilithium"
attr(small_key, "algorithm") <- "1.3.6.1.4.1.54392.5.1859.1.2.1"
expect_error(sign_dilithium(small_key, "text_message")) # c++ error
})
2 changes: 1 addition & 1 deletion tests/testthat/test-sign_sphincs.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,6 @@ test_that("Sphincs+ digital signature fails on wrong parameters", {

small_key <- key$private[1:25]
class(small_key) <- "pqcrypto_private_key"
attr(small_key, "algorithm") <- "sphincs+"
attr(small_key, "algorithm") <- "1.3.6.1.4.1.54392.5.1859.1.3.11"
expect_error(sign_sphincs(small_key, "text_message")) # wrong key size
})
6 changes: 6 additions & 0 deletions tests/testthat/test-verify_dilithium.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ test_that("Digital signatures verification fails with bad parameters", {

key <- keygen_kyber()
expect_error(verify_dilithium(important_message, signature, key$public)) # bad key algorithm

key <- keygen_sphincs()
expect_error(verify_dilithium(important_message, signature, key$public)) # bad key algorithm

key <- keygen_dilithium()
expect_error(verify_dilithium(important_message, signature, key$public)) # mismatching key
})
6 changes: 6 additions & 0 deletions tests/testthat/test-verify_sphincs.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,10 @@ test_that("Sphincs+ digital signatures verification fails with bad parameters",
key <- keygen_dilithium()
expect_error(verify_sphincs(important_message, signature, key$public)) # bad key algorithm

key <- keygen_kyber()
expect_error(verify_sphincs(important_message, signature, key$public)) # bad key algorithm

key <- keygen_sphincs()
expect_error(verify_sphincs(important_message, signature, key$public)) # mismatching key

})
Binary file added tests/testthat/testdata/key
Binary file not shown.

0 comments on commit 7ae535f

Please sign in to comment.