# Block cipher to encrypt 8 bytes/64 bits - Use 64 or 128 bit cipher?

Here's the problem: I have a transport stream that I have been requested to encrypt between the transmitter and receiver. The data size is at most 8 bytes so it seems I can only use ECB as I only have a single block - the most I can do is pad to 8 bytes if its less, which I intend to do with random data (the receiver can figure out the correct length from the decrypted data).

I've been looking for 64-bit ciphers and came up with the most popular: DES, 3DES, TEA, XTEA, XXTEA, Blowfish. I've discounted DES, 3DES and Blowfish due to their code size (not enough space to implement it, and concerns over speed of encryption/decryption on the embedded platform we are using)

I'd rather not use TEA, as it seems insecure from what I've read.

Is there another 64-bit cipher that is more secure than TEA, but doesn't require lots of code space plus lots of constant data like Blowfish does?

Is it possible to use a 128-bit cipher and "trim" the result to 64-bits?

• you can easily trim if you use CTR mode, but not ECB, which is a very bad idea – Richie Frame Nov 16 '14 at 11:24
• If you want compact 64-bit block cipher, I would suggest Speck or RC5. XTEA should also be fine, but you have to be careful with key management (as always). – LightBit Nov 16 '14 at 12:40
• If you use a block cipher in ECB mode, the same plaintext will always lead to the same ciphertext, allowing to detect if the same plaintext is sent twice, which is against the security goals assigned to a cipher, and why good block ciphers operating modes use IVs. $\;$ Also: it would not be the first time when "requested to encrypt" should be understood as also requested to protect against malicious alteration. $\;$ Before choosing the block size of the cipher, find your goals, and what cipher or/and MAC or/and authenticated encryption you want to use. – fgrieu Nov 16 '14 at 14:29
• What are your actual security requirements? As everyone is pointing out, you've already made some very questionable decisions so what are you trying to accomplish? Confidentiallity? Replay protection? Integrity? Please fill us in with as much detail as possible. – Thomas M. DuBuisson Dec 16 '14 at 18:03
• I've voted to close this question as you haven't responded to the questions asking for the security requirements and use case. Without that there are too many options / answers possible. – Maarten Bodewes Sep 6 '15 at 12:17

You can safely use ECB if all of the following conditions are met:

• Your messages can be unambiguously encoded in a form with a fixed size which is equal to the cipher's block size. For example, your messages all have the same size which is smaller than the block size, or they're all smaller than the block size and they never have trailing null bytes.
• You only need message confidentiality, not authenticity or integrity (i.e. you don't need to protect against an attacker who might modify the message in transit, possibly without knowing its content).
• You don't mind that an observer can tell if you're sending the same message twice.

Even if you don't think you need authenticity or integrity checks, carefully consider the design of the whole system. What happens if an adversary submits fake messages (either made from whole cloth, or modifications of legitimate messages)? What happens if an adversary resubmits a previous message after having observed its effect?

If the messages are all produced and received by the same entity, and the sender and the receiver can agree on some kind of message identifier (e.g. a number that is incremented for each message), then there's a better mode: counter mode (CTR). CTR has several advantages:

• By mixing the message number into the encryption, messages with identical content have distinct, unlinkable ciphertexts.
• CTR turns a block cipher into a stream cipher, so you can send the exact number of bytes (of bits, even) that matches the length of the message.
• CTR requires only encryption on both sides, never decryption, which can same a tiny bit of code size.

CTR only works if the sender and the receiver agree on the initial counter value for each message. Usually the initial counter value is sent as a prefix of the ciphertext, but if you already have a unique identifier for the message, you can repurpose it.

CTR requires distinct counter values for each block of all messages. For messages that are shorter than the block length, this requirement simplifies to not reusing a counter value for different messages.

Note that CTR does not help with message integrity. It even makes it trivial to make predictable changes to the ciphertext without deciphering it (flipping a bit in the ciphertext flips the corresponding bit in the plaintext).

You cannot trim a block-cipher. It is against the security requirements, avalanche effect.

Also, when you talk about security, especially for the DES, you should mention the level. For example the DES can be attacked by the brute-force with a known-plaintext in a single day.

http://www.sciengines.com/company/news-a-events/74-des-in-1-day.html

• You cannot trim a block-cipher. It is against the security requirements, avalanche effect. – I didn´t down-vote, but that´s wrong. You can trim a block-cipher… just like you can trim a crypto-secure hash. Trimming doesn´t have a negative effect on security requirements or the avalance effect. The strict avalanche criterion (SAC) is satisfied if, whenever a single input bit is complemented, each of the output bits changes with a 50% probability. This can also be expected of trimmed outputs… which is why we consider a trimmed crypto-secure hash to still be cryptographically secure. – e-sushi Jun 19 '15 at 4:43
• When trimming, ı'd consider the design change. – kelalaka Jan 23 '16 at 21:29
• In that case I’m curious how you’ld explain how block ciphers maintain security when using them (for example) in modes like CTR – which practically turns block ciphers into a stream cipher and is well vetted in its security. (As Gilles explained in his answer – CTR mode makes most sense in the scenario the question describes.) See… when trimming, you trim the output of the block cipher, not some internal functionality. If you would fiddle with the internal functionality, that would be a design change. But no one would want to mess with the internals in the first place. Hope that helps… – e-sushi Jan 23 '16 at 22:59
• CTR mode is a scheme. It also requires analysis. – kelalaka Jan 24 '16 at 0:51
• Such analysis exists. In short: stream cipher output (which includes using block ciphers in CTR-mode) can be truncated. The only issue (depending on the individual scenario) is that CTR mode is not secure against chosen-ciphertext attacks. Yet, same goes for the other classic block cipher modes of operation too so that’s no surprise. It’s pretty common knowledge that you need authenticated encryption (eg: CTR mode encryption + HMAC) to protect against a chosen-ciphertext attacks. (hint: “encrypt-then-mac”) – e-sushi Jan 24 '16 at 10:20