Skip to content

cipher.final should not be required for streaming ciphers #5772

Closed

Description

@kreynolds

Environment

Provide at least:

  • jruby 9.2.6.0 (2.5.3) 2019-02-11 15ba00b OpenJDK 64-Bit Server VM 11.0.2+9 on 11.0.2+9 +jit [darwin-x86_64]
  • Darwin Kelleys-MBP.neo.rr.com 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

Expected Behavior

  • OpenSSL::Cipher.new('aes-256-ctr') should not require cipher.final for streaming ciphers

Actual Behavior

  • It requires cipher.final to get the trailing bytes

Sample script

require 'openssl'
require 'securerandom'

# String which will have 4 trailing bytes
string = 'a'.b*20

cipher = OpenSSL::Cipher.new('aes-256-ctr')
cipher.iv = SecureRandom.random_bytes(16)
cipher.key = SecureRandom.random_bytes(32)

# str should be 20 bytes long
puts cipher.update(string).size

# In MRI
# => 20
# In JRuby
# => 16

Activity

  1. shibz commented on Jun 27, 2019

    @shibz
    Contributor

    cipher.update and cipher.final have different behavior in JRuby vs MRI for block ciphers also when data is added in KEY_LENGTH sized chunks.

    require 'openssl'
    require 'securerandom'
    
    KEY_LENGTH = 16
    
    cipher = OpenSSL::Cipher.new("AES-128-CBC")
    cipher.encrypt
    cipher.key = SecureRandom.random_bytes(KEY_LENGTH)
    
    puts cipher.update(SecureRandom.random_bytes(KEY_LENGTH)).length
    
    # MRI = 16
    # JRuby = 0
    
    puts cipher.final.length
    
    # MRI = 16
    # JRuby = 32
    
  2. headius commented on Jul 9, 2019

    @headius
    Member

    This might get more responses if filed with https://github.com/jruby/jruby-openssl but copying @kares here so everyone relevant sees it.

  3. kreynolds commented on Jul 10, 2019

    @kreynolds
    Author

    Ah .. I didn't realize that was a separate thing. I refiled there and will close this issue.

  4. added this to the Invalid or Duplicate milestone on Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions