MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / ScalarMult

Method ScalarMult

crypto/secp256k1/curve.go:243–276  ·  view source on GitHub ↗

ScalarMult does the private scalar.

(Bx, By *big.Int, scalar []byte)

Source from the content-addressed store, hash-verified

241
242// ScalarMult does the private scalar.
243func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
244 // Ensure scalar is exactly 32 bytes. We pad always, even if
245 // scalar is 32 bytes long, to avoid a timing side channel.
246 if len(scalar) > 32 {
247 panic("can't handle scalars > 256 bits")
248 }
249 // NOTE: potential timing issue
250 padded := make([]byte, 32)
251 copy(padded[32-len(scalar):], scalar)
252 scalar = padded
253
254 // Do the multiplication in C, updating point.
255 point := make([]byte, 64)
256 readBits(Bx, point[:32])
257 readBits(By, point[32:])
258
259 pointPtr := (*C.uchar)(unsafe.Pointer(&point[0]))
260 scalarPtr := (*C.uchar)(unsafe.Pointer(&scalar[0]))
261 res := C.cql_secp256k1_ext_scalar_mul(context, pointPtr, scalarPtr)
262
263 // Unpack the result and clear temporaries.
264 x := new(big.Int).SetBytes(point[:32])
265 y := new(big.Int).SetBytes(point[32:])
266 for i := range point {
267 point[i] = 0
268 }
269 for i := range padded {
270 scalar[i] = 0
271 }
272 if res != 1 {
273 return nil, nil
274 }
275 return x, y
276}
277
278// ScalarBaseMult returns k*G, where G is the base point of the group and k is
279// an integer in big-endian form.

Callers 1

ScalarBaseMultMethod · 0.95

Calls 2

readBitsFunction · 0.85
SetBytesMethod · 0.80

Tested by

no test coverage detected