Shop OBEX P1 Docs P2 Docs Learn Events
AES-128 in PASM — Parallax Forums

AES-128 in PASM

ericballericball Posts: 774
edited 2012-01-27 20:20 in Propeller 1
Attached is a functioning AES-128 implementation in PASM (with just enough SPIN to set the pointer to the SBox & InvSBox lookup tables).

1. I have tested it (successfully) against the FIPS-197 example using GEAR V09_10_26. (Note: this is the Data and Key in the file, output in istate.)
2. It is not a complete driver, it just encrypts & decrypts data loaded with the PASM and leaves that data in the COG. Adding data movement (along with the steps needed to support multi-block modes) is left to the implementor.

ObEx licensed, although I'll wait for some feedback before adding it to ObEx.

Performance: Key Expansion ~4.4K cycles, Cipher ~16.1K cycles/block, Inverse Cipher ~18K cycles/block.

Comments

  • ericballericball Posts: 774
    edited 2010-09-02 08:37
    I have updated the code with the Inverse Cipher function, so the code is now effectively complete.

    Note: it is possible to modify the code to support AES-192 and AES-256 (or non-AES Rijndael, i.e. different block sizes) but care must be taken. In particular, KeyExpand assumes Nk is divisible by 4 (not true for AES-192).
  • Bill HenningBill Henning Posts: 6,445
    edited 2010-09-02 09:52
    Nice work eric, this will be useful.
  • DestructinatorDestructinator Posts: 34
    edited 2010-09-10 23:24
    Wow, Im glad to see that someone was able to finish this system. I am impressed. I also lacked all the knowledge and materials to complete the task, but again, Wow. Great work. Keep it up
  • hinvhinv Posts: 1,255
    edited 2010-09-18 11:38
    Wow, this is impressive! If I am calculating this correctly, at 80MHz it encrypts at 621KB/sec and decrypts at 555KB/Sec. Am I understanding this correctly?
    I don't know what the Key Expansion is, but I would assume that for AES-256 it would take longer than 4.4Kcycles.
    Do you have any demos available. What would be really neat is an app that took a file off the SDcard and encrypted it and wrote it back. Then we could verify the coding on another computer.

    Thanks for your hard work,

    Doug
  • ericballericball Posts: 774
    edited 2010-09-18 13:08
    Key Expansion in AES-128 takes the initial 128 bit key and expands it to 1408 bits (11 * 128) which is then XOR'd into the current state after each round of encryption (10 rounds + initial XOR). AES-192 & AES-256 have a 192 & 256 bit keys and use more rounds for more secure encryption* (in theory, in reality it's more like secure for your lifetime, the lifetime of the sun, or the lifetime of the universe).

    Each block is 128 bits or 16 bytes. 80M * 8 / 16.1K = 77.6Kbyte/s encrypt, 69.4Kbyte/s decrypt.


    * AES-128 should be secure enough for almost any possible use. The real issue is keeping the key (and the initalization vector) secret.
  • hinvhinv Posts: 1,255
    edited 2010-09-18 21:21
    For the key reason, I would certainly like to see some pgp encryption for the prop. I have no idea how this would be implemented, or if it is even possible. Because it is a dual key method, it is easier to keep the secret key secret. How to implement it is way over my head though, and probably takes way more cycles than would be practical on the prop I....but it would be nice.

    I mistook the blocks to be 128Bytes instead of 128bits, hence my calculation is way off.

    Thanks,
    Doug
  • wiebelwiebel Posts: 7
    edited 2012-01-18 15:32
    This coould open a Door to a basic ssh Server on the Spinneret although this will still be a long way. It would be awsome.
  • Mark_TMark_T Posts: 1,981
    edited 2012-01-18 18:41
    RFC5656 is entitled "Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer" which is interesting - I'm currently playing with implementing ECC on the Propeller in some form incidentally :)
  • Mark_TMark_T Posts: 1,981
    edited 2012-01-27 20:20
    hinv wrote: »
    Wow, this is impressive! If I am calculating this correctly, at 80MHz it encrypts at 621KB/sec and decrypts at 555KB/Sec. Am I understanding this correctly?
    I don't know what the Key Expansion is, but I would assume that for AES-256 it would take longer than 4.4Kcycles.
    Do you have any demos available. What would be really neat is an app that took a file off the SDcard and encrypted it and wrote it back. Then we could verify the coding on another computer.

    Thanks for your hard work,

    Doug
    Nothing like that speed I'm afraid, 16100 cycles is about 200us per block, 16 bytes to the block so about 80kB/second...

    I've been inspired (by this and other things) recently to look at AES and have put together a more fully featured AES object with 128/192/256 bit key support and CBC mode as well as ECB. Eric's code has been one of the inspirations (but I'm also doing java versions for other systems and getting close to an Elliptic Curve Cryptography object for the Prop).

    Its just "AES" in the ObEx, and comes with test code to generate test-vectors (that for me all agree with the official NIST results).
Sign In or Register to comment.