aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_cipher.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix RDoc markuptopic/fix-rdoc-markupKazuki Yamaguchi2017-02-241-14/+14
| | | | | Ruby core uses _str_ for emphasizing argument names and +str+ for codes. Match with the rule for better rendering.
* Remove support for OpenSSL 0.9.8 and 1.0.0topic/drop-openssl-098-and-100Kazuki Yamaguchi2016-12-221-16/+0
| | | | | | | | | | They are no longer receiving security updates from the OpenSSL development team since 2015-12. We have kept basic compatibility until now because RHEL 5 still uses an (heavily modified) OpenSSL 0.9.8e. The RHEL 5 will reach EOL on 2017-03, thus it is now safe to assume nobody is still using such old versions of OpenSSL.
* cipher: always define Cipher#authenticated?Kazuki Yamaguchi2016-10-041-18/+21
| | | | | Implement Cipher#authenticated? even when the OpenSSL version does not support AEAD. It just returns false.
* cipher: fix documentation regarding default IVKazuki Yamaguchi2016-10-031-9/+4
| | | | | | | Remove a sentence "If not explicitly set, the OpenSSL default of an all-zeroes ("\\0") IV is used." It actually works so, but not guranteed by the OpenSSL API. At least I didn't find any formal documentation saying so.
* Merge branch 'topic/cipher-no-initialize-null-key'Kazuki Yamaguchi2016-09-281-12/+13
|\ | | | | | | | | * topic/cipher-no-initialize-null-key: cipher: don't set dummy encryption key in Cipher#initialize
| * cipher: don't set dummy encryption key in Cipher#initializetopic/cipher-no-initialize-null-keyKazuki Yamaguchi2016-09-281-12/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the encryption key initialization from Cipher#initialize. This is effectively a revert of r32723 ("Avoid possible SEGV from AES encryption/decryption", 2011-07-28). r32723, which added the key initialization, was a workaround for Ruby Bug #2768. For some certain ciphers, calling EVP_CipherUpdate() before setting an encryption key caused segfault. It was not a problem until OpenSSL implemented GCM mode - the encryption key could be overridden by repeated calls of EVP_CipherInit_ex(). But, it is not the case for AES-GCM ciphers. Setting a key, an IV, a key, in this order causes the IV to be reset to an all-zero IV. The problem of Bug #2768 persists on the current versions of OpenSSL. So, make Cipher#update raise an exception if a key is not yet set by the user. Since encrypting or decrypting without key does not make any sense, this should not break existing applications. Users can still call Cipher#key= and Cipher#iv= multiple times with their own responsibility. Reference: https://bugs.ruby-lang.org/issues/2768 Reference: https://bugs.ruby-lang.org/issues/8221 Reference: https://github.com/ruby/openssl/issues/49
* | fid typos [ci skip]nobu2016-09-251-1/+1
|/ | | | | | * fix typos, "a" before "Integer" to "an". [Fix GH-1438] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Merge branch 'topic/cipher-auth-tag-len'Kazuki Yamaguchi2016-08-261-3/+45
|\ | | | | | | | | * topic/cipher-auth-tag-len: cipher: add Cipher#auth_tag_len=
| * cipher: add Cipher#auth_tag_len=topic/cipher-auth-tag-lenKazuki Yamaguchi2016-08-141-3/+45
| | | | | | | | | | | | Add a method to set the authentication tag length to be generate by an AEAD ciphers. In particular, OCB mode which is implemented in OpenSSL 1.1.0 requires this.
* | cipher: allow cipher name in GetCipherPtr()Kazuki Yamaguchi2016-08-221-3/+16
| | | | | | | | | | | | | | | | | | | | | | | | The function GetCipherPtr() is used when we want a const EVP_CIPHER that represents a cipher algorithm. This change allows users to write a code that exports a PKey encrypted without creating an OpenSSL::Cipher instance: pkey = OpenSSL::PKey.read(...) pkey.export("aes-128-cbc") { password } This is the same as what happened to GetDigestPtr() in r12128.
* | cipher: fixup documentationKazuki Yamaguchi2016-08-221-21/+27
| |
* | cipher: follow up for the previous documentation updatetopic/cipher-doc-aeadKazuki Yamaguchi2016-08-161-6/+8
| | | | | | | | | | | | Add some explaination about the associated data. Also fix the description of the AES-GCM example: the IV (nonce) doesn't need to be unpredictable.
* | cipher: update documentationKazuki Yamaguchi2016-08-141-22/+33
|/ | | | | Add a note about GCM mode - warn of the risk of reusing nonce and authentication tag truncation. [GH ruby/openssl#63]
* cipher: avoid -Wshorten-64-to-32 warning in ossl_cipher_update_long()Kazuki Yamaguchi2016-07-241-1/+1
| | | | Fixes c0548c94e499.
* cipher: fix handling huge data larger than INT_MAX bytesKazuki Yamaguchi2016-07-241-18/+16
| | | | | | | | | | | | | | | | The function ossl_cipher_update_long() was added to fix this in r48923 (ossl_cipher.c: workaround of OpenSSL API, 2014-12-23), but it didn't work well. [Bug #10633] This can be tested by running: $ fallocate -l 2G data.img $ ruby -ropenssl <<EOF cipher = OpenSSL::Cipher.new("aes-128-ecb").encrypt cipher.key = "\x00" * 16 ct = cipher.update(File.read("data.img")) << cipher.final p ct.bytesize EOF
* Merge branch 'topic/cipher-iv-len'Kazuki Yamaguchi2016-07-201-3/+57
|\ | | | | | | | | * topic/cipher-iv-len: cipher: allow setting IV length when using AEAD ciphers
| * cipher: allow setting IV length when using AEAD cipherstopic/cipher-iv-lenKazuki Yamaguchi2016-07-091-3/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Add OpenSSL::Cipher#iv_len=. For interoperability with other applications, it is sometimes required. Normally 'IV' is fixed-length, but in OpenSSL, some ciphers such as aes-128-gcm make use of it as 'nonce', which is variable-length. Changing the IV length in Cipher#iv= is also an option but I decided not to choose it. Because in Ruby <= 2.3 Cipher#iv= truncates the input when the length is longer than the current IV length, changing the behavior might cause unexpected encryption result. [Bug #8667] [Bug #10420] [GH ruby/ruby#569]
* | Fix RDoc styletopic/rdoc-fixesKazuki Yamaguchi2016-07-091-1/+2
|/
* openssl: support non AES-GCM AEAD ciphers in OpenSSL::Cipherrhe2016-06-191-55/+17
| | | | | | | | | | | | | | | | | * ext/openssl/ossl_cipher.c (ossl_cipher_get_auth_tag, ossl_cipher_set_auth_tag): Check if the cipher flags retrieved by EVP_CIPHER_CTX_flags() includes EVP_CIPH_FLAG_AEAD_CIPHER to see if the cipher supports AEAD. AES-GCM was the only supported in OpenSSL 1.0.1. (Init_ossl_cipher): Fix doc; OpenSSL::Cipher::AES.new(128, :GCM) can't work. * ext/openssl/openssl_missing.h: Define EVP_CTRL_AEAD_{GET,SET}_TAG if missing. They are added in OpenSSL 1.1.0, and have the same value as EVP_CTRL_GCM_{GET,SET}_TAG and EVP_CTRL_CCM_{GET,SET}_TAG. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* openssl: fix free function of OpenSSL::Cipherrhe2016-06-091-5/+1
| | | | | | | | * ext/openssl/ossl_cipher.c (ossl_cipher_free): Use EVP_CIPHER_CTX_free() to free EVP_CIPHER_CTX allocated by EVP_CIPHER_CTX_new(). [ruby-core:75225] [Feature #12324] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* openssl: adapt to OpenSSL 1.1.0 opaque structsrhe2016-06-091-20/+15
| | | | | | | | | | | | | | | * ext/openssl/extconf.rb: Check existence of accessor functions that don't exist in OpenSSL 0.9.8. OpenSSL 1.1.0 made most of its structures opaque and requires use of these accessor functions. [ruby-core:75225] [Feature #12324] * ext/openssl/openssl_missing.[ch]: Implement them if missing. * ext/openssl/ossl*.c: Use these accessor functions. * test/openssl/test_hmac.rb: Add missing test for HMAC#reset. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* openssl: drop OpenSSL 0.9.6/0.9.7 supportrhe2016-05-311-10/+0
| | | | | | * ext/openssl, test/openssl: Drop OpenSSL < 0.9.8 support. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* openssl: make Cipher#key= and #iv= reject too long valuesrhe2016-05-311-5/+9
| | | | | | | | | | | | * ext/openssl/ossl_cipher.c (ossl_cipher_set_key, ossl_cipher_set_iv): Reject too long values as well as too short ones. Currently they just truncate the input but this would hide bugs and lead to unexpected encryption/decryption results. * test/openssl/test_cipher.rb: Test that Cipher#key= and #iv= reject Strings with invalid length. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* openssl: use StringValueCStr() where NUL-terminated string is expectedrhe2016-05-311-2/+2
| | | | | | | | | | | | | | * ext/openssl/ossl_asn1.c, ext/openssl/ossl_bn.c, ext/openssl/ossl_cipher.c, ext/openssl/ossl_digest.c ext/openssl/ossl_engine.c, ext/openssl/ossl_ns_spki.c ext/openssl/ossl_pkcs12.c, ext/openssl/ossl_pkcs7.c ext/openssl/ossl_pkey.c, ext/openssl/ossl_pkey_ec.c ext/openssl/ossl_rand.c, ext/openssl/ossl_ssl.c ext/openssl/ossl_x509attr.c, ext/openssl/ossl_x509cert.c ext/openssl/ossl_x509ext.c, ext/openssl/ossl_x509store.c: Use StringValueCStr() where NUL-terminated string is expected. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* sync code from upstreamSHIBATA Hiroshi2015-12-301-1/+1
|
* Sync with ruby trunkZachary Scott2015-09-231-2/+0
|
* Upstream ruby/ruby@451fe26 from r50673Zachary Scott2015-06-031-7/+3
|
* Apply ruby/ruby@325a50fc572516a171d640765d6ddf9b20be14dc to fix typosZachary Scott2015-05-041-1/+1
| | | | See also r50351 from ruby/ruby#876
* Sync with ruby trunkZachary Scott2015-01-051-8/+38
|
* import ruby trunkSHIBATA Hiroshi2014-10-271-0/+987