File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -614,7 +614,11 @@ public int getIvLength() {
614614 getKeyLength ();
615615
616616 if ( ivLength == -1 ) {
617- if ( "AES" .equals (base ) ) {
617+ // ECB mode does not use an IV, so check this first
618+ if ( "ECB" .equals (mode ) ) {
619+ ivLength = 0 ;
620+ }
621+ else if ( "AES" .equals (base ) ) {
618622 ivLength = 16 ; // OpenSSL defaults to 12
619623 // NOTE: we can NOT handle 12 for non GCM mode
620624 if ( "GCM" .equals (mode ) || "CCM" .equals (mode ) ) ivLength = 12 ;
@@ -625,9 +629,6 @@ public int getIvLength() {
625629 //else if ( "RC4".equals(base) ) {
626630 // ivLength = 8;
627631 //}
628- else if ( "ECB" .equals (mode ) ) {
629- ivLength = 0 ;
630- }
631632 else {
632633 ivLength = 8 ;
633634 }
Original file line number Diff line number Diff line change @@ -126,6 +126,17 @@ def test_des_iv_len
126126 assert_equal 8 , cipher . iv_len
127127 end
128128
129+ def test_aes_ecb_iv_len
130+ # ECB mode does not use an IV, so iv_len should be 0
131+ cipher = OpenSSL ::Cipher . new 'AES-128-ECB'
132+ assert_equal 0 , cipher . iv_len
133+ cipher = OpenSSL ::Cipher . new 'AES-192-ECB'
134+ assert_equal 0 , cipher . iv_len
135+ cipher = OpenSSL ::Cipher . new 'AES-256-ECB'
136+ assert_equal 0 , cipher . iv_len
137+ end
138+
139+
129140 @@test_encrypt_decrypt_des_variations = nil
130141
131142 def test_encrypt_decrypt_des_variations
You can’t perform that action at this time.
0 commit comments