newhope_simple_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // newhope_simple_test.go - NewHope-Simple 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 testSimpleIntegration(t *testing.T) {
  14. for i := 0; i < 1024; i++ {
  15. // Generate Alice's key's.
  16. alicePriv, alicePub, err := GenerateKeyPairSimpleAlice(rand.Reader)
  17. if err != nil {
  18. t.Fatalf("GenerateKeyPairSimpleAlice failed: %v", err)
  19. }
  20. // Finish Bob's handshake.
  21. bobPub, bobShared, err := KeyExchangeSimpleBob(rand.Reader, alicePub)
  22. if err != nil {
  23. t.Fatalf("KeyExchangeSimpleBob failed: %v", err)
  24. }
  25. // Finish Alice's handshake.
  26. aliceShared, err := KeyExchangeSimpleAlice(bobPub, alicePriv)
  27. if err != nil {
  28. t.Fatalf("KeyExchangeSimpleAlice failed: %v", err)
  29. }
  30. if !bytes.Equal(aliceShared, bobShared) {
  31. t.Fatalf("shared secrets mismatched")
  32. }
  33. }
  34. }
  35. func TestSimpleIntegration(t *testing.T) {
  36. TorSampling = false
  37. testSimpleIntegration(t)
  38. }
  39. func TestSimpleIntegrationTor(t *testing.T) {
  40. TorSampling = true
  41. testSimpleIntegration(t)
  42. }