Author Topic: Favorite cipher for uC implementation  (Read 6597 times)

0 Members and 1 Guest are viewing this topic.

Offline HarvsTopic starter

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
Favorite cipher for uC implementation
« on: April 23, 2014, 08:30:48 am »
Anyone like to share what cipher(s) they find is particularly suitable for implementing on microcontrollers for "low speed" comms or file storage?

Personally I'm most interested in anything that would be suitable for CM0 to CM4 with >=4k RAM.

Bonus points if it's already got C implementations, and even better if it's also already implemented in higher level PC languages (e.g. Java/C# etc.)

No I don't have a specific application I'm working on, I'm just interested for future projects...

Edit: spelling corrected...
« Last Edit: April 23, 2014, 08:51:18 am by Harvs »
 

Offline Balaur

  • Supporter
  • ****
  • Posts: 525
  • Country: fr
Re: Favorite cyper for uC implementation
« Reply #1 on: April 23, 2014, 08:43:39 am »
s/cyper/cipher/g ?
 

Offline jeremy

  • Super Contributor
  • ***
  • Posts: 1079
  • Country: au
Re: Favorite cipher for uC implementation
« Reply #2 on: April 23, 2014, 08:54:47 am »
A bunch of micros have hardware AES built in. STM32F4 series comes to mind but I think you need to sign an export license to get the ones with crypto.
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: Favorite cipher for uC implementation
« Reply #3 on: April 23, 2014, 09:11:25 am »
If you want a symmetric cipher:
AES-128 without contest if you want it to be very secure (up till 2030 according to latest NIST).
As mentioned above there are HW versions but then you are stuck to very limited devices.

Software code is widely available (for instance the original code called Rijndael or better optimised versions in OpenSSL but also in other places).
You also have the choice between speed and larger code or slower and smaller code (for speed you pre-calculate more tables and store them in ROM).
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26896
  • Country: nl
    • NCT Developments
Re: Favorite cipher for uC implementation
« Reply #4 on: April 23, 2014, 03:25:20 pm »
RC6 is nice and compact.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline kfitch42

  • Frequent Contributor
  • **
  • Posts: 300
  • Country: us
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: Favorite cipher for uC implementation
« Reply #6 on: April 23, 2014, 05:18:33 pm »
If you want less security but size and speed are the most important there is also XTEA but as said before AES is the defacto standard at the moment.
http://en.wikipedia.org/wiki/XTEA
 

Offline ve7xen

  • Super Contributor
  • ***
  • Posts: 1192
  • Country: ca
    • VE7XEN Blog
Re: Favorite cipher for uC implementation
« Reply #7 on: April 23, 2014, 05:36:39 pm »
I would probably stick to AES (Rijndael). It's well studied, lots of implementations are available, it's quite simple, and is small and fast on 8-bit CPUs. I don't see any reason not to use it unless you're seriously constrained in one parameter or another. Many micros you may choose to target will have a coprocessor for it too, which you might be able to make use of at one point or another in your system.

TEA/XTEA/XXTEA are simpler and maybe faster/smaller but much less well studied (and have more serious known weaknesses) and for modern CPUs probably don't offer a huge performance gain over Rijndael.

My understanding from the AES process was that RC6 was both larger in RAM and slower than Rijndael and possibly difficult/slow to implement in constant-time (at least on small 8-bitters) without exposing timing attacks due to variable rotation and multiplication. This might be well out of date now, from Schneier's papers during the AES competition.
73 de VE7XEN
He/Him
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26896
  • Country: nl
    • NCT Developments
Re: Favorite cipher for uC implementation
« Reply #8 on: April 23, 2014, 06:17:25 pm »
In my experience AES is either big and/or slow. There is a reason that AES is usually implemented in hardware if a lot of information needs to be processed...
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline GiskardReventlov

  • Frequent Contributor
  • **
  • Posts: 598
  • Country: 00
  • How many pseudonyms do you have?
Re: Favorite cipher for uC implementation
« Reply #9 on: April 23, 2014, 08:42:29 pm »
Is the criteria a cypher for mcu or is the criteria something else? You say for "comms or file storage".
Comms == end-to-end encryption?
file storage == after the data is stored, when the file is created and while it's stored and after it's stored?

How much time do you want your mcu to spend with encrypt/decrypt?

Look at all the ones that NIST, NSA have blessed and market, then use different one?

Gibson at grc wanted to write his own end-to-end secure VPN but never started because he knew the feds would insist on a back door.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Favorite cipher for uC implementation
« Reply #10 on: April 23, 2014, 09:51:12 pm »
Quote
particularly suitable for implementing on microcontrollers for "low speed" comms or file storage?

Parity? CRC? particularly on a chip with hardware parity / CRC generator.
================================
https://dannyelectronics.wordpress.com/
 

Offline HarvsTopic starter

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
Re: Favorite cipher for uC implementation
« Reply #11 on: April 23, 2014, 11:31:07 pm »
Comms == end-to-end encryption?
As in encrypt on send and receive of packets between a uC and a PC.  I'm thinking of giving some degree of protection to totally open RF interfaces like I've used in the past.

Quote
file storage == after the data is stored, when the file is created and while it's stored and after it's stored?
More thinking of encrypting the data prior to storage, and decrypting on read.  Say something like encrypting passwords and contact info on an SD card that's loaded into the system.

Quote
How much time do you want your mcu to spend with encrypt/decrypt?
Hard to say... How long is a piece of string?  The less processing power it takes to do, the more inclined I'd be to use it more often.

Having a browse around I found these benchmarks for AES on CM0
http://realtimelogic.com/products/sharkssl/Cortex-M0/

This is a commercial library and won't include any of the overhead that goes with shifting data around, but even still I'm actually surprised that @ 24MHz they're getting >200KB/s through AES.  I thought it was going to be a lot worse than that.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Favorite cipher for uC implementation
« Reply #12 on: April 23, 2014, 11:54:42 pm »
Don't forget that a block cypher like AES needs quite a bit of additional "intellectual infrastructure" around it before you have a secure file or data stream encryption technique.  Do any of it wrong, and you render the scheme "useless" for security.  (That's "useless" by cryptographer's measures.  IMPO, there's a lot of use to be had in between "I sent plaintext" and "I implemented a cryptographically provable secure algorithm."   Just be aware that if your scheme will end up used in something that is likely to be an "attractive target", then eventually there will appear a "tool" that does all the hard work for would-be "crackers."  (Even embarrassingly awful crypto algorithms can be useful.))
 

