mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 17:06:25 +08:00
27 lines
439 B
Go
27 lines
439 B
Go
/* +build cgo */
|
|
package gmssl
|
|
|
|
/*
|
|
#include <openssl/rand.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"errors"
|
|
"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, errors.New("GmSSL Failure")
|
|
}
|
|
|
|
return outbuf[:length], nil
|
|
}
|