Source file src/crypto/internal/boring/rand.go

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build boringcrypto && linux && (amd64 || arm64) && !android && !msan
     6  
     7  package boring
     8  
     9  // #include "goboringcrypto.h"
    10  import "C"
    11  import "unsafe"
    12  
    13  type randReader int
    14  
    15  func (randReader) Read(b []byte) (int, error) {
    16  	// Note: RAND_bytes should never fail; the return value exists only for historical reasons.
    17  	// We check it even so.
    18  	if len(b) > 0 && C._goboringcrypto_RAND_bytes((*C.uint8_t)(unsafe.Pointer(&b[0])), C.size_t(len(b))) == 0 {
    19  		return 0, fail("RAND_bytes")
    20  	}
    21  	return len(b), nil
    22  }
    23  
    24  const RandReader = randReader(0)
    25  

View as plain text