aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src/crypto.c
AgeCommit message (Collapse)Author
2016-10-04Merge branch 'RoadRunnr/crypto/no-rc4/PR-1169/OTP-13896' into maintRaimo Niskanen
* RoadRunnr/crypto/no-rc4/PR-1169/OTP-13896: disable RC4 in SSL when crypto doesn't support it Fix compilation when OpenSSL doesn't support RC4 Conflicts: lib/crypto/c_src/crypto.c
2016-09-28Support using OpenSSL in FIPS modeDániel Szoboszlay
FIPS mode support needs to be enabled at compile time, by configuring Erlang/OTP with --enable-fips option. In FIPS mode the non-FIPS algorithms are disabled and raise error notsup. The supported protocols list is properly updated in FIPS mode to advertise only the enabled protocols. FIPS mode is off by default even if Erlang/OTP was built with FIPS support. It needs to be turned on at runtime. The official approach is to set the fips_mode application environment parameter of the crypto application to true. This would turn FIPS mode on when the NIF is loaded and would prevent loading the module on error. Another method is provided via the crypto:enable_fips_mode/1 function, but it is not recommended to be used in production, as it won't prevent the use of the crypto module in case of an error, and would risk OpenSSL crashing the emulator. It is very useful for test suites however that need to check both validated and non-validated functionality. This commit is based on commit 00b3a04d17a653b4abddeebd6dd8a2c38df532d0.
2016-09-22Fix compilation when OpenSSL doesn't support RC4Andreas Schultz
When OpenSSL has been configured with the "no-rc4" option, the header file rc4.h doesn't exist, and neither does the rc4 functions. Let's handle those by checking whether OPENSSL_NO_RC4 is defined.
2016-09-19Use more correct delimiters for erl_nif.h includeTuncer Ayaz
Anywhere but the beam sources we shouldn't #include "erl_nif.h", because what "erl_nif.h" does is: (1) fail to find it outside of -I dirs, (2) then treat it as if it was written like <erl_nif.h>. Using <erl_nif.h> skips (1). More information can be found in 6.10.2 of the C standard. Because the examples use "erl_nif.h", NIF projects in the Erlang ecosystem copy this verbatim and make the same mistake.
2016-09-14Fix compilation when OpenSSL doesn't support RC2Magnus Henoch
When OpenSSL has been configured with the "no-rc2" option, the header file rc2.h doesn't exist, and neither does the function EVP_rc2_cbc. Let's handle those by checking whether OPENSSL_NO_RC2 is defined. Also update pbe_SUITE, which uses RC2-CBC in one of the tests.
2016-09-13Merge branch 'maint'Raimo Niskanen
2016-09-13Silence warnings in cryptoRaimo Niskanen
2016-09-07Merge branch 'maint'Raimo Niskanen
2016-09-02Add '_cfb' alias for misspelled '_cbf' cipherRaimo Niskanen
2016-09-02Fix badarg -> notsup and test casesRaimo Niskanen
Also correct algo_cipher[] size since it was one to small.
2016-09-02Honour OPENSSL_NO_DESRaimo Niskanen
Patch suggestion by Michae in ERL-203 at bugs.erlang.org.
2016-08-31Merge branch 'gotthardp/crypto/add-cmac/ERL-82/PR-1138/OTP-13779'Raimo Niskanen
* gotthardp/crypto/add-cmac/ERL-82/PR-1138/OTP-13779: Skip the cmac test cases on older OpenSSL Added a reference to cmac RFC in the description part of the man page Fix building crypto/cmac_nif on 64-bit machines. crypto:cmac calculating the Cipher-based Message Authentication Code
2016-08-03Fix segfault in crypto by increasing algo_cipher arrayDuncaen
2016-07-30Fix building crypto/cmac_nif on 64-bit machines.Petr Gotthard
2016-07-30crypto:cmac calculating the Cipher-based Message Authentication CodePetr Gotthard
The ERL-82 issue requests a way to calculate a CMAC in Erlang. The AES128 CMAC is standartized in RFC 4493 and used e.g. for message authentication in the LoRaWAN networks. The CMAC is implemented by OpenSSL since v1.0.1, but as @IngelaAndin stated in response to the ERL-82, the current crypto implementation does not include functions that call those OpenSSL cryptolib functions. This commit introduces a new function `crypto:cmac` that calls the corresponding OpenSSL functions and calculates the CMAC. Only the cmac_nif is implemented. The incremental functions (init, update, final) are not provided because the current OpenSSL does not allow custom memory allocators like `enif_alloc_resource`. The Erlang user guide states that at least OpenSSL 0.9.8 is required, so I added few #ifdefs so the code is compatible with all versions. However, the OpenSSL pages say that the pre-1.0.1 versions (0.9.8 and 1.0.0) are no longer maintained. Even the 1.0.1 will be retired by Dec 2016. Hence I believe that adding a 1.0.1-only function like CMAC should be OK.
2016-05-26crypto: Add OpenSSL_version macrosSverker Eriksson
to make it easier to read and construct version checks.
2016-05-26crypto: Allow any AES-GCM tag length for non-EVP implSverker Eriksson
Same fix as was done for EVP in f4f588683dce36c447017.
2016-05-26crypto: Workaround buggy GCM via EVPSverker Eriksson
2016-04-25crypto: Deprecate rand_bytes/1Ingela Anderton Andin
OpenSSL has deprecated the function RAND_pseudo_bytes used by crypto:rand_bytes/1, so this function is now deprecated in OTP too. rand_bytes/3 also used this function, but was not documented so we can remove it right away. This commit also removes the fallback in generate_key to use rand_bytes/1 if strong_rand_bytes/1 throws low entropy. This is a potential incompatibility but we think it is desirable as crypto should provide cryptographically secure functions.
2016-04-18Merge branch 'mururu/crypto/aes-gcm-tag-len.PR-998.OTP-13483'Sverker Eriksson
2016-04-13Merge branch 'henrik/update-copyrightyear'Henrik Nord
* henrik/update-copyrightyear: update copyright-year
2016-03-29crypto: Optimize digest/cipher lookupsSverker Eriksson
by not repeating calls to get static EVP_MD and EVP_CIPHER objects. Also compressed the structs with unions for better caching during search.
2016-03-29crypto: Raise 'notsup' if lacking 'characteristic_two_field'Sverker Eriksson
and not badarg.
2016-03-26crypto: Enable AES-GCM tag length to changeYuki Ito
This commit enables AES-GCM encryption/decryption to change its tag length between 1 to 16 bytes.
2016-03-15update copyright-yearHenrik Nord
2016-02-08Merge branch 'maint'Sverker Eriksson
2016-01-27Check the result of EC_GROUP_new_curve_* callsDániel Szoboszlay
The FIPS-enabled OpenSSL on RHEL disallows the use of < 256 bit prime fields (like secp128r1 or secp160k1), and the EC_GROUP_new_cuve_GFp call would return a NULL pointer for such fields. Not checking for this failure could result in a segfault in the NIF code.
2016-01-14crypto: Fix bug for multiple blocks for AES-ECBAndrew Bennett
2015-12-17Merge branch 'sverk/crypto/aes-ecb-192-bit'Sverker Eriksson
OTP-13207 * sverk/crypto/aes-ecb-192-bit: crypto: Support 192-bit keys for AES ECB
2015-12-17crypto: Support 192-bit keys for AES ECBAndrew Bennett
2015-12-17Merge branch 'sverk/crypto/aes-cbc-192-bit'Sverker Eriksson
OTP-13206 * sverk/crypto/aes-cbc-192-bit: crypto: Support 192-bit keys for AES CBC
2015-12-11crypto: Support 192-bit keys for AES CBCSverker Eriksson
and deprecate aes_cbc128 and aes_cbc256 in favor of aes_cbc. This commit is pr 832 squashed, rebased and made work on master https://github.com/erlang/otp/pull/832/commits
2015-12-11crypto: Fix potential memory leak in error case for block cipherSverker Eriksson
2015-12-11crypto: Optimize AES-GCM cipher to not use dynamic allocationSverker Eriksson
for the EVP_CIPHER_CTX.
2015-12-11Use EVP for AES-GCMYuki Ito
This enables the use of hardware acceleration on newer Intel CPUs (AES-NI).
2015-12-01crypto: Avoid bug in OpenSSL-0.9.8 for ECB ciphersSverker Eriksson
that make EVP_CIPHER_iv_length() return non-zero value. Seems to be fixed in 0.9.8m.
2015-11-17Fix EVP_aes_???_ctr to demand OpenSSL 1.0.1 or later.Sverker Eriksson
2015-11-17Fix bug for aes_cfb_128_encrypt with empty binarySverker Eriksson
causing OpenSSL 0.9.8h to crash with evp_enc.c(282): OpenSSL internal error, assertion failed: inl > 0
2015-11-17crypto: Refactor nif code to use EVP interfaceSverker Eriksson
Using the generic EVP_* API makes it possible to unify algorithm-specific nif functions to a single generic function. Effectively the same change that took place on the Erlang API in R16B01 is now applied to the C code. The old implementation using the low-level API is kept for compiling against old OpenSSL, as parts of the EVP API were introduced in OpenSSL 1.0.0. There are various minor improvements as well: - supported algorithms are now provided by the nif code (not a mix of the C and Erlang code) - remove unnecessary variables and macro definitions Most of the changes in this commit comes from Dániel Szoboszlay https://github.com/dszoboszlay/otp/commit/07f7056f955b324df4ace which is part of his 'fips' branch. Now also rebased on master branch.
2015-07-10ose: Remove all code related to the OSE portLukas Larsson
The OSE port is no longer supported and this commit removed it and any changes related to it. The things that were general improvements have been left in the code.
2015-06-18Change license text to APLv2Bruce Yinhe
2015-05-11crypto: Fix bug in generate_key(ecdh,...)Sverker Eriksson
that could cause VM crash on faulty input.
2015-04-09crypto: Fix undefined symbol EVP_CIPHER_CTX_newSverker Eriksson
Use a stack allocated context and EVP_CIPHER_CTX_init/cleanup instead of dynamic EVP_CIPHER_CTX_new/free that does not exist in older 0.9.8 versions.
2015-02-27Merge branch 'maint'Henrik Nord
2015-02-04Accept all valid key sizes in aes_cfb functionsKelly McLaughlin
Despite the confusion caused by the name, aes_cfb_8_crypt and aes_cfb_128_crypt can use key lengths of 128, 192, or 256. The integer in the function name refers to the block size for CFB mode. Change the aes_cfb_8_crypt and aes_cfb_128_crypt functions to accept and use keys of length 128, 192, or 256. Also augment the existing testing for these functions using the NIST test vectors for the additional key lengths to ensure the changes function properly.
2015-01-14Merge branch 'andreaTP/added-aes-ecb-to-crypto/OTP-12403'Marcus Arendt
* andreaTP/added-aes-ecb-to-crypto/OTP-12403: aligned implementation following last specs finally fixed docs fixed incorrect tag proposal of documentation fixes and tests add aes ecb to crypto library
2015-01-12Merge branch 'RoadRunnr/crypto-ecc-gen-key'Bruce Yinhe
OTP-12394 * RoadRunnr/crypto-ecc-gen-key: [crypto] enhance generate_key for ECC keys
2015-01-09add aes ecb to crypto libraryandreaP
2014-11-28crypto: use EVP for AES-CBCAlex Wilson
This enables the use of hardware acceleration for AES crypto on newer Intel CPUs (AES-NI), among other platforms.
2014-11-17[crypto] enhance generate_key for ECC keysAndreas Schultz
enhance generate_key to calculate ECC public keys from private keys