22 lines
446 B
Go
22 lines
446 B
Go
|
/*
|
||
|
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)
|
||
|
}
|