Skip to main content
replaced http://security.stackexchange.com/ with https://security.stackexchange.com/
Source Link

Thomas Pornin (the other bear) posted an excellent explanationexcellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

CBC mode (probably the most common) uses the output of a given cipher block to set the state for the next block, which means that state is heavily affected by the content of the previous block encrypted. This means that the presence and size of cycles (if any) would be partly determined by the plaintext being encrypted. This makes the math a little less exact, but you should expest no worse performance than with OFB mode.

TL;DR: Use CTR mode and don't bother switching keys.

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

CBC mode (probably the most common) uses the output of a given cipher block to set the state for the next block, which means that state is heavily affected by the content of the previous block encrypted. This means that the presence and size of cycles (if any) would be partly determined by the plaintext being encrypted. This makes the math a little less exact, but you should expest no worse performance than with OFB mode.

TL;DR: Use CTR mode and don't bother switching keys.

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

CBC mode (probably the most common) uses the output of a given cipher block to set the state for the next block, which means that state is heavily affected by the content of the previous block encrypted. This means that the presence and size of cycles (if any) would be partly determined by the plaintext being encrypted. This makes the math a little less exact, but you should expest no worse performance than with OFB mode.

TL;DR: Use CTR mode and don't bother switching keys.

edited body
Source Link
tylerl
  • 83.8k
  • 26
  • 154
  • 234

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

CBC mode (probably the most common) uses the output of a given cipher block to set the state for the next block, which means that state is heavily affected by the content of the previous block encrypted. This means that the presence and size of cycles (if any) would be partly determined by the plaintext being encrypted. This makes the math a little less exact, but you should expest no worse performance than with OFB mode.

TL;DR: Use CTR mode instead of CFB mode and don't bother switching keys.

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

TL;DR: Use CTR mode instead of CFB mode and don't bother switching keys.

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

CBC mode (probably the most common) uses the output of a given cipher block to set the state for the next block, which means that state is heavily affected by the content of the previous block encrypted. This means that the presence and size of cycles (if any) would be partly determined by the plaintext being encrypted. This makes the math a little less exact, but you should expest no worse performance than with OFB mode.

TL;DR: Use CTR mode and don't bother switching keys.

edited body
Source Link
tylerl
  • 83.8k
  • 26
  • 154
  • 234

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in CFBOFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

TL;DR: Use CTR mode instead of CFB mode and don't bother switching keys.

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in CFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

TL;DR: Use CTR mode instead of CFB mode and don't bother switching keys.

Thomas Pornin (the other bear) posted an excellent explanation of how encryption modes affect this aspect of your cipher. The short answer is that if you use the output of the previous block to set the state for the next block, then you run the risk of repeating yourself.

And in OFB mode in particular, you get into a loop when the pattern repeats itself. This could be a very tight loop, or there's a chance that the loop won't repeat at all until all possible values are explored. The average loop size is at N/2 bits. Specifically, with 2N total possible states, on the average, you'll run through 2N/2 of those states before repeating. Since your state counter is typically the same size as your block, then with a block size of 128 bits, on the average you'll cycle through 264 blocks (not bits, not bytes) before repeating.

Conversely, "counter mode" ("CTR") operation uses a simple counter as the cipher state. This means you're guaranteed to cycle through the entire possible space before repeating. So if your state is 128 bits, then you'll cycle through all 2128 states before repeating.

It's worth pointing out that a space that size is effectively infinite. That's about 5,000,000,000,000,000,000,000,000,000,000,000,000,000 bytes before you have to change keys. And that's with a 128-bit block; with a 256-bit block, you double the number of zeroes.

TL;DR: Use CTR mode instead of CFB mode and don't bother switching keys.

Source Link
tylerl
  • 83.8k
  • 26
  • 154
  • 234
Loading