github.com/dusk-network/dusk-crypto@v0.1.3/rangeproof/helper.go (about) 1 package rangeproof 2 3 // // Key represents a scalar or point 4 // type Key [32]byte 5 6 // // add two points together 7 // func AddKeys(sum, k1, k2 *Key) { 8 // a := k1.ToExtended() 9 // b := new(CachedGroupElement) 10 // k2.ToExtended().ToCached(b) 11 // c := new(CompletedGroupElement) 12 // geAdd(c, a, b) 13 // tmp := new(ExtendedGroupElement) 14 // c.ToExtended(tmp) 15 // tmp.ToBytes(sum) 16 // return 17 // } 18 19 // // compute a*G + b*B 20 // func AddKeys2(result, a, b, B *Key) { 21 // BPoint := B.ToExtended() 22 // RPoint := new(ProjectiveGroupElement) 23 // GeDoubleScalarMultVartime(RPoint, b, BPoint, a) 24 // RPoint.ToBytes(result) 25 // return 26 // } 27 28 // // subtract two points A - B 29 // func SubKeys(diff, k1, k2 *Key) { 30 // a := k1.ToExtended() 31 // b := new(CachedGroupElement) 32 // k2.ToExtended().ToCached(b) 33 // c := new(CompletedGroupElement) 34 // geSub(c, a, b) 35 // tmp := new(ExtendedGroupElement) 36 // c.ToExtended(tmp) 37 // tmp.ToBytes(diff) 38 // return 39 // } 40 41 // func (k *Key) ToExtended() (result *ExtendedGroupElement) { 42 // result = new(ExtendedGroupElement) 43 // result.FromBytes(k) 44 // return 45 // } 46 47 // func identity() (result *Key) { 48 // result = new(Key) 49 // result[0] = 1 50 // return 51 // } 52 53 // // convert a uint64 to a scalar 54 // func d2h(val uint64) (result *Key) { 55 // result = new(Key) 56 // for i := 0; val > 0; i++ { 57 // result[i] = byte(val & 0xFF) 58 // val /= 256 59 // } 60 // return 61 // } 62 63 // // multiply a scalar by H (second curve point of Pedersen Commitment) 64 // func ScalarMultH(scalar *Key) (result *Key) { 65 // h := new(ExtendedGroupElement) 66 // h.FromBytes(&H) 67 // resultPoint := new(ProjectiveGroupElement) 68 // GeScalarMult(resultPoint, scalar, h) 69 // result = new(Key) 70 // resultPoint.ToBytes(result) 71 // return 72 // }