Files
GmSSL/go/gmssl/rand.go
Zhi Guan 27940499bc Update Go API to version 1.2
Add Certificate Object, support parse, check and access (very limited)
attributes of an X.509 certificate in PEM format.
2018-07-15 10:54:52 +08:00

26 lines
413 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
}