0

The javax crypto blowfish counter increment function seems to be fixed ( standard inc by 1? ).

(a) How to change the increment function, say by 4?

(b) Could "increment" be achieved by manipulating IV values?

We could write code on top of ECB but at this moment we try to stay within java security and javax crypto without writing our own version of CTR.

MORE INFO:

We want our java code increments not by 1 in order to match outputs from a legacy program which doesn't increment by 1, but by another input parameter from the caller function. So, increment by value other than 1 is non-standard? maybe invalid?

Thanks in advance.

1 Answer 1

1

Standard CTR always uses increment by 1 and is considered to be secure as long as you always use a different random IV for every encryption: NIST-paper

Why?

Generally there is absolutely no security difference in incrementing the counter by 1 or by, say 8.

The main reason for using increment by 1 is the fact that CTR is only secure as long as the key-stream does not repeat.

When using CTR with 16 byte counter; increment by 1; 16 bytes blocks you can encrypt the full counter space (2^(16*8)) of blocks before that happens. When using increment by another number (for example 8), the stream does only allow you to encrypt an 1/8 of the counter space
(2^(16*8) / 8).

Generally when using an incremental value of k * 2^s then it will only cover 1 / 2^s of the counter space before it starts repeating. (It will also cover the whole counter-space if you increment by an odd value though.)

In addition you would have to store the incremental value for every encryption somewhere, so you know which to use for decryption.
(I assume that addition is also marginally slower than simple incrementation by 1.)

So all in all there basically is no reason to use an increment by more than 1 since it only provides (usually not very crucial but still) some disadvantages. I think that is probably the reason why the standard Java-API does not provide this feature.


I guess implementing the function by yourself will possibly be the best solution in case you really require that feature ...

4
  • Our java code increments not by 1 in order to match outputs from a legacy program which doesn't increment by 1, but by another input parameter from the caller function. So, increment by value other than 1 is non-standard? maybe invalid? Jul 28, 2014 at 20:59
  • Ah okay, you didn't state that in your question. I edited my answer to provide an explanation for why increment by 1 is used and a added a reference to the official CTR specification.
    – i_turo
    Jul 28, 2014 at 21:51
  • @i_turo: your math is a little bit off. It's not 1/234 of the counter space, its actually 1/2 of the counter space. In general, if you counter increments by k*2s every step then it will only cover 1/2s of the counter space before it repeats. This, any odd counter increment will cover the entire counter space before repeating. Jul 28, 2014 at 23:29
  • @GregS: Tanks for the correction. I have updated and corrected my answer with your info.
    – i_turo
    Jul 29, 2014 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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