Offline theatrus

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Favorite cipher for uC implementation
« Reply #13 on: April 24, 2014, 05:34:40 am »
AES should be your default for a symmetric cipher. Absolute worst case RC4 with all of the known caveats.

However preshared keys are terrible. Using ECC for key setup (ECDHE with ECDSA, a well seeded AES RNG, SHAxxx for diffusion) is going to add a lot of capability. Unlike RSA, ECC at 256bit sizes is quite doable. I've ported implementations from TinyECC to vanilla C (watch out for bugs in ECDSA mode)
Software by day, hardware by night; blueAcro.com
 

Offline tonyarkles

  • Regular Contributor
  • *
  • Posts: 118
Re: Favorite cipher for uC implementation
« Reply #14 on: April 24, 2014, 07:02:30 am »
Something like Salsa20 might be a good choice. Super simple implementation, http://en.wikipedia.org/wiki/Salsa20
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: Favorite cipher for uC implementation
« Reply #15 on: April 24, 2014, 07:43:06 am »
However preshared keys are terrible.
You will need a decent keyderivation algorithm and both sides should dynamically share a partially random number in the protocol but you already know that. Since PSK is a standard ciphersuite in TLS and DTLS I see no real problem in terms of terrible. It saves a lot of time/uC cycles and in the domain of the IoT, resource constrained devices, it can be the difference between using security in the first place.

Quote
Using ECC for key setup (ECDHE with ECDSA, a well seeded AES RNG, SHAxxx for diffusion) is going to add a lot of capability. Unlike RSA, ECC at 256bit sizes is quite doable. I've ported implementations from TinyECC to vanilla C (watch out for bugs in ECDSA mode)
Yes you are right but AFAIK at a huge cost in RAM/ROM size. If you can, will you please share some RAM/ROM and time benchmarks for your ECC implementations?
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: Favorite cipher for uC implementation
« Reply #16 on: April 24, 2014, 07:51:13 am »
Having a browse around I found these benchmarks for AES on CM0
This is a commercial library and won't include any of the overhead that goes with shifting data around, but even still I'm actually surprised that @ 24MHz they're getting >200KB/s through AES.  I thought it was going to be a lot worse than that.
Those are probably optimized for speed so large AES code.
I have implemented a very small AES version and then it takes much more time, I calculated 1kB encryption at 11ms and decryption at around 12 ms on an 120MHz Cortex M3, so about 90kB/s.
I timed an OpenSSL AES implementation 2 years ago at around ten times faster 1,1ms for 1kB so about 900kB/s on the same 120MHz Cortex M3.

As previously said it is all a balance between ROM/RAM size and speed, five times larger code: ten times the speed  ;)
« Last Edit: April 24, 2014, 07:55:17 am by Kjelt »
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26896
  • Country: nl
    • NCT Developments
Re: Favorite cipher for uC implementation
« Reply #17 on: April 24, 2014, 08:13:58 am »
More thinking of encrypting the data prior to storage, and decrypting on read.  Say something like encrypting passwords and contact info on an SD card that's loaded into the system.
If that is your goal look at the sha1 hashing algorithm. That way you can sign the data to check it's authenticity. Passwords don't need to be stored in a way they can be decrypted. Just test if the sha1 hashes of the stored password and entered password are identical.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline DrGeoff

  • Frequent Contributor
  • **
  • Posts: 794
  • Country: au
    • AXT Systems
Re: Favorite cipher for uC implementation
« Reply #18 on: April 24, 2014, 08:57:30 am »
AES or Twofish. Both work very well in small 8-bit micros, either in C or assembler.
The security value will depend on your entire system implementation, not just the algorithm.
Was it really supposed to do that?
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: Favorite cipher for uC implementation
« Reply #19 on: April 24, 2014, 09:29:12 am »
I would not recommend DES or 3DES for new designs unless they have to be backward compatible such as the case with banking systems.
 

Offline theatrus

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Favorite cipher for uC implementation
« Reply #20 on: April 24, 2014, 02:21:06 pm »
However preshared keys are terrible.
You will need a decent keyderivation algorithm and both sides should dynamically share a partially random number in the protocol but you already know that. Since PSK is a standard ciphersuite in TLS and DTLS I see no real problem in terms of terrible. It saves a lot of time/uC cycles and in the domain of the IoT, resource constrained devices, it can be the difference between using security in the first place.

Quote
Using ECC for key setup (ECDHE with ECDSA, a well seeded AES RNG, SHAxxx for diffusion) is going to add a lot of capability. Unlike RSA, ECC at 256bit sizes is quite doable. I've ported implementations from TinyECC to vanilla C (watch out for bugs in ECDSA mode)
Yes you are right but AFAIK at a huge cost in RAM/ROM size. If you can, will you please share some RAM/ROM and time benchmarks for your ECC implementations?

CM3 ROM of ECC-256+sha256+ECDHE+ecdsa+protocol bits for wireless was ~10k. RAM I don't remember. Runtime for the slowest operation (final AES shared key agreement) was 20-30 seconds @ 14MHz. Note that all communications used AES (as in TLS), but with an agreed upon ephemeral key.

RNG was using AES-CTR mode with whitened seed from the radio's RNG. In order to use ECDHE and ECDSA a very high quality RNG is a must.

Sadly I don't work there anymore, but it was a derivation of TinyECC.
« Last Edit: April 24, 2014, 02:28:52 pm by theatrus »
Software by day, hardware by night; blueAcro.com
 

Offline theatrus

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: us
Re: Favorite cipher for uC implementation
« Reply #21 on: April 24, 2014, 02:26:37 pm »

More thinking of encrypting the data prior to storage, and decrypting on read.  Say something like encrypting passwords and contact info on an SD card that's loaded into the system.
If that is your goal look at the sha1 hashing algorithm. That way you can sign the data to check it's authenticity. Passwords don't need to be stored in a way they can be decrypted. Just test if the sha1 hashes of the stored password and entered password are identical.

Straight hashes are terrible. Rainbow tables and even GPU hashers can make mincemeat out of that.

Using PBKDF#2 with a salt and as many rounds as you can tolerate is a must.

If your goal is authentication then use HMAC. Crypto is very nuanced.

SHA1 is currently "wounded", so a newer variant or even a djb hash should be looked at.
Software by day, hardware by night; blueAcro.com
 

Offline GiskardReventlov

  • Frequent Contributor
  • **
  • Posts: 598
  • Country: 00
  • How many pseudonyms do you have?
Re: Favorite cipher for uC implementation
« Reply #22 on: April 24, 2014, 04:21:08 pm »
It's a many faceted decision.  "How long is string?" Good one.

Who's eyes do you want to keep away from your data?

Locking your bike up keeps the honest people honest.

Come up with your own scheme, then alter once in a while? Will you store your code on github?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf