Skip to content

Commit 3d16091

Browse files
authored
Merge pull request #384 from bdewater/lower-case-cipher
User lower case cipher names for maximum compatibility
2 parents b362c0a + 7bc4912 commit 3d16091

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

ext/openssl/ossl.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
664664
* ahold of the key may use it unless it is encrypted. In order to securely
665665
* export a key you may export it with a pass phrase.
666666
*
667-
* cipher = OpenSSL::Cipher.new 'AES-256-CBC'
667+
* cipher = OpenSSL::Cipher.new 'aes-256-cbc'
668668
* pass_phrase = 'my secure pass phrase goes here'
669669
*
670670
* key_secure = key.export cipher, pass_phrase
@@ -772,7 +772,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
772772
* using PBKDF2. PKCS #5 v2.0 recommends at least 8 bytes for the salt,
773773
* the number of iterations largely depends on the hardware being used.
774774
*
775-
* cipher = OpenSSL::Cipher.new 'AES-256-CBC'
775+
* cipher = OpenSSL::Cipher.new 'aes-256-cbc'
776776
* cipher.encrypt
777777
* iv = cipher.random_iv
778778
*
@@ -795,7 +795,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
795795
* Use the same steps as before to derive the symmetric AES key, this time
796796
* setting the Cipher up for decryption.
797797
*
798-
* cipher = OpenSSL::Cipher.new 'AES-256-CBC'
798+
* cipher = OpenSSL::Cipher.new 'aes-256-cbc'
799799
* cipher.decrypt
800800
* cipher.iv = iv # the one generated with #random_iv
801801
*
@@ -830,7 +830,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
830830
*
831831
* First set up the cipher for encryption
832832
*
833-
* encryptor = OpenSSL::Cipher.new 'AES-256-CBC'
833+
* encryptor = OpenSSL::Cipher.new 'aes-256-cbc'
834834
* encryptor.encrypt
835835
* encryptor.pkcs5_keyivgen pass_phrase, salt
836836
*
@@ -843,7 +843,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
843843
*
844844
* Use a new Cipher instance set up for decryption
845845
*
846-
* decryptor = OpenSSL::Cipher.new 'AES-256-CBC'
846+
* decryptor = OpenSSL::Cipher.new 'aes-256-cbc'
847847
* decryptor.decrypt
848848
* decryptor.pkcs5_keyivgen pass_phrase, salt
849849
*
@@ -931,7 +931,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
931931
* ca_key = OpenSSL::PKey::RSA.new 2048
932932
* pass_phrase = 'my secure pass phrase goes here'
933933
*
934-
* cipher = OpenSSL::Cipher.new 'AES-256-CBC'
934+
* cipher = OpenSSL::Cipher.new 'aes-256-cbc'
935935
*
936936
* open 'ca_key.pem', 'w', 0400 do |io|
937937
* io.write ca_key.export(cipher, pass_phrase)

ext/openssl/ossl_cipher.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ ossl_cipher_alloc(VALUE klass)
104104
* call-seq:
105105
* Cipher.new(string) -> cipher
106106
*
107-
* The string must contain a valid cipher name like "AES-256-CBC".
107+
* The string must contain a valid cipher name like "aes-256-cbc".
108108
*
109109
* A list of cipher names is available by calling OpenSSL::Cipher.ciphers.
110110
*/
@@ -874,7 +874,7 @@ Init_ossl_cipher(void)
874874
* individual components name, key length and mode. Either all uppercase
875875
* or all lowercase strings may be used, for example:
876876
*
877-
* cipher = OpenSSL::Cipher.new('AES-128-CBC')
877+
* cipher = OpenSSL::Cipher.new('aes-128-cbc')
878878
*
879879
* === Choosing either encryption or decryption mode
880880
*
@@ -904,7 +904,7 @@ Init_ossl_cipher(void)
904904
* without processing the password further. A simple and secure way to
905905
* create a key for a particular Cipher is
906906
*
907-
* cipher = OpenSSL::Cipher.new('AES-256-CFB')
907+
* cipher = OpenSSL::Cipher.new('aes-256-cfb')
908908
* cipher.encrypt
909909
* key = cipher.random_key # also sets the generated key on the Cipher
910910
*
@@ -972,14 +972,14 @@ Init_ossl_cipher(void)
972972
*
973973
* data = "Very, very confidential data"
974974
*
975-
* cipher = OpenSSL::Cipher.new('AES-128-CBC')
975+
* cipher = OpenSSL::Cipher.new('aes-128-cbc')
976976
* cipher.encrypt
977977
* key = cipher.random_key
978978
* iv = cipher.random_iv
979979
*
980980
* encrypted = cipher.update(data) + cipher.final
981981
* ...
982-
* decipher = OpenSSL::Cipher.new('AES-128-CBC')
982+
* decipher = OpenSSL::Cipher.new('aes-128-cbc')
983983
* decipher.decrypt
984984
* decipher.key = key
985985
* decipher.iv = iv
@@ -1015,7 +1015,7 @@ Init_ossl_cipher(void)
10151015
* not to reuse the _key_ and _nonce_ pair. Reusing an nonce ruins the
10161016
* security guarantees of GCM mode.
10171017
*
1018-
* cipher = OpenSSL::Cipher.new('AES-128-GCM').encrypt
1018+
* cipher = OpenSSL::Cipher.new('aes-128-gcm').encrypt
10191019
* cipher.key = key
10201020
* cipher.iv = nonce
10211021
* cipher.auth_data = auth_data
@@ -1031,7 +1031,7 @@ Init_ossl_cipher(void)
10311031
* ciphertext with a probability of 1/256.
10321032
*
10331033
* raise "tag is truncated!" unless tag.bytesize == 16
1034-
* decipher = OpenSSL::Cipher.new('AES-128-GCM').decrypt
1034+
* decipher = OpenSSL::Cipher.new('aes-128-gcm').decrypt
10351035
* decipher.key = key
10361036
* decipher.iv = nonce
10371037
* decipher.auth_tag = tag

test/openssl/test_cipher.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ def test_ciphers
147147

148148
def test_AES
149149
pt = File.read(__FILE__)
150-
%w(ECB CBC CFB OFB).each{|mode|
151-
c1 = OpenSSL::Cipher.new("AES-256-#{mode}")
150+
%w(ecb cbc cfb ofb).each{|mode|
151+
c1 = OpenSSL::Cipher.new("aes-256-#{mode}")
152152
c1.encrypt
153153
c1.pkcs5_keyivgen("passwd")
154154
ct = c1.update(pt) + c1.final
155155

156-
c2 = OpenSSL::Cipher.new("AES-256-#{mode}")
156+
c2 = OpenSSL::Cipher.new("aes-256-#{mode}")
157157
c2.decrypt
158158
c2.pkcs5_keyivgen("passwd")
159159
assert_equal(pt, c2.update(ct) + c2.final)
@@ -163,7 +163,7 @@ def test_AES
163163
def test_update_raise_if_key_not_set
164164
assert_raise(OpenSSL::Cipher::CipherError) do
165165
# it caused OpenSSL SEGV by uninitialized key [Bug #2768]
166-
OpenSSL::Cipher.new("AES-128-ECB").update "." * 17
166+
OpenSSL::Cipher.new("aes-128-ecb").update "." * 17
167167
end
168168
end
169169

0 commit comments

Comments
 (0)