File tree 2 files changed +36
-1
lines changed
openssl-sys/src/handwritten
2 files changed +36
-1
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,18 @@ pub fn keep_random_devices_open(keep: bool) {
50
75
51
76
#[ cfg( test) ]
52
77
mod tests {
53
- use super :: rand_bytes;
78
+ use super :: { rand_bytes, rand_priv_bytes } ;
54
79
55
80
#[ test]
56
81
fn test_rand_bytes ( ) {
57
82
let mut buf = [ 0 ; 32 ] ;
58
83
rand_bytes ( & mut buf) . unwrap ( ) ;
59
84
}
85
+
86
+ #[ test]
87
+ #[ cfg( ossl111) ]
88
+ fn test_rand_priv_bytes ( ) {
89
+ let mut buf = [ 0 ; 32 ] ;
90
+ rand_priv_bytes ( & mut buf) . unwrap ( ) ;
91
+ }
60
92
}
You can’t perform that action at this time.
0 commit comments