• 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## 概述
11
12定义随机数生成器API。
13
14**引用文件:** <CryptoArchitectureKit/crypto_rand.h>
15
16**库:** libohcrypto.so
17
18**系统能力:** SystemCapability.Security.CryptoFramework
19
20**起始版本:** 20
21
22**相关模块:** [CryptoRandApi](capi-cryptorandapi.md)
23
24## 汇总
25
26### 结构体
27
28| 名称 | typedef关键字 | 描述 |
29| -- | -- | -- |
30| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) | OH_CryptoRand | 定义随机数生成器结构。 |
31
32### 函数
33
34| 名称 | 描述 |
35| -- | -- |
36| [OH_Crypto_ErrCode OH_CryptoRand_Create(OH_CryptoRand **ctx)](#oh_cryptorand_create) | 创建随机数生成器。 |
37| [OH_Crypto_ErrCode OH_CryptoRand_GenerateRandom(OH_CryptoRand *ctx, int len, Crypto_DataBlob *out)](#oh_cryptorand_generaterandom) | 生成随机数。 |
38| [const char *OH_CryptoRand_GetAlgoName(OH_CryptoRand *ctx)](#oh_cryptorand_getalgoname) | 获取随机数生成器实例的算法名称。 |
39| [OH_Crypto_ErrCode OH_CryptoRand_SetSeed(OH_CryptoRand *ctx, Crypto_DataBlob *seed)](#oh_cryptorand_setseed) | 设置随机数生成器的种子。 |
40| [void OH_CryptoRand_Destroy(OH_CryptoRand *ctx)](#oh_cryptorand_destroy) | 销毁随机数生成器实例。 |
41
42## 函数说明
43
44### OH_CryptoRand_Create()
45
46```
47OH_Crypto_ErrCode OH_CryptoRand_Create(OH_CryptoRand **ctx)
48```
49
50**描述**
51
52创建随机数生成器。
53
54**起始版本:** 20
55
56
57**参数:**
58
59| 参数项 | 描述 |
60| -- | -- |
61| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) **ctx | 指向随机数生成器实例的指针。 |
62
63**返回:**
64
65| 类型 | 说明 |
66| -- | -- |
67| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | CRYPTO_SUCCESS:操作成功。<br>         CRYPTO_NOT_SUPPORTED:操作不支持。<br>         CRYPTO_MEMORY_ERROR:内存错误。<br>         CRYPTO_PARAMETER_CHECK_FAILED:参数检查失败。<br>         CRYPTO_OPERTION_ERROR:调用三方算法库API出错。 |
68
69### OH_CryptoRand_GenerateRandom()
70
71```
72OH_Crypto_ErrCode OH_CryptoRand_GenerateRandom(OH_CryptoRand *ctx, int len, Crypto_DataBlob *out)
73```
74
75**描述**
76
77生成随机数。
78
79**起始版本:** 20
80
81
82**参数:**
83
84| 参数项 | 描述 |
85| -- | -- |
86| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | 随机数生成器实例。 |
87| int len | 表示生成随机数的长度,单位为byte,范围在[1, INT_MAX]。 |
88| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *out | 用于获取随机数的指针。 |
89
90**返回:**
91
92| 类型 | 说明 |
93| -- | -- |
94| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | CRYPTO_SUCCESS:操作成功。<br>         CRYPTO_NOT_SUPPORTED:操作不支持。<br>         CRYPTO_MEMORY_ERROR:内存错误。<br>         CRYPTO_PARAMETER_CHECK_FAILED:参数检查失败。<br>         CRYPTO_OPERTION_ERROR:调用三方算法库API出错。 |
95
96### OH_CryptoRand_GetAlgoName()
97
98```
99const char *OH_CryptoRand_GetAlgoName(OH_CryptoRand *ctx)
100```
101
102**描述**
103
104获取随机数生成器实例的算法名称。
105
106**起始版本:** 20
107
108
109**参数:**
110
111| 参数项 | 描述 |
112| -- | -- |
113| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | 指向随机数生成器实例。 |
114
115**返回:**
116
117| 类型 | 说明 |
118| -- | -- |
119| const char * | 返回随机数生成器实例的算法名称。 |
120
121### OH_CryptoRand_SetSeed()
122
123```
124OH_Crypto_ErrCode OH_CryptoRand_SetSeed(OH_CryptoRand *ctx, Crypto_DataBlob *seed)
125```
126
127**描述**
128
129设置随机数生成器的种子。
130
131**起始版本:** 20
132
133
134**参数:**
135
136| 参数项 | 描述 |
137| -- | -- |
138| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | 随机数生成器实例。 |
139| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *seed | 种子数据。 |
140
141**返回:**
142
143| 类型 | 说明 |
144| -- | -- |
145| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | CRYPTO_SUCCESS:操作成功。<br>         CRYPTO_NOT_SUPPORTED:操作不支持。<br>         CRYPTO_MEMORY_ERROR:内存错误。<br>         CRYPTO_PARAMETER_CHECK_FAILED:参数检查失败。<br>         CRYPTO_OPERTION_ERROR:调用三方算法库API出错。 |
146
147### OH_CryptoRand_Destroy()
148
149```
150void OH_CryptoRand_Destroy(OH_CryptoRand *ctx)
151```
152
153**描述**
154
155销毁随机数生成器实例。
156
157**起始版本:** 20
158
159
160**参数:**
161
162| 参数项 | 描述 |
163| -- | -- |
164| [OH_CryptoRand](capi-cryptorandapi-oh-cryptorand.md) *ctx | 随机数生成器实例。 |
165
166
167