在调用 tls_crypto_trng () 函数时, 在开始阶段, 是不是需要收到物理信号才会产生随机数? 那么这端程序逻辑是什么流程呢? 如何搭配物理设备可以收到这个信号? 现在有温湿度传感器, 陀螺仪, 气压传感器.
g_crypto_ctx. gpsec_lock 定义的是一个互斥锁, 在 SDK 的初始化时有调用 tls_crypto_init, 在这里创建了该信号量, 初始值是 1, 所以在没有其他地方用到该模块时, 调用 tls_os_sem_acquire (g_crypto_ctx. gpsec_lock, 0) ; 会立即返回接着往下执行. 如果有其他地方调用了就会等待, 直到能获取到信号量才能接着往下执行, 起到一个互斥锁的功能. 调用 tls_os_sem_acquire 获取, 信号量的个数会减一, 调用 tls_os_sem_release 释放, 信号量的个数会加一, 这两个接口是成对使用的. 在使用信号量实现互斥锁的功能时, 创建信号量时初始值会设置为 1, 这样有一个地方获取了锁的使用权后, 其他地方就需要等待这里释放了才能获取, 起到防止出现同一个模块或者变量或者接口被同时操作的情况. 并不是一个物理信号.
Hello! SDK for w80x is still at the conceptual stage in our team.
We have not yet thoroughly understood how this pie works : ) ) For HAL 0. 6. 0, extracting true random numbers was easy. You can see this technique in our Arduino core. Methods trng_init () and rng_Get () . There is no need for a special signal to generate a random number. A noise-like signal is generated on the cryptomodule crystal. There is a description of this in the datasheet.
Thank you very much for your reply! I am developing with the SDK as shown in the figure below. I don't know where the Arduino core you mentioned is, as there is no relevant explanation in the materials provided by the manufacturer. Could you explain it in more detail? Also, I found that when the wait time is set to 0, it seems to be waiting for a signal all the time, so no true random number is generated. So when the wait time is set to 20, is it generating pseudo-random numbers?
@1201 Sorry, but I don't understand what your problem is.
Let's look at random number generation as programmers who are not familiar with the internal structure of the w80x chip. What do we usually do? We use two functions from stdlib - srand (time (NULL) ) and rand () . This way we get a non-repeating pseudo-random sequence. Exploring the SDK-W80X we will find the definitions and prototypes we need for generation in the files wm_crypto_hard. h and *. c
It says that by default the generation of a true random number works -
define USE_TRNG 1
By analogy with stdlib, we need to initialize the generator using the function
int tls_crypto_random_init (u32 seed, CRYPTO_RNG_SWITCH rng_switch) ;
In this case, the seed parameter will not affect the sequence, because the white noise generator is running.
The next step is to get a pointer to a random number using the function int tls_crypto_trng (unsigned char *out, u32 len) ;
And that's enough.
I have another question - Why do they slow down the core by calling the function delay_cnt (1000) ; ? White noise turns on during initialization and runs until we stop it.
@1201 To expand on my answer. . . The semaphore blocking may be due to the fact that this is a critical section according to the SDK developers. If you don't have a deep understanding of how RTOS works, you don't need to go there. : )
@AnatolSher I know that if random numbers generated with a seed are pseudo-random, then I have a question: is it certain that the tls_crypto_trng () function can generate true random numbers? Looking forward to your response. Thank you.
@1201 Be confident. Datasheets usually don" t write nonsense : )
See section 7. 3. 8 on page 63.
The difference between a true random number generator (TRNG) and a pseudo random number generator (PRNG) is that an TRNG uses unpredictable physical means to generate numbers (such as junction noise) , while a PRNG uses mathematical algorithms (entirely computer generated) .
@1201 junction noise = semiconductor P-N junction noise
This is not a predictable phenomenon
@AnatolSher Where can I find datasheets?
@1201
https: //www. winnermicro. com/html/1/156/158/558. html
@1201 http: //ask. winnermicro. com/article/3. html
@AnatolSher I have read this document but I did not find what I was looking for. 0. 0