Information Security Stack Exchange is a question and answer site for information security professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After accepting an answer to my previous question, I am beginning to have doubts.

I want to updating pricing information in vending machines by inserting an SD card with new pricing.

I have to encrypt the file, because anyone who can change it can get one cent drinks. The people who stock the machines would exchange the cards when there is new pricing. They are on minimum wage and generally not renowned hackers, but could, I suppose, pass a card on.

The SD card would be behind a locked casing and anyone who opened that could just clean out the cash box & would probably be unlikely to swipe the card.

The code in the machines is rarely changed, but there will be an option for firmware upgrade (via the same SD card), so I suppose I could update keys that way if they become compromised & store them in NonVolatile memory.

Each machine has a unique CPU Id and also is aware of its model type “drinks, candy, etc” where all machines of the same type have the same pricing structure – if that is of any use for seeding, etc

Question: what’s a good algorithm to use when I am writing in Delphi on Windows and reading in C on a low memory (128kB) embedded system (the file is likely ot be of the order of 512 to 1,024 bytes)? How to deal with keys in this scenario? Hard code into the s/w?

Any other comments or suggestions?

share|improve this question
How many price updates do you assume there'll be in a year (or between each firmware upgrade), and how much storage is available in the vending machine? I'm thinking One-Time Pad! – Henning Klevjer Nov 7 '12 at 7:41
+1 @HenningKlevjer I don't expect more than 2 or 3 updates per year. teh f/w is new & likely to be buggy at first so an inital slew of f/w upates trailing off to none within the frist year ... ? – Mawg Nov 7 '12 at 7:59
up vote 6 down vote accepted

I have to encrypt the file, because anyone who can change it can get one cent drinks.

Encryption is used for confidentiality - to prevent unauthorized parties from reading the file. Since your goal is to prevent people from changing the file what you need is a digital signature.

There are two kinds of digital signatures: asymmetric signatures and symmetric signatures.

When using a symmetric signature the side checking the signature needs to have the same secret key used by the signer. In your case this means that the secret key needs to reside in the machine's firmware which sits on the same SD card as the file your trying to protect. Not very secure.

When using an asymmetric signature the side checking the signature (i.e. the vending machine) has a public key and doesn't have the private key needed to sign a file, which solves the above problem.

But this is still trivial for an attacker to break. Since the firmware if on the SD card, and we're assuming the attacker can modify the SD card, the attacker can simply modify the firmware so that it doesn't check the signature.

The ideal solution for this would be if the vending machine's hardware (e.g. BIOS) would validate a signature on the firmware before loading it. There are embedded devices in the world that do this (e.g. game consoles, mobile device) but vending machines are not one of them.

Given the lack of a firmware signature check there is no way to achieve real security for this. The best you could do is obfuscate the code so that it would be more difficult for a hacker to reverse engineer and modify.

If you have good reason to believe that attackers cannot modify the firmware then all you need to do is sign the file using RSA with PKCS#1 padding (which is good enough for your needs). Delphi code for this can be found in TurboPower LockBox; OpenSSL has C code.

Having said all that, there doesn't seem to be much of a threat here. If an operator lowers the price for a specific machine then you should be able to identify the discrepancy for that machine between the amount of drinks that were put into the machine and the amount of money that you got out of it. This is something you need to check anyway to ensure that the machine operators aren't simply taking money (which is clearly a more severe threat than stealing a few drinks).

share|improve this answer
+1 @DavidWachtfogel I take your point about wanting to prevent tampering, not reading - but can't I do both? I think I didn't explain well - the firmware is on a microprocessor in the machine and runs from there. If I need to load new f/w then, yes, it comes from the SD card, but is an encrypted exe & hard to hack (I hope). I take your point about auditing & there will be a lot ofback end s/w associated with the sales databse. Thansk for your feedback. What do you suggest, in concrete terms? – Mawg Nov 7 '12 at 8:02
Seeing as the last question from @Mawg asks for "just good enough" and "security through obscurity", I'd assume that an attacker was not able to modify firmware. – Henning Klevjer Nov 7 '12 at 8:36
If you assume that the attacker cannot modify the firmware then all you need to do is sign the file using RSA with PKCS#1 padding (which is good enough for your needs). has Delphi code for this; OpenSSL has C code. Since the information in the file (prices) is not secret there's no reason to encrypt the file. – David Wachtfogel Nov 7 '12 at 9:13
Don't be so sure about attackers not modding your firmware. Vending machines (and similar devices) can often be pwned via buffer overflows on all sorts of easily accessible interfaces. – Polynomial Nov 7 '12 at 10:34
+1 @Polynomial You intrigued me so much that I asked a new quesstion. Please see… – Mawg Nov 8 '12 at 2:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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