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.

47 lines
1.1 KiB

  1. package ringct
  2. import "encoding/hex"
  3. import "github.com/deroproject/derosuite/crypto"
  4. // convert a hex string to a key
  5. // a copy of these functions exists in the crypto package also
  6. func HexToKey(h string) (result Key) {
  7. byteSlice, _ := hex.DecodeString(h)
  8. if len(byteSlice) != 32 {
  9. panic("Incorrect key size")
  10. }
  11. copy(result[:], byteSlice)
  12. return
  13. }
  14. func HexToHash(h string) (result crypto.Hash) {
  15. byteSlice, _ := hex.DecodeString(h)
  16. if len(byteSlice) != 32 {
  17. panic("Incorrect key size")
  18. }
  19. copy(result[:], byteSlice)
  20. return
  21. }
  22. // zero fill the key
  23. func Sc_0(k *Key) {
  24. for i:=0; i < 32;i++{
  25. k[i]=0
  26. }
  27. }
  28. // RandomPubKey takes a random scalar, interprets it as a point on the curve
  29. // and then multiplies by 8 to make it a point in the Group
  30. // remember the low order bug and do more auditing of the entire thing
  31. func RandomPubKey() (result *Key) {
  32. result = new(Key)
  33. p3 := new(ExtendedGroupElement)
  34. var p1 ProjectiveGroupElement
  35. var p2 CompletedGroupElement
  36. h := RandomScalar()
  37. p1.FromBytes(h)
  38. GeMul8(&p2, &p1)
  39. p2.ToExtended(p3)
  40. p3.ToBytes(result)
  41. return
  42. }