diff options
author | Hans Nilsson <[email protected]> | 2019-02-04 11:52:27 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-02-04 11:52:27 +0100 |
commit | 784fb8d859fe3277435c8046b55a65a80313c6f5 (patch) | |
tree | c29a454b304df35e0a40320b3458a8e567168626 /lib/crypto/c_src/cipher.c | |
parent | bc0aef4bb631acbf0b8e8fd8ecc51cb1286ed8c9 (diff) | |
parent | 0b67f754bd6e0f22b1b7e1c9b2270f8118a66f38 (diff) | |
download | otp-784fb8d859fe3277435c8046b55a65a80313c6f5.tar.gz otp-784fb8d859fe3277435c8046b55a65a80313c6f5.tar.bz2 otp-784fb8d859fe3277435c8046b55a65a80313c6f5.zip |
Merge pull request #2095 from hogand/crypto/revamp-files
crypto: revamp C code [WIP]
OTP-14732
Diffstat (limited to 'lib/crypto/c_src/cipher.c')
-rw-r--r-- | lib/crypto/c_src/cipher.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/lib/crypto/c_src/cipher.c b/lib/crypto/c_src/cipher.c index 6580cb183f..5d306b80dd 100644 --- a/lib/crypto/c_src/cipher.c +++ b/lib/crypto/c_src/cipher.c @@ -34,47 +34,51 @@ static struct cipher_type_t cipher_types[] = #else {NULL} #endif - }, - {{"des_cbc"}, {COND_NO_DES_PTR(&EVP_des_cbc)}}, - {{"des_cfb"}, {COND_NO_DES_PTR(&EVP_des_cfb8)}}, - {{"des_ecb"}, {COND_NO_DES_PTR(&EVP_des_ecb)}}, - {{"des_ede3_cbc"}, {COND_NO_DES_PTR(&EVP_des_ede3_cbc)}}, + ,0}, + {{"des_cbc"}, {COND_NO_DES_PTR(&EVP_des_cbc)}, 0}, + {{"des_cfb"}, {COND_NO_DES_PTR(&EVP_des_cfb8)}, 0}, + {{"des_ecb"}, {COND_NO_DES_PTR(&EVP_des_ecb)}, 0}, + {{"des_ede3_cbc"}, {COND_NO_DES_PTR(&EVP_des_ede3_cbc)}, 0}, {{"des_ede3_cbf"}, /* Misspelled, retained */ #ifdef HAVE_DES_ede3_cfb_encrypt {COND_NO_DES_PTR(&EVP_des_ede3_cfb8)} #else {NULL} #endif - }, + ,0}, {{"des_ede3_cfb"}, #ifdef HAVE_DES_ede3_cfb_encrypt {COND_NO_DES_PTR(&EVP_des_ede3_cfb8)} #else {NULL} #endif - }, - {{"blowfish_cbc"}, {&EVP_bf_cbc}}, - {{"blowfish_cfb64"}, {&EVP_bf_cfb64}}, - {{"blowfish_ofb64"}, {&EVP_bf_ofb}}, - {{"blowfish_ecb"}, {&EVP_bf_ecb}}, + ,0}, + {{"blowfish_cbc"}, {&EVP_bf_cbc}, 0}, + {{"blowfish_cfb64"}, {&EVP_bf_cfb64}, 0}, + {{"blowfish_ofb64"}, {&EVP_bf_ofb}, 0}, + {{"blowfish_ecb"}, {&EVP_bf_ecb}, 0}, {{"aes_cbc"}, {&EVP_aes_128_cbc}, 16}, {{"aes_cbc"}, {&EVP_aes_192_cbc}, 24}, {{"aes_cbc"}, {&EVP_aes_256_cbc}, 32}, - {{"aes_cbc128"}, {&EVP_aes_128_cbc}}, - {{"aes_cbc256"}, {&EVP_aes_256_cbc}}, - {{"aes_cfb8"}, {&EVP_aes_128_cfb8}}, - {{"aes_cfb128"}, {&EVP_aes_128_cfb128}}, + {{"aes_cbc128"}, {&EVP_aes_128_cbc}, 0}, + {{"aes_cbc256"}, {&EVP_aes_256_cbc}, 0}, + {{"aes_cfb8"}, {&EVP_aes_128_cfb8}, 0}, + {{"aes_cfb128"}, {&EVP_aes_128_cfb128}, 0}, {{"aes_ecb"}, {&EVP_aes_128_ecb}, 16}, {{"aes_ecb"}, {&EVP_aes_192_ecb}, 24}, {{"aes_ecb"}, {&EVP_aes_256_ecb}, 32}, - {{NULL}} + {{NULL},{NULL},0} }; #ifdef HAVE_EVP_AES_CTR ErlNifResourceType* evp_cipher_ctx_rtype; static void evp_cipher_ctx_dtor(ErlNifEnv* env, struct evp_cipher_ctx* ctx) { - EVP_CIPHER_CTX_free(ctx->ctx); + if (ctx == NULL) + return; + + if (ctx->ctx) + EVP_CIPHER_CTX_free(ctx->ctx); } #endif @@ -84,13 +88,15 @@ int init_cipher_ctx(ErlNifEnv *env) { (ErlNifResourceDtor*) evp_cipher_ctx_dtor, ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER, NULL); - if (evp_cipher_ctx_rtype == NULL) { - PRINTF_ERR0("CRYPTO: Could not open resource type 'EVP_CIPHER_CTX'"); - return 0; - } + if (evp_cipher_ctx_rtype == NULL) + goto err; #endif return 1; + + err: + PRINTF_ERR0("CRYPTO: Could not open resource type 'EVP_CIPHER_CTX'"); + return 0; } void init_cipher_types(ErlNifEnv* env) |