File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
openssl-sys/src/handwritten Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ use libc::*;
3
3
extern "C" {
4
4
pub fn RAND_bytes ( buf : * mut u8 , num : c_int ) -> c_int ;
5
5
6
+ #[ cfg( ossl111) ]
7
+ pub fn RAND_priv_bytes ( buf : * mut u8 , num : c_int ) -> c_int ;
8
+
6
9
#[ cfg( ossl111) ]
7
10
pub fn RAND_keep_random_devices_open ( keep : c_int ) ;
8
11
Original file line number Diff line number Diff line change @@ -37,6 +37,31 @@ pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> {
37
37
}
38
38
}
39
39
40
+ /// Fill buffer with cryptographically strong pseudo-random bytes. It is
41
+ /// intended to be used for generating values that should remain private.
42
+ ///
43
+ /// # Examples
44
+ ///
45
+ /// To generate a buffer with cryptographically strong random bytes:
46
+ ///
47
+ /// ```
48
+ /// use openssl::rand::rand_priv_bytes;
49
+ ///
50
+ /// let mut buf = [0; 256];
51
+ /// rand_priv_bytes(&mut buf).unwrap();
52
+ /// ```
53
+ ///
54
+ /// Requires OpenSSL 1.1.1 or newer.
55
+ #[ corresponds( RAND_priv_bytes ) ]
56
+ #[ cfg( ossl111) ]
57
+ pub fn rand_priv_bytes ( buf : & mut [ u8 ] ) -> Result < ( ) , ErrorStack > {
58
+ unsafe {
59
+ ffi:: init ( ) ;
60
+ assert ! ( buf. len( ) <= c_int:: max_value( ) as usize ) ;
61
+ cvt ( ffi:: RAND_priv_bytes ( buf. as_mut_ptr ( ) , buf. len ( ) as LenType ) ) . map ( |_| ( ) )
62
+ }
63
+ }
64
+
40
65
/// Controls random device file descriptor behavior.
41
66
///
42
67
/// Requires OpenSSL 1.1.1 or newer.
@@ -50,11 +75,16 @@ pub fn keep_random_devices_open(keep: bool) {
50
75
51
76
#[ cfg( test) ]
52
77
mod tests {
53
- use super :: rand_bytes;
54
-
55
78
#[ test]
56
79
fn test_rand_bytes ( ) {
57
80
let mut buf = [ 0 ; 32 ] ;
58
- rand_bytes ( & mut buf) . unwrap ( ) ;
81
+ super :: rand_bytes ( & mut buf) . unwrap ( ) ;
82
+ }
83
+
84
+ #[ test]
85
+ #[ cfg( ossl111) ]
86
+ fn test_rand_priv_bytes ( ) {
87
+ let mut buf = [ 0 ; 32 ] ;
88
+ super :: rand_priv_bytes ( & mut buf) . unwrap ( ) ;
59
89
}
60
90
}
You can’t perform that action at this time.
0 commit comments