• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# crypto_rand.h
2
3<!--Kit: Crypto Architecture Kit-->
4<!--Subsystem: Security-->
5<!--Owner: @zxz--3-->
6<!--Designer: @lanming-->
7<!--Tester: @PAFT-->
8<!--Adviser: @zengyawen-->
9
10## Overview
11
12Defines APIs for a random number generator.
13
14**Header file**: <CryptoArchitectureKit/crypto_rand.h>
15
16**Library**: libohcrypto.so
17
18**System capability**: SystemCapability.Security.CryptoFramework
19
20**Since**: 20
21
22**Related Module**: [CryptoRandApi](capi-cryptorandapi.md)
23
24## Summary
25
26### Structs
27
28| Name| typedef Keyword| Description|
29| -- | -- | -- |
30| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) | OH_CryptoRand | Defines a struct for a random number generator.|
31
32### Functions
33
34| Name| Description|
35| -- | -- |
36| [OH_Crypto_ErrCode OH_CryptoRand_Create(OH_CryptoRand **ctx)](#oh_cryptorand_create) | Creates a random number generator.|
37| [OH_Crypto_ErrCode OH_CryptoRand_GenerateRandom(OH_CryptoRand *ctx, int len, Crypto_DataBlob *out)](#oh_cryptorand_generaterandom) | Generates random numbers.|
38| [const char *OH_CryptoRand_GetAlgoName(OH_CryptoRand *ctx)](#oh_cryptorand_getalgoname) | Obtains the algorithm name of a random number generator instance.|
39| [OH_Crypto_ErrCode OH_CryptoRand_SetSeed(OH_CryptoRand *ctx, Crypto_DataBlob *seed)](#oh_cryptorand_setseed) | Sets the seed of a random number generator.|
40| [void OH_CryptoRand_Destroy(OH_CryptoRand *ctx)](#oh_cryptorand_destroy) | Destroys a random number generator instance.|
41
42## Function Description
43
44### OH_CryptoRand_Create()
45
46```
47OH_Crypto_ErrCode OH_CryptoRand_Create(OH_CryptoRand **ctx)
48```
49
50**Description**
51
52Creates a random number generator.
53
54**Since**: 20
55
56
57**Parameters**
58
59| Name| Description|
60| -- | -- |
61| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) **ctx | Pointer to the random number generator instance.|
62
63**Returns**
64
65| Type| Description|
66| -- | -- |
67| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br>         **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br>         **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br>         **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br>         **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.|
68
69### OH_CryptoRand_GenerateRandom()
70
71```
72OH_Crypto_ErrCode OH_CryptoRand_GenerateRandom(OH_CryptoRand *ctx, int len, Crypto_DataBlob *out)
73```
74
75**Description**
76
77Generates random numbers.
78
79**Since**: 20
80
81
82**Parameters**
83
84| Name| Description|
85| -- | -- |
86| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | Random number generator instance.|
87| int len | Length of the random number to generate, in bytes. The value range is [1, INT_MAX].|
88| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *out | Pointer to the random number.|
89
90**Returns**
91
92| Type| Description|
93| -- | -- |
94| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br>         **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br>         **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br>         **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br>         **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.|
95
96### OH_CryptoRand_GetAlgoName()
97
98```
99const char *OH_CryptoRand_GetAlgoName(OH_CryptoRand *ctx)
100```
101
102**Description**
103
104Obtains the algorithm name of a random number generator instance.
105
106**Since**: 20
107
108
109**Parameters**
110
111| Name| Description|
112| -- | -- |
113| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | Pointer to the random number generator instance.|
114
115**Returns**
116
117| Type| Description|
118| -- | -- |
119| const char * | Algorithm name of a random number generator instance.|
120
121### OH_CryptoRand_SetSeed()
122
123```
124OH_Crypto_ErrCode OH_CryptoRand_SetSeed(OH_CryptoRand *ctx, Crypto_DataBlob *seed)
125```
126
127**Description**
128
129Sets the seed of a random number generator.
130
131**Since**: 20
132
133
134**Parameters**
135
136| Name| Description|
137| -- | -- |
138| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | Random number generator instance.|
139| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *seed | Seed data.|
140
141**Returns**
142
143| Type| Description|
144| -- | -- |
145| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br>         **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br>         **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br>         **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br>         **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.|
146
147### OH_CryptoRand_Destroy()
148
149```
150void OH_CryptoRand_Destroy(OH_CryptoRand *ctx)
151```
152
153**Description**
154
155Destroys a random number generator instance.
156
157**Since**: 20
158
159
160**Parameters**
161
162| Name| Description|
163| -- | -- |
164| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | Random number generator instance.|
165