Initial commit of pkg functions
This commit is contained in:
parent
c325fa17e5
commit
6b6866077c
17 changed files with 1689 additions and 0 deletions
21
pkg/serial/rand.go
Normal file
21
pkg/serial/rand.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
Package serial provides serial number related functionality.
|
||||
*/
|
||||
package serial
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
const randBits = 160
|
||||
|
||||
// Rand returns a random serial number with 159 bits of entropy.
|
||||
func Rand() *big.Int {
|
||||
q := make([]byte, randBits/8)
|
||||
io.ReadFull(rand.Reader, q)
|
||||
// this just means all serial numbers are justified to the same bitlen, which is nice for tools!
|
||||
q[0] |= 0x80
|
||||
return big.NewInt(0).SetBytes(q)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue