Master The Pico WiFi: Random Numbers
Written by Harry Fairhead & Mike James   
Monday, 11 March 2024
Article Index
Master The Pico WiFi: Random Numbers
Pseudo Randomness
Cryptographic Random Generator
Harnessing Entropy
Pico SDK Randomness

Random numbers are the basis of most security, but they are suprisingly difficult to create. This is an extract from our intermediate level book on the Pico's Wifi capabilities. 

Master the Raspberry Pi Pico in C:
WiFiwith lwIP & mbedtls

By Harry Fairhead & Mike James

picomaster360

Buy from Amazon.

Contents

       Preface

  1. The Pico WiFi Stack
  2. Introduction To TCP
          Extract:
    Simplest HTTP Client
  3. More Advanced TCP
  4. SSL/TLS and HTTPS
          Extract:
    Simplest HTTPS Client
  5. Details of Cryptography
          Extract:
    Random Numbers
  6. Servers
          Extract: HTTP Server NEW!!
  7. UDP For Speed
          Extract: 
    Basic UDP
  8. SNTP For Time-Keeping
  9. SMTP For Email
  10. MQTT For The IoT

    Appendix 1 Getting Started In C

<ASIN:B0C247QJLK>

 

Cryptography is hard and you need to be an expert to implement almost any of its methods, however you also need to be a little bit of an expert to understand what the choices are in making use of a library like mbedtls. This chapter is a collection of theory and practice concerning the various things you have to get right to ensure that you are using the cryptography provided by the library in a secure way. This is by no means a complete or advanced treatment and at the end of the chapter there is still much to know but you should be able to appreciate some of the difficulties in achieving and maintaining security. It’s a “get you started” practical guide.

The Problem of Random Numbers

One of the requirements of IoT devices that are intended for anything other than personal or experimental use is ensuring that the device is secure. The best way to do this is to use a well-known and widely used cryptographic library such as mbedtls. If you do this you can claim “uses industry standard” encryption. Unfortunately all of the security rests on the foundation of a good random number source.

The reason for this is not difficult to see. The random numbers are used to generate the key used in the symmetric key encryption used to transmit the bulk of the data between client and server. The public and private key encryption which doesn’t rely on a random number generation is secure as long as you keep the private key secret and as long as it has enough bits to make working it out from the public key or guessing it difficult.

Symmetric key encryption, on the other hand, is vulnerable to simply guessing the key. You can try to decrypt the data using trial keys until you get something intelligible as plain text. Again this is difficult as long as the key has enough bits and has been chosen at random. However, if the random number generator has any statistical flaws then the search space of trial keys can be much reduced. For example, any random number generator that delivers more zeros than ones cuts the search space in half. If you can find enough statistical irregularities you can reduce the initial huge search space into something more reasonable.

In short, the security of symmetric key encryption depends on the quality of the random number generator.

The question is how much quality do you need in a random number generator?

In practice, the chance of a device being hacked due to a not-quite-perfect random number generator is small because it generally isn’t worth the effort and there are lots of easier ways to compromise a system, especially if you have physical access to it. However, there is also the matter of how things are presented. Some users are very security-conscious and the only reasonable way of satisfying them is to use industry standard encryption with industry standard best practices. If you have to state “we use a standard cryptographic library but use a homemade random number generator” then confidence will be dented.

To make use of TLS you have to provide a random number generator, mbedtls_hardware_poll, to enable the key exchange to work. With the introduction of SDK 1.5 there are a number of new random number generating functions and a standard implementation of mbedtls_hardware_poll is made available using them. However, this doesn’t mean you can ignore the problem. Random numbers are important and understanding the problem is worth the investment.



Last Updated ( Monday, 11 March 2024 )