update go api

This commit is contained in:
Zhi Guan
2017-05-09 22:16:21 +08:00
parent a08b9e2221
commit a71c82c373
16 changed files with 81 additions and 0 deletions

26
go/gmssl/rand.go Normal file
View 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
}