goc25519sm_verify_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2021 Jeffrey H. Johnson <trnsz@pobox.com>.
  2. // Copyright 2021 Gridfinity, LLC.
  3. // Copyright 2020 Frank Denis <j at pureftpd dot org>.
  4. // Copyright 2012 The Go Authors.
  5. //
  6. // All rights reserved.
  7. //
  8. // Use of this source code is governed by the BSD-style
  9. // license that can be found in the LICENSE file.
  10. package goc25519sm
  11. import (
  12. "fmt"
  13. "os"
  14. "testing"
  15. u "github.com/johnsonjh/leaktestfe"
  16. )
  17. func TestMain(m *testing.M) {
  18. CorruptBasepointTest = true
  19. exitVal := m.Run()
  20. os.Exit(
  21. exitVal,
  22. )
  23. }
  24. func TestOldScalarMultVerifyFailure(
  25. t *testing.T,
  26. ) {
  27. defer u.Leakplug(
  28. t,
  29. )
  30. var dst, scalar, point [X25519Size]byte
  31. copy(dst[:], ExamplePointB[:])
  32. copy(scalar[:], ExamplePointA[:])
  33. copy(point[:], ExamplePointB[:])
  34. err := oldScalarMultVerify(&dst, &scalar, &point)
  35. if err != nil {
  36. t.Fatal(
  37. fmt.Sprintf(
  38. "\ngoc25519sm_verify_test.TestOldScalarMultVerifyFailure.oldScalarMultVerify FAILURE:\n dst=%v\n scalar=%v\n point=%v\n %v",
  39. dst,
  40. scalar,
  41. point,
  42. err,
  43. ),
  44. )
  45. }
  46. }
  47. func TestOldScalarMultVerifyLowFailure(
  48. t *testing.T,
  49. ) {
  50. defer u.Leakplug(
  51. t,
  52. )
  53. var dst, scalar, point [X25519Size]byte
  54. copy(scalar[:], ExamplePointA[:])
  55. copy(point[:], ExamplePointB[:])
  56. err := oldScalarMultVerify(&dst, &scalar, &point)
  57. if err == nil {
  58. t.Fatal(
  59. fmt.Sprintf(
  60. "\ngoc25519sm_verify_test.TestOldScalarMultVerifyLowFailure.oldScalarMultVerify FAILURE:\n dst=%v\n scalar=%v\n point=%v\n %v",
  61. dst,
  62. scalar,
  63. point,
  64. err,
  65. ),
  66. )
  67. }
  68. }
  69. func TestInitCorruptBasepointTestFailure(
  70. t *testing.T,
  71. ) {
  72. defer u.Leakplug(
  73. t,
  74. )
  75. if !CorruptBasepointTest {
  76. t.Fatal(
  77. "\ngoc25519sm_verify_test.TestInitFailure FAILURE:\n CorruptBasepointTest unset",
  78. )
  79. }
  80. }