mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-10 07:53:57 +08:00
update go api
This commit is contained in:
26
go/gmssl/rand.go
Normal file
26
go/gmssl/rand.go
Normal file
@@ -0,0 +1,26 @@
|
||||
/* +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 1 != C.RAND_bytes((*C.uchar)(&outbuf[0]), C.int(length)) {
|
||||
return nil, errors.New("GmSSL Failure")
|
||||
}
|
||||
|
||||
return outbuf[:length], nil
|
||||
}
|
||||
Reference in New Issue
Block a user