Revision a49d80b89c9df3cb2497adb8175915c654479708 authored by Ismail Khoffi on 27 March 2019, 18:12:01 UTC, committed by Anton Kaliaev on 27 March 2019, 22:14:57 UTC
1 parent ccfe75e
random.go
package crypto
import (
crand "crypto/rand"
"encoding/hex"
"io"
)
// This only uses the OS's randomness
func randBytes(numBytes int) []byte {
b := make([]byte, numBytes)
_, err := crand.Read(b)
if err != nil {
panic(err)
}
return b
}
// This only uses the OS's randomness
func CRandBytes(numBytes int) []byte {
return randBytes(numBytes)
}
// CRandHex returns a hex encoded string that's floor(numDigits/2) * 2 long.
//
// Note: CRandHex(24) gives 96 bits of randomness that
// are usually strong enough for most purposes.
func CRandHex(numDigits int) string {
return hex.EncodeToString(CRandBytes(numDigits / 2))
}
// Returns a crand.Reader.
func CReader() io.Reader {
return crand.Reader
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...