File: test_sodium.R

package info (click to toggle)
r-cran-openssl 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: ansic: 3,074; sh: 20; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
context("Sodium Compatibility")

test_that("Signatures are compatible with sodium", {
  skip_if(fips_mode())
  skip_if_not(openssl_config()$x25519)

  # Generate keypair with sodium
  sk <- sodium::sig_keygen()
  pk <- sodium::sig_pubkey(sk)
  msg <- serialize(iris, NULL)

  # Parse in openssl
  key <- read_ed25519_key(sk)
  pubkey <- read_ed25519_pubkey(pk)

  # Create sodium signature
  sig1 <- sodium::sig_sign(msg, key = sk)
  expect_true(sodium::sig_verify(msg, sig1, pk))
  expect_true(ed25519_verify(msg, sig1, pubkey = pubkey))

  # Create openssl signature
  sig2 <- ed25519_sign(msg, key)
  expect_true(sodium::sig_verify(msg, sig2, pk))
  expect_true(ed25519_verify(msg, sig2, pubkey = pubkey))

})

test_that("Diffie Hellman is compatible with sodium", {
  skip_if(fips_mode())
  skip_if_not(openssl_config()$x25519)
  # Generate keypair with sodium
  sk1 <- sodium::keygen()
  sk2 <- sodium::keygen()
  dh1 <- sodium::diffie_hellman(sk1, sodium::pubkey(sk2))

  # Same in openssl
  key <- read_x25519_key(sk2)
  pubkey <- read_x25519_pubkey(sodium::pubkey(sk1))
  dh2 <- x25519_diffie_hellman(key, pubkey)
  expect_equal(dh1, dh2)
})