I would like to attach a SRAM module to the RasPi.

My idea is to store sensitive (encrypted) data on the SD card but keep the key on a SRAM module. It would have its own backup battery (or supercapacitor) and an anti-tamper switch that would erase the contents if the enclosure was opened.

Is there any way to interface to the SRAM with only the 8 available GPIO lines?

The SRAM module itself would need a capacity of at least 128 bits (the size of the smallest AES key) but even a 1-bit wide memory would seem to require 7 address lines and one data line plus 2 or 3 control lines.

Can it be done? I am thinking it may be possible to cheat by reusing an I/O line that was designed for something else.


To install SRAM, I would suggest using an I2C/SPI module (example, instead of using the GPIO lines. Although potentially slower, it means you have the other GPIO lines for other things and your SRAM can be quite large.

There is a big disadvantage to using SRAM though. Suppose you store some really valuable information on your RPi and I'm really mean. Suppose I could hack into your RPi and run arbitrary code, then I could retrieve your key from the SRAM, which is required to decrypt the data. This is a security risk. Alternatively, you could use a AVR/PIC coprocessor, which you communicate which over I2C/SPI/UART. Instead of doing the encryption/decryption on the RPi, you would send your data to the coprocessor and ensure that there is no instruction for sending the key to your RPi. There can, however, be an instruction for generating a new key, and of course, you could have several keys stored on the coprocessor. This could make a cool little project.

  • Thanks, but the sensitive data must pass through the CPU anyway (so it is already compromised if someone gets root access to the Pi.) – finnw Jun 15 '12 at 11:55
  • I agree to an extent. If you have a password on the key, then there is no way to decrypt the data you have already stored. – Alex Chamberlain Jun 15 '12 at 12:33
  • 2
    There's no point. The data won't be any more secure there than in normal memory. Anyone who rooted the OS could get it in either place. Anyone who didn't couldn't get it in either place. – David Schwartz Jun 20 '12 at 3:49
  • @David Schwartz: The point is that (1) rooting the OS requires you to open the case (2) opening the case opens a switch that erases the SRAM. Whoever roots the OS now has access to (a) the data in main memory and flash and (b) a bunch of zeros on the external SRAM, so now they don't have the key to decrypt the flash data. Obviously we must still protect the OS from being rooted via the network (as we do already.) – finnw Jul 13 '12 at 8:45
  • 1
    Then you could use the MCP79410. It has a two pin serial interface (clock and data), 64 bytes of SRAM, and a pin for input from an external battery. Just make sure your tamper switch severs both battery and supply voltage! – David Schwartz Jul 13 '12 at 15:40

You could just use a small microcontroller to emulate the RAM over SPI or I2C.

All but the very smallest micros would have 128 bits of RAM to store the key


MSP430G2001 has 128 bytes of RAM
PIC12F508 has 50 bytes of RAM (16 bytes for key, 34 bytes free)
PIC10F202 has 24 bytes of RAM (16 bytes for key, 8 bytes free)

If you really prefer serial RAM, they also exist

23K640 is 64kbits/2.7-3.6V


You are assuming that there are only 8 gpio lines available on the Pi. In fact it is possible to have up to 17.

I don't know the details of how to access them, but you can find more information here


  • 1
    I just downvoted (I feel I should explain), because you pretty much just gave was a link, didn't explain. (I don't know whether you will appreciate this, but I denfinately like people telling my why they downvoted.) – ACarter Jun 18 '12 at 18:01
  • I thought knowing you can get more than 8 io lines is pretty useful, but I appreciate the comment – David Sykes Jun 19 '12 at 3:29

You can use I2C SRAM modules, like the PCF8570P £1.50ish 256x8Bit SRAM. It operates between 2.5V and 6.0V, has a power saving mode that draws as little as 50nA and can be stacked to create more RAM if needed.

Hook it up to I2C directly or to a Master for multiple I2C device. Only uses 2 GPIO, Power and Negative, with the option of MCU power off RAM retention using a small battery.

enter image description here

Alex Chamberlains security concern should be taken seriously if you wanted to protect the Private Key. Possibly thinking about creating some kind of isolation in your code which requires escalation to access to the SRAM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.