newhope_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // newhope_test.go - NewHope Integration tests.
  2. //
  3. // To the extent possible under law, Yawning Angel has waived all copyright
  4. // and related or neighboring rights to newhope, using the Creative
  5. // Commons "CC0" public domain dedication. See LICENSE or
  6. // <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
  7. package newhope
  8. import (
  9. "bytes"
  10. "crypto/rand"
  11. "testing"
  12. )
  13. func testIntegration(t *testing.T) {
  14. for i := 0; i < 1024; i++ {
  15. // Generate Alice's key's.
  16. alicePriv, alicePub, err := GenerateKeyPairAlice(rand.Reader)
  17. if err != nil {
  18. t.Fatalf("GenerateKeyPairAlice failed: %v", err)
  19. }
  20. // Finish Bob's handshake.
  21. bobPub, bobShared, err := KeyExchangeBob(rand.Reader, alicePub)
  22. if err != nil {
  23. t.Fatalf("KeyExchangeBob failed: %v", err)
  24. }
  25. // Finish Alice's handshake.
  26. aliceShared, err := KeyExchangeAlice(bobPub, alicePriv)
  27. if err != nil {
  28. t.Fatalf("KeyExchangeAlice failed: %v", err)
  29. }
  30. if !bytes.Equal(aliceShared, bobShared) {
  31. t.Fatalf("shared secrets mismatched")
  32. }
  33. }
  34. }
  35. func TestIntegration(t *testing.T) {
  36. TorSampling = false
  37. testIntegration(t)
  38. }
  39. func TestIntegrationTor(t *testing.T) {
  40. TorSampling = true
  41. testIntegration(t)
  42. }