-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutil.go
More file actions
29 lines (25 loc) · 856 Bytes
/
util.go
File metadata and controls
29 lines (25 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package clevis
import (
"crypto/elliptic"
"math/big"
)
// expandBuffer prepends zero bytes so that len(result) == finalLength.
// If buffer is already the right length or longer, it is returned as-is.
func expandBuffer(buffer []byte, finalLength int) []byte {
if len(buffer) >= finalLength {
return buffer
}
newBuffer := make([]byte, finalLength)
copy(newBuffer[finalLength-len(buffer):], buffer)
return newBuffer
}
// divRoundUp divides num to divisor with rounding up the result to the next integer value
func divRoundUp(num, divisor int) int {
return (num + divisor - 1) / divisor
}
// ecSubtract subtracts point (x2,y2) from (x1,y1) over curve ecCurve
func ecSubtract(ecCurve elliptic.Curve, x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int) {
yy := new(big.Int).Neg(y2)
yy.Mod(yy, ecCurve.Params().P)
return ecCurve.Add(x1, y1, x2, yy)
}