Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / src / shared / platform / nacl_secure_random_base.h
1 /*
2  * Copyright 2008 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /*
8  * NaCl Service Runtime.  Secure RNG abstraction.  Base class.
9  */
10
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_NACL_SECURE_RANDOM_BASE_H_
12 #define NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_NACL_SECURE_RANDOM_BASE_H_
13
14 #include "native_client/src/include/portability.h"
15
16 #include "native_client/src/include/nacl_base.h"
17
18 EXTERN_C_BEGIN
19
20 struct NaClSecureRngIf;  /* fwd: base interface class */
21
22 struct NaClSecureRngIfVtbl {
23   void      (*Dtor)(struct NaClSecureRngIf  *self);
24   /*
25    * Generates a uniform random 8-bit byte (uint8_t).
26    */
27   uint8_t   (*GenByte)(struct NaClSecureRngIf *self);
28   /*
29    * Generates a uniform random 32-bit unsigned int.
30    */
31   uint32_t  (*GenUint32)(struct NaClSecureRngIf *self);
32   /*
33    * Generate an uniformly random number in [0, range_max).  May invoke
34    * the provided generator multiple times.
35    */
36   void      (*GenBytes)(struct NaClSecureRngIf  *self,
37                         uint8_t                 *buf,
38                         size_t                  nbytes);
39   uint32_t  (*Uniform)(struct NaClSecureRngIf *self,
40                        uint32_t               range_max);
41 };
42
43 struct NaClSecureRngIf {
44   struct NaClSecureRngIfVtbl const  *vtbl;
45 };
46
47 EXTERN_C_END
48
49 #endif  /* NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_NACL_SECURE_RANDOM_BASE_H_ */