goc25519sm_example_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright © 2021 Jeffrey H. Johnson <trnsz@pobox.com>
  2. // Copyright © 2021 Gridfinity, LLC.
  3. // Copyright © 2019 The Go Authors.
  4. //
  5. // All rights reserved.
  6. //
  7. // Use of this source code is governed by the BSD-style
  8. // license that can be found in the LICENSE file.
  9. // Package goc25519sm_test provides tests for the goc25519sm library.
  10. package goc25519sm_test
  11. import (
  12. "fmt"
  13. goc25519sm "github.com/johnsonjh/goc25519sm"
  14. )
  15. // OldScalarMult sets 'dst' to the product of ('scalar' * 'point'), where
  16. // 'scalar' and 'point' are the x coordinates of group points, with all values
  17. // specified in little-endian form. As always, care must be taken when
  18. // copying 'dst' into a fixed-size array to avoid potential application bugs.
  19. func ExampleOldScalarMult() {
  20. var err error
  21. var dst [goc25519sm.X25519Size]byte
  22. err = goc25519sm.OldScalarMult(
  23. &dst,
  24. &goc25519sm.ExamplePointA,
  25. &goc25519sm.Basepoint,
  26. )
  27. if err != nil {
  28. fmt.Println(
  29. fmt.Errorf(
  30. "\ngoc25519sm_test.ExampleOldScalarMult.goc25519sm.OldScalarMult FAILURE:\n dst=%v\n point=%v\n base=%v\n %v",
  31. dst,
  32. goc25519sm.ExamplePointA,
  33. goc25519sm.Basepoint,
  34. err,
  35. ),
  36. )
  37. } else {
  38. fmt.Printf(
  39. "%v",
  40. dst,
  41. )
  42. }
  43. // Output: [66 122 229 107 218 63 64 231 243 68 229 108 16 57 164 54 219 131 67 199 51 187 152 115 156 62 194 207 141 229 208 116]
  44. }
  45. // OldScalarBaseMult sets 'dst' to the product of ('scalar' * 'base'), where
  46. // 'scalar' and 'base' are the x coordinates of group points, and 'base' is
  47. // always the standard canonical Curve25519 generator, with all values
  48. // specified in little-endian form. As always, care must be taken by when
  49. // copying 'dst' into a fixed-size array to avoid potential application bugs.
  50. func ExampleOldScalarBaseMult() {
  51. var err error
  52. var dst [goc25519sm.X25519Size]byte
  53. err = goc25519sm.OldScalarBaseMult(
  54. &dst,
  55. &goc25519sm.ExamplePointB,
  56. )
  57. if err != nil {
  58. fmt.Println(
  59. fmt.Errorf(
  60. "\ngoc25519sm_test.ExampleOldScalarBaseMult.goc25519sm.OldScalarBaseMult FAILURE:\n dst=%v\n point=%v\n %v",
  61. dst,
  62. goc25519sm.ExamplePointB,
  63. err,
  64. ),
  65. )
  66. } else {
  67. fmt.Printf(
  68. "%v\n",
  69. dst,
  70. )
  71. }
  72. // Output: [93 146 199 126 178 229 251 64 79 89 30 113 124 116 224 71 248 157 194 158 254 59 217 255 200 96 218 131 168 125 174 103]
  73. }