CryptoSwift icon indicating copy to clipboard operation
CryptoSwift copied to clipboard

Use BlockCipher.blockSize as a result length in randomIV helper

Open evnik opened this issue 4 years ago • 2 comments

Checklist:

  • [ ] Correct file headers (see CONTRIBUTING.md) (not needed).
  • [x] Formatted with SwiftFormat.
  • [x] Tests added.

Changes proposed in this pull request:

Use BlockCipher.blockSize as a result length in randomIV helper. This should help to avoid two mistakes when randomIV helper is used:

  • Passing of invalid array length for IV generation.
  • Usage of randomIV helper for a key generation. Because it uses Swift.SystemRandomNumberGenerator, depending on the platform the result might be not cryptographically secure to be used as a key. Security.SecRandomCopyBytes should be preferred to generate a key on Apple platforms.

evnik avatar Oct 04 '21 06:10 evnik

@krzyzanowskim any feedback for this?

evnik avatar Oct 20 '21 02:10 evnik