netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: linux@horizon.com
To: ak@muc.de, linux@horizon.com
Cc: arjan@infradead.org, bunk@stusta.de, chrisw@osdl.org,
	davem@redhat.com, hlein@progressive-comp.com,
	linux-kernel@vger.kernel.org, netdev@oss.sgi.com,
	shemminger@osdl.org, Valdis.Kletnieks@vt.edu
Subject: Re: [PATCH] OpenBSD Networking-related randomization port
Date: 12 Feb 2005 23:25:18 -0000	[thread overview]
Message-ID: <20050212232518.10838.qmail@science.horizon.com> (raw)
In-Reply-To: <m11xblif93.fsf@muc.de>

> linux@horizon.com writes:
>> (The homebrew 15-bit block cipher in this code does show how much the
>> world needs a small block cipher for some of these applications.)
>
> Doesn't TEA fill this niche? It's certainly used for this in the Linux
> kernel, e.g. in reiserfs (although I have my doubts it is really useful
> there) 

Sorry; ambiguous parsing.  I meant "(small block) cipher", not "small
(block cipher)".  TEA is intended for the latter niche.  What I meant
was a cipher that could encrypt blocks smaller than 64 bits.

It's easy to make a smaller hash by just thowing bits away, but a block
cipher is a permutation, and has to be invertible.

For example, if I take a k-bit counter and encrypt it with a k-bit
block cipher, the output is guaranteed not to repeat in less than 2^k
steps, but the value after a given value is hard to predict.

There is a well-known technique for reducing the block size of a cipher
by a small factor, such as from a power of 2 to a prime number
slightly lower.  That is:

unsigned
encrypt_mod_n(unsigned x, unsigned n)
{
	assert(x < n);
	do {
		x = encrypt(x);
	} while (x >= n);
	return x;
}

It takes a bit of thinking to realize why this creates an bijection from
[0..n-1] -> [0..n-1], but it's kind of a neat "aha!" when it does.

Remember, encrypt() is a bijection from [0..N-1] -> [0..N-1] for some
N >= n.  Typically N = 2^k for some k.

However, this technique requires N/n calls to encrypt().  I.e.
n calls to encrypt_mod_n() will cause N calls to encrypt().

It's generally considered practical up to N/n = 2, so we can encrypt
modulo any modulus n if we have encrypt() functions for any N = 2^k a
power of 2.  I.e. a k-bit block cipher.

For example, suppose we want to encrypt 7-digit North American telephone
numbers.  These are of the form NXX-XXXX, where N is a digit other than
0 or 1, and X is any digit.  there are 8e6 possibilities.  Using this
scheme and a 23-bit block cipher, we can encrypt them to different valid
7-digit telephone numbers.

Likewise, 10-digit number with area codes, +1 NXX NXX-XXXX (but not
starting with N11) are also possible.  There are 792 area codes and
8e6 numbers for a total of 7776000000 < 2^33 combinations.

This sort of thing is very useful for adding encryption to protocols and
file formats not designed for it.


However, the standard literature is notably lacking in block ciphers
in funny block sizes.  There was one AES submission (The Hasty Pudding
Cipher, http://www.cs.arizona.edu/~rcs/hpc/) that supported variable
block sizes, but it was eliminated fairly early.


To start with, consider very small blocks: 1, 2 or 3 bits.
There are only two possible things encrypt() can do with a 1-bit value:
either invert it or leave it alone.

There are 4! = 24 possible 2-bit encryption operations.  Ideally, the
key should specify them all with equal probability, but 24 does not
evenly divide the (power of 2 sized) keyspace.  It is interesting to
look at how iniformly the possibilities are covered.

It's fun to consider a Feistel network, dividing the plaintext into 1-bit
L and R values, and alternating L ^= f(R), R ^= f(L) for (not nexessarily
invertible) round functions f.  Since there are only 4 possible 1-bit
functions (1, 0, x and !x), you can consider each round to have an
independent 2-bit round subkey and see how the cipher's uniformity
develops as you increase the number of rounds and the key length to go
with it.

There are 8! = 40320 3-bit encryption operations.  Again, all should be
covered uniformly.  An odd number of bits makes a Feistel design more
challenging.  But if you don't allow odd numbers of bits, you have to push
the shrinking technique it to N/n = 4, which starts to get unpleasant.

  reply	other threads:[~2005-02-12 23:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1106932637.3778.92.camel@localhost.localdomain>
     [not found] ` <20050128174046.GR28047@stusta.de>
     [not found]   ` <1106934475.3778.98.camel@localhost.localdomain>
2005-01-28 18:18     ` [PATCH] OpenBSD Networking-related randomization port Stephen Hemminger
2005-01-28 18:54       ` Lorenzo Hernández García-Hierro
     [not found] ` <20050128100229.5c0e4ea1@dxpl.pdx.osdl.net>
2005-01-28 18:31   ` Lorenzo Hernández García-Hierro
2005-01-28 18:52     ` Stephen Hemminger
2005-01-28 18:58       ` Lorenzo Hernández García-Hierro
2005-01-28 20:34       ` Lorenzo Hernández García-Hierro
2005-01-28 20:45         ` David S. Miller
2005-01-28 21:34           ` Stephen Hemminger
2005-01-28 21:45             ` David S. Miller
2005-01-29  6:59             ` Andi Kleen
2005-01-28 20:47         ` Arjan van de Ven
2005-01-28 22:12           ` Lorenzo Hernández García-Hierro
2005-01-29  8:04             ` Arjan van de Ven
2005-01-29  8:05             ` Arjan van de Ven
2005-01-29  9:15           ` Valdis.Kletnieks
2005-01-31 16:50             ` Adrian Bunk
2005-01-31 17:23               ` Lorenzo Hernández García-Hierro
2005-01-31 20:11                 ` Ingo Molnar
2005-01-31 23:27                   ` linux
2005-02-12 22:29                     ` Andi Kleen
2005-02-12 23:25                       ` linux [this message]
2005-02-13  0:18                         ` Roland Dreier
2005-02-13  1:41                           ` linux
2005-02-02 17:17                   ` linux
2005-02-02 17:38                     ` Lorenzo Hernández García-Hierro
2005-02-03 19:51                       ` Stephen Hemminger
2005-02-03 20:14                         ` Lennert Buytenhek
2005-01-31 19:42               ` Valdis.Kletnieks
2005-01-31 20:03                 ` Lorenzo Hernández García-Hierro
2005-02-01 23:22                   ` Matt Mackall
     [not found] ` <1106935677.7776.29.camel@laptopd505.fenrus.org>
2005-01-28 18:36   ` Lorenzo Hernández García-Hierro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050212232518.10838.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=ak@muc.de \
    --cc=arjan@infradead.org \
    --cc=bunk@stusta.de \
    --cc=chrisw@osdl.org \
    --cc=davem@redhat.com \
    --cc=hlein@progressive-comp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@oss.sgi.com \
    --cc=shemminger@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).