X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=engines%2Fafalg%2Fe_afalg.c;h=2e7ce3455abc44059eb28082a88d2368368f7309;hp=d4b4f6bc5885f286523a64bf96deb708673f63a9;hb=7218ae513408a58e8f8f20ed49dc45505e00a5b2;hpb=a193388811db7e842ed7d1966bbe2552095b26cc diff --git a/engines/afalg/e_afalg.c b/engines/afalg/e_afalg.c index d4b4f6bc58..2e7ce3455a 100644 --- a/engines/afalg/e_afalg.c +++ b/engines/afalg/e_afalg.c @@ -1,55 +1,10 @@ -/* ==================================================================== - * Copyright (c) 1999-2016 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * openssl-core@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). +/* + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html */ /* Required for vmsplice */ @@ -60,6 +15,7 @@ #include #include +#include #include #define K_MAJ 4 @@ -68,6 +24,9 @@ #if LINUX_VERSION_CODE <= KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2) # warning "AFALG ENGINE requires Kernel Headers >= 4.1.0" # warning "Skipping Compilation of AFALG engine" +void engine_load_afalg_int(void) +{ +} #else # include @@ -103,7 +62,7 @@ #define ALG_MAX_SALG_TYPE 14 # ifdef OPENSSL_NO_DYNAMIC_ENGINE -void engine_load_afalg_internal(void); +void engine_load_afalg_int(void); # endif /* Local Linkage Functions */ @@ -127,7 +86,7 @@ static int afalg_chk_platform(void); /* Engine Id and Name */ static const char *engine_afalg_id = "afalg"; -static const char *engine_afalg_name = "AFLAG engine support"; +static const char *engine_afalg_name = "AFALG engine support"; static int afalg_cipher_nids[] = { NID_aes_128_cbc @@ -135,27 +94,27 @@ static int afalg_cipher_nids[] = { static EVP_CIPHER *_hidden_aes_128_cbc = NULL; -static inline int io_setup(unsigned n, aio_context_t *ctx) +static ossl_inline int io_setup(unsigned n, aio_context_t *ctx) { return syscall(__NR_io_setup, n, ctx); } -static inline int eventfd(int n) +static ossl_inline int eventfd(int n) { return syscall(__NR_eventfd, n); } -static inline int io_destroy(aio_context_t ctx) +static ossl_inline int io_destroy(aio_context_t ctx) { return syscall(__NR_io_destroy, ctx); } -static inline int io_read(aio_context_t ctx, long n, struct iocb **iocb) +static ossl_inline int io_read(aio_context_t ctx, long n, struct iocb **iocb) { return syscall(__NR_io_submit, ctx, n, iocb); } -static inline int io_getevents(aio_context_t ctx, long min, long max, +static ossl_inline int io_getevents(aio_context_t ctx, long min, long max, struct io_event *events, struct timespec *timeout) { @@ -271,7 +230,7 @@ int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, memset(cb, '\0', sizeof(*cb)); cb->aio_fildes = sfd; cb->aio_lio_opcode = IOCB_CMD_PREAD; - cb->aio_buf = (unsigned long)buf; + cb->aio_buf = (uint64_t)buf; cb->aio_offset = 0; cb->aio_data = 0; cb->aio_nbytes = len; @@ -351,7 +310,7 @@ int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, return 1; } -static inline void afalg_set_op_sk(struct cmsghdr *cmsg, +static ossl_inline void afalg_set_op_sk(struct cmsghdr *cmsg, const unsigned int op) { cmsg->cmsg_level = SOL_ALG; @@ -373,7 +332,7 @@ static void afalg_set_iv_sk(struct cmsghdr *cmsg, const unsigned char *iv, memcpy(aiv->iv, iv, len); } -static inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key, +static ossl_inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key, const int klen) { int ret; @@ -539,7 +498,7 @@ static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, return 0; } - actx = EVP_CIPHER_CTX_cipher_data(ctx); + actx = EVP_CIPHER_CTX_get_cipher_data(ctx); if (actx == NULL) { ALG_WARN("%s: Cipher data NULL\n", __func__); return 0; @@ -602,7 +561,7 @@ static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, return 0; } - actx = (afalg_ctx *) EVP_CIPHER_CTX_cipher_data(ctx); + actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx); if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) { ALG_WARN("%s afalg ctx passed\n", ctx == NULL ? "NULL" : "Uninitialised"); @@ -649,7 +608,7 @@ static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx) return 0; } - actx = (afalg_ctx *) EVP_CIPHER_CTX_cipher_data(ctx); + actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx); if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) { ALG_WARN("%s afalg ctx passed\n", ctx == NULL ? "NULL" : "Uninitialised"); @@ -772,6 +731,7 @@ static int afalg_chk_platform(void) int ret; int i; int kver[3] = { -1, -1, -1 }; + int sock; char *str; struct utsname ut; @@ -799,6 +759,14 @@ static int afalg_chk_platform(void) return 0; } + /* Test if we can actually create an AF_ALG socket */ + sock = socket(AF_ALG, SOCK_SEQPACKET, 0); + if (sock == -1) { + AFALGerr(AFALG_F_AFALG_CHK_PLATFORM, AFALG_R_SOCKET_CREATE_FAILED); + return 0; + } + close(sock); + return 1; } @@ -815,7 +783,7 @@ static ENGINE *engine_afalg(void) return ret; } -void engine_load_afalg_internal(void) +void engine_load_afalg_int(void) { ENGINE *toadd; @@ -844,6 +812,8 @@ static int afalg_finish(ENGINE *e) static int afalg_destroy(ENGINE *e) { ERR_unload_AFALG_strings(); + EVP_CIPHER_meth_free(_hidden_aes_128_cbc); + _hidden_aes_128_cbc = NULL; return 1; }