xref: /trunk/main/sal/inc/rtl/random.h (revision b9fd132d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _RTL_RANDOM_H_
25 #define _RTL_RANDOM_H_ "$Revision$"
26 
27 #include <sal/types.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*========================================================================
34  *
35  * rtlRandom interface.
36  *
37  *======================================================================*/
38 /** Random Pool opaque type.
39  */
40 typedef void* rtlRandomPool;
41 
42 
43 /** Error Code enumeration.
44  */
45 enum __rtl_RandomError
46 {
47 	rtl_Random_E_None,
48 	rtl_Random_E_Argument,
49 	rtl_Random_E_Memory,
50 	rtl_Random_E_Unknown,
51 	rtl_Random_E_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
52 };
53 
54 /** Error Code type.
55  */
56 typedef enum __rtl_RandomError rtlRandomError;
57 
58 
59 /** Create a Random Pool.
60 	@return initialized Random Pool, or NULL upon failure.
61  */
62 rtlRandomPool SAL_CALL rtl_random_createPool (void) SAL_THROW_EXTERN_C();
63 
64 
65 /** Destroy a Random Pool.
66 	@param  Pool [in] a Random Pool.
67 	@return none. Pool is invalid.
68  */
69 void SAL_CALL rtl_random_destroyPool (
70 	rtlRandomPool Pool
71 ) SAL_THROW_EXTERN_C();
72 
73 
74 /** Add bytes to a Random Pool.
75 	@param Pool    [in] a Random Pool.
76 	@param pBuffer [in] a buffer containing the bytes to add.
77 	@param nBufLen [in] the number of bytes to read from the buffer.
78 	@return rtl_Random_E_None upon success.
79  */
80 rtlRandomError SAL_CALL rtl_random_addBytes (
81 	rtlRandomPool  Pool,
82 	const void    *Buffer,
83 	sal_Size       Bytes
84 ) SAL_THROW_EXTERN_C();
85 
86 
87 /** Retrieve bytes from a Random Pool.
88 	@param Pool    [in] a Random Pool.
89 	@param pBuffer [inout] a buffer to receive the random bytes.
90 	@param nBufLen [in] the number of bytes to write to the buffer.
91 	@return rtl_Random_E_None upon success.
92  */
93 rtlRandomError SAL_CALL rtl_random_getBytes (
94 	rtlRandomPool  Pool,
95 	void          *Buffer,
96 	sal_Size       Bytes
97 ) SAL_THROW_EXTERN_C();
98 
99 /*========================================================================
100  *
101  * The End.
102  *
103  *======================================================================*/
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* _RTL_RANDOM_H_ */
110 
111