30519

48-bit blowfish

Question:

Is there an implementation (Java/C++/Ruby) of a Blowfish algorithm that supports 48-bit data blocks? I have an encryption problem where the input and output channels are exactly 48-bits. All implementations on the net are for 64-bit blocks.

Answer1:

That's because <a href="http://en.wikipedia.org/wiki/Blowfish_%28cipher%29" rel="nofollow">Blowfish</a> has a set block size of 64-bits. You could pad two random bytes to the end of your data.

require 'rubygems' require 'crypt/blowfish' blowfish = Crypt::Blowfish.new("A key up to 56 bytes long") plain="123456" encryptedBlock = blowfish.encrypt_block(plain+(rand(250)+5).chr+(rand(250)+5).chr)

or if your plain could be less than 6 bytes / 48 bits

encryptedBlock = blowfish.encrypt_block(plain.ljust(8))

Answer2:

You could use <a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29" rel="nofollow">counter-mode</a> with blowfish. Just remember never to reuse any counter-value.

Just select a counter (it will need to be unique across all encryptions with the same key), pad the counter to 64 bits and encrypt the padded counter. Then XOR the first 48 bits of this encryption with your plaintext to gain the ciphertext. Repeat the operation on the ciphertext to decrypt.

The only problem is finding a suitable counter. If you include it with the ciphertext, you need more than 48 bits. Perhaps you have a session-id or something you can use?

Answer3:

I recommend using RC4-drop 1024. RC4 is a stream cipher so you can encrypt an arbitrary size, if the message is less than 48bytes, then you can pad it with nulls. Drop 1024 means you throw away the first 1024 bytes of PRNG stream, to do this you can encrypt 1024 bytes of junk the first time you use it.

BitTorrent's Message Stream Encryption uses RC4-drop 1024 and here is a python implementation using the ARC4 library:

<a href="http://google.com/codesearch/p?hl=en#4FSOSMZ6Pxc/distfiles/BitTorrent-5.0.7.tar.gz|eyN-AXYL_0E/BitTorrent-5.0.7/BitTorrent/Connector.py&q=lang:python%20%22ARC4.new%22" rel="nofollow">http://google.com/codesearch/p?hl=en#4FSOSMZ6Pxc/distfiles/BitTorrent-5.0.7.tar.gz|eyN-AXYL_0E/BitTorrent-5.0.7/BitTorrent/Connector.py&q=lang:python%20%22ARC4.new%22</a>

Recommend

  • Hashing password in register and login do not match [duplicate]
  • Blowfish ECB Mode in BouncyCastle
  • Linux: CPU benchmark requiring longer time and different CPU utilization levels
  • IRC blowfish encryption mode?
  • Rails New SampleApp Hangs forever after Run Bundle Install
  • Unwanted scaling on mobile devices
  • Create Function to replace index in string with index in list, then save those values into an HTML f
  • Xcode openURL doesn't read link
  • Automatic string resources translate
  • Php, socket and connecting to pop3-server [duplicate]
  • How can I play audio stream without saving it into the file with pyglet?
  • Python CSV file UTF-16 to UTF-8 print error
  • How to do sub-sorting in python?
  • How to receive a call from GSM Modem
  • Data signatures using Perl
  • Pony yandex.ru and mail.ru specifics
  • Find and replace over multiple lines using sed in Xcode Run Script bin/sh
  • Server Socket errno 57 - Socket is not connected
  • How to install the guess_language package in Python
  • passenger config.ru permission denied
  • Ruby Rack Heroku: Serving Static Files
  • Carbon locale format and decline
  • How to apply a texture to THREE.ExtrudeGeometry?
  • X509Certificate2 p12 is store required?
  • Getting access to a binary response byte-by-byte in classic asp/JScript
  • PHP Script in my Wordpress Files. Please Decode or Help Me Remove it [closed]
  • How do I stop js files being cached in IE?
  • Towers of Hanoi with “counter” in python
  • Why Is jQuery Not Submitting This Form? (Or What Have I Done Wrong? :-p)
  • How to generate random events in android?
  • RewriteCond and rewriteRule to redirect depending on the domain
  • Yii: any way to save the images in compressed form?
  • How do I make openssl_encrypt pad the input to the required block size?
  • How can I tell Phusion Passenger which python to use?
  • How can I let users share their location in Bot Framework webchat channel?
  • Inversing an interpolation of rotation
  • HttpURLConnection Closing IO Streams
  • How to 'create temp table as select' in Slick?
  • Parsing a CSV string while ignoring commas inside the individual columns
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword