如何使用STM32 MCU生成REAL随机数? [英] How generate REAL random number using STM32 MCU?

查看:807
本文介绍了如何使用STM32 MCU生成REAL随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用keil microvision IDE中的STM32F103E arm cortex-m3 MCU开发一个项目.
我出于某些目的需要生成随机数,但是我不想使用标准c ++库正在生成的伪随机数,因此我需要一种使用硬件功能生成REAL随机数的方法,但是我不知道如何我能做到的
任何的想法? (我不是软件工程师,也不是电子专业人员,所以请简单地描述一下:P)

I'm working on a project with STM32F103E arm cortex-m3 MCU in keil microvision IDE.
I need to generate random numbers for some purposes, but I don't want to use pseudo-random numbers which standard c++ libraries are generating, so I need a way to generate REAL random numbers using hardware features, but I don't know how I can do it.
Any idea? (I'm a software engineer & not an electronic professional, so please describe it simple :P)

推荐答案

如前所述,该芯片没有硬件RNG.

As pointed out, the chip does not have a hardware RNG.

但是您可以自己动手.通常的方法是测量独立时钟之间的抖动.独立意味着两个时钟由不同的基督或RC振荡器支持,而不是从相同的时钟衍生出来的.

But you can roll your own. The usual approach is to measure jitter between INDEPENDENT clocks. Independent means that the two clocks are backed by different christals or RC-oscillators and not derived from the same.

我会使用:

  • SysTick计时器/计数器源自系统时钟(MHz范围)
  • 其中一个kHz范围的RC振荡器

在kHz范围的RC振荡器上设置一个计数器,使您每秒可以中断几次.在中断处理程序中,您将读取SysTick计数器的当前值.不管SysTick是否用于其他目的(计划),低5位都绝对不可预测.

Set up a counter on the kHz-range RC oscillator to give you an interrupt several times a second. In the interrupt handler you read the current value of the SysTick counter. Whether or not SysTick is used for other purposes (scheduling), the lower 5 or so bits are by all means unpredictable.

要从中获取随机数,请使用常规的伪RNG.使用上面收集的熵以不可预测的方式改变伪RNG的内部状态.对于密钥生成,不要一次读取所有位,而是要允许发生一些突变.

For getting random numbers out of this, use a normal pseudo RNG. Use the entropy gathered above to unpredictably mutate the internal state of the pseudo RNG. For key generation, don't read all the bits at once but allow for a couple of mutations to happen.

明显的对策:如果攻击者可以测量或控制高达MHz精度的kHz范围的RC振荡器,那么随机性就会消失.如果您担心这一点,请使用智能卡或其他安全协处理器.

Attacks against this are obvious: If the attacker can measure or control the kHz-range RC oscillator up to MHz precision, the randomness goes away. If you are worried about that, use a smart card or other security co-processor.

这篇关于如何使用STM32 MCU生成REAL随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