element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Blog RC6 cipher implemented in Verilog
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join FPGA to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: misaz
  • Date Created: 5 Aug 2022 6:23 PM Date Created
  • Views 1089 views
  • Likes 3 likes
  • Comments 0 comments
  • arty-s7
  • 7 Ways to Leave Your Spartan-6
  • xilinx
  • rc6
  • fpga
  • vivado
  • crypto
  • spartan-7
  • encryption
  • Spartan_Migration
Related
Recommended

RC6 cipher implemented in Verilog

misaz
misaz
5 Aug 2022

Hello everyone. I welcome you to this blog post describing my project as part of 7 Ways to Leave Your Spartan-6 FPGA contest.

In this blog post I will describe my core project as part of this competition. As part of this competition I originally promised different project as part of which I made PCB for connecting camera to the ARTY S7 board, but I did several mistakes including connecting wrong power supply to the camera which was not very easy to patch, so I decided to change my project and implement different (I hope still interesting!) project.

As part of this competition I decided to utilize some skills from university and implement block cipher encryption in the hardware. Common and very popular block cipher is AES, but there are plenty of AES implementations on the internet, so I decided to implement different one. I chosen RC6.

RC6

RC6 was candidate to being selected as worldwide standard nowadays referred as AES but cipher named Rijndael was selected as this standard. AES have some advantages over it.

Similarly, to AES it works over blocks of data. Standard do not specify exact size of data and you can implement whatever site you want, but most implementations use 32-bit data size. Similarly, this cipher is flexible in terms of key length and many keys are possible.

FPGA Implementation

Following image show block diagram of my solution.

image

The most important block rc6_engine is the block which is responsible for encryption. It strongly depends on block responsible for key scheduling operation. Engine can encrypt one block at time. A, B, C and D are 32-bit registers for data. In is used as input for encryption and OUT are used for outputting encrypted data. RC6 encryption do not use key directly, instead it relies on some pre-processed key, which in fact has different length than original key. For this pre-processing of key there are key_scheduler block which is responsible for this operation and acts as a memory for the engine. Engine set index of key bate using S_addr signal and key-scheduler outputs pre-processed key byte.

As you can see on the image interface to the circuit is using UART with baudrate 115200 which is derived from input clock of 12 MHz which is available on Arty S7 board. Controller process data from the UART, passes data between data registers and control triggering of key scheduling and encryption operations.

RC6 encryption is implement using automata iterating over required number of rounds (which is dynamically configurable). Some operations are split for reducing critical path in arithmetic operations which are done as part of RC6 cipher.

UART Interface

Device communicates over standard UART (baudrate=115200, parity=no, stop_bits=1) interface and communication is based on commands and replies. Every command is initiated by transmitting 1-byte opcode and optional data payload. Device reply to every command with status code or output data. After reset device transmits status code STS_INIT_OK (0x45) indicating that the device is ready to process data. Device supports following 4 commands.

Commands

  • CMD_SET_ROUNDS (0b010aaaaa, aaaaa is number of rounds): Command is used for setting number of rounds used when scheduling key and encrypting data. Number of rounds is encoded into opcode and command has no data payload. Device reply status code STS_SET_ROUNDS_OK and no output data.
  • CMD_SET_KEY (0b10aaaaaa, aaaaaa is key length in bytes): Sets n bytes of key. Number of key bytes is encoded as part of opcode. Key bytes are transmitted after transmitting opcode. After receiving last byte of key device start key scheduling process. Device reply with status code STS_SET_KEY_OK after completing key scheduling process. Do not issue any command to the device between transmitting last key byte and receiving STS_SET_KEY_OK status code. Issuing any command to the device when device is scheduling key tend to undefined behaviour and may harm key scheduling process.
  • CMD_SET_ABCD (0b00000000): This command is used to transmit input data for encryption. This command requires 16-byte payload. First four bytes are used as input for A register in RC6 cipher, 5th to 8th bytes are used as input for B register and so on. Transmitted register values are treated as little-endian. Device replies with status code STS_SET_ABCD_OK receiving 16th byte of input data and output has no payload.
  • CMD_ENCRYPT (0b00000001): This command starts encryption of previously transmitted input data. After completing encryption process device will respond no status code, but outputs 16 bytes of encrypted data. Do not issue any command to the device between issuing CMD_ENCRYPT and receiving output data. Issuing any command to the device when device is encrypting tend to undefined behaviour and may result into invalid encryption results.

Status codes

Possible status codes are:

STS_SET_ROUNDS_OK (0x43): Device send this code after successful processing of CMD_SET_ROUNDS command.

STS_SET_KEY_OK (0x42): Device send this code after successful scheduling of previously transmitted key as part of CMD_SET_KEY command.

STS_SET_ABCD_OK (0x44): Device send this code after successful processing of data CMD_SET_ABCD command. Note that CMD_SET_ABCD does not encrypt transmitted data. Issue CMD_ENCRYPT command to encrypt data previously transmitted by CMD_SET_ABCD command.

STS_INIT_OK (0x45): Initialization completed. This code does not result from any command. Device sends it after reset.

Implementation

I wrote whole project in Verilog and did not depend on any other part. In fact, I used Vivado very basically in this project. I did not used any block diagram because this project does not rely on any system part. Instead of I just created Verilog (SystemVerilog) files and one constraint file for mapping pins to the signals. Final utilization is quite a large when you take in account that it is not a very complicated circuit. It is because I implemented all registers including expanded key storage using registers. Consequently, design consumes 12% of available LUTs and 5% of Flip Flops. Vivado synthesis also utilized 6 DSP blocks, most probably for some arithmetic operation as part of cipher.

image

Testing

Because interface is mostly binary, I implemented simple utility in VB.NET which can communicate with device and send encoded commands to the device and read responses from device.

image

Summary

This is all from my blog post describing my project implemented on the Arty S7 platform. In this blog I descfibed my main project as part of 7 Ways to Leave Your Spartan-6 FPGA. Thank you for reading this blog.

 

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube