You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 line
1.3 KiB

  1. package p751toolbox
  2. import (
  3. "reflect"
  4. "fmt"
  5. "bytes"
  6. )
  7. func PrintHex(obj interface{}) (out string) {
  8. var buffer bytes.Buffer
  9. vector := reflect.ValueOf(obj)
  10. switch vector.Kind() {
  11. case reflect.Array, reflect.Slice:
  12. buffer.WriteString("0x")
  13. format := ""
  14. switch vector.Index(0).Kind() {
  15. case reflect.Uint8:
  16. format = "%02x"
  17. case reflect.Uint64:
  18. format = "%016x"
  19. }
  20. len := vector.Len()
  21. for i:=len-1; i>=0; i-- {
  22. word := vector.Index(i)
  23. buffer.WriteString(fmt.Sprintf(format,word))
  24. }
  25. buffer.WriteString("\n")
  26. }
  27. return buffer.String()
  28. }
  29. func (element Fp751Element) String() string {
  30. var out [94]byte
  31. element.toBytesFromMontgomeryForm(out[:])
  32. return fmt.Sprintf("%s",PrintHex(out[:]))
  33. }
  34. func (primeElement PrimeFieldElement) String() string {
  35. return fmt.Sprintf("%s",primeElement.A.String())
  36. }
  37. func (extElement ExtensionFieldElement) String() string {
  38. var out [188]byte
  39. extElement.ToBytes(out[:])
  40. return fmt.Sprintf("A: %sB: %s", PrintHex(out[:94]), PrintHex(out[94:]))
  41. }
  42. func (point ProjectivePoint) String() string {
  43. return fmt.Sprintf("X:\n%sZ:\n%s", point.X.String(), point.Z.String())
  44. }
  45. func (point ProjectivePrimeFieldPoint) String() string {
  46. return fmt.Sprintf("X:\n%sZ:\n%s", point.X.String(), point.Z.String())
  47. }