Files
GmSSL/go/gmssl/rand.go
2018-08-06 20:51:29 +08:00

25 lines
412 B
Go

/* +build cgo */
package gmssl
/*
#include <openssl/rand.h>
*/
import "C"
import (
"unsafe"
)
func SeedRandom(seed []byte) error {
C.RAND_seed(unsafe.Pointer(&seed[0]), C.int(len(seed)))
return nil
}
func GenerateRandom(length int) ([]byte, error) {
outbuf := make([]byte, length)
if C.RAND_bytes((*C.uchar)(&outbuf[0]), C.int(length)) <= 0 {
return nil, GetErrors()
}
return outbuf[:length], nil
}