# # Copyright (c) 2008-2010 TrueCrypt Developers Association. All rights reserved. # # Governed by the TrueCrypt License 3.0 the full text of which is contained in # the file License.txt included in TrueCrypt binary and source code distribution # packages. # #------ Command line arguments ------ # DEBUG: Disable optimizations and enable debugging checks # DEBUGGER: Enable debugging information for use by debuggers # NOASM: Exclude modules requiring assembler # NOGUI: Disable graphical user interface (build console-only application) # NOSTRIP: Do not strip release binary # NOTEST: Do not test release binary # RESOURCEDIR: Run-time resource directory # VERBOSE: Enable verbose messages # WXSTATIC: Use static wxWidgets library #------ Targets ------ # all # clean # wxbuild: Configure and build wxWidgets - source code must be located at $(WX_ROOT) #------ Build configuration ------ export APPNAME := veracrypt export BASE_DIR := $(CURDIR) export BUILD_INC := $(BASE_DIR)/Build/Include export AR ?= ar export CC ?= gcc export CXX ?= g++ export AS := nasm export RANLIB ?= ranlib export CFLAGS := -Wall export CXXFLAGS := -Wall -Wno-unused-parameter C_CXX_FLAGS := -MMD -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -I$(BASE_DIR) -I$(BASE_DIR)/Crypto export ASFLAGS := -Ox -D __GNUC__ export LFLAGS := export PKG_CONFIG_PATH ?= /usr/local/lib/pkgconfig export WX_CONFIG ?= wx-config export WX_CONFIG_ARGS := --unicode WX_CONFIGURE_FLAGS := export WXCONFIG_CFLAGS := export WXCONFIG_CXXFLAGS := WX_ROOT ?= .. export TC_BUILD_CONFIG := Release ifeq "$(origin DEBUG)" "command line" ifneq "$(DEBUG)" "0" TC_BUILD_CONFIG := Debug endif endif ifeq "$(origin NOGUI)" "command line" export TC_NO_GUI := 1 C_CXX_FLAGS += -DTC_NO_GUI WX_CONFIGURE_FLAGS += --disable-gui endif ifdef PKCS11_INC C_CXX_FLAGS += -I$(PKCS11_INC) else C_CXX_FLAGS += -I$(CURDIR)/PKCS11 endif ifeq "$(origin RESOURCEDIR)" "command line" C_CXX_FLAGS += -DTC_RESOURCE_DIR="$(RESOURCEDIR)" endif ifneq "$(origin VERBOSE)" "command line" MAKEFLAGS += -s endif ifeq "$(origin WXSTATIC)" "command line" WX_CONFIG = $(WX_BUILD_DIR)/wx-config WX_CONFIG_ARGS += --static endif #------ Release configuration ------ ifeq "$(TC_BUILD_CONFIG)" "Release" C_CXX_FLAGS += -O2 -fno-strict-aliasing # Do not enable strict aliasing export WX_BUILD_DIR ?= $(BASE_DIR)/wxrelease WX_CONFIGURE_FLAGS += --disable-debug_flag --disable-debug_gdb --disable-debug_info else #------ Debug configuration ------ C_CXX_FLAGS += -DDEBUG CXXFLAGS += -fno-default-inline -Wno-unused-function -Wno-unused-variable export WX_BUILD_DIR ?= $(BASE_DIR)/wxdebug WX_CONFIGURE_FLAGS += --enable-debug_flag --disable-debug_gdb --disable-debug_info endif #------ Debugger configuration ------ ifeq "$(origin DEBUGGER)" "command line" C_CXX_FLAGS += -ggdb WX_CONFIGURE_FLAGS += --enable-debug_gdb --enable-debug_info endif #------ Platform configuration ------ export PLATFORM := "Unknown" export PLATFORM_ARCH := "Unknown" export PLATFORM_UNSUPPORTED := 0 export CPU_ARCH ?= unknown ARCH = $(shell uname -p) ifeq "$(ARCH)" "unknown" ARCH = $(shell uname -m) endif ifneq (,$(filter i386 i486 i586 i686 x86,$(ARCH))) CPU_ARCH = x86 ASFLAGS += -f elf32 else ifneq (,$(filter x86_64 x86-64 amd64 x64,$(ARCH))) CPU_ARCH = x64 ASFLAGS += -f elf64 endif ifeq "$(origin NOASM)" "command line" CPU_ARCH = unknown endif ifeq "$(CPU_ARCH)" "x86" PLATFORM_ARCH := i386 C_CXX_FLAGS += -D TC_ARCH_X86 else ifeq "$(CPU_ARCH)" "x64" PLATFORM_ARCH := amd64 C_CXX_FLAGS += -D TC_ARCH_X64 endif #------ Linux configuration ------ ifeq "$(shell uname -s)" "Linux" PLATFORM := Linux C_CXX_FLAGS += -DTC_UNIX -DTC_LINUX ifeq "$(TC_BUILD_CONFIG)" "Release" C_CXX_FLAGS += -fdata-sections -ffunction-sections LFLAGS += -Wl,--gc-sections ifneq "$(shell ld --help 2>&1 | grep sysv | wc -l)" "0" LFLAGS += -Wl,--hash-style=sysv endif WXCONFIG_CFLAGS += -fdata-sections -ffunction-sections WXCONFIG_CXXFLAGS += -fdata-sections -ffunction-sections endif ifneq "$(origin WXSTATIC)" "command line" LFLAGS += -ldl endif endif #------ Mac OS X configuration ------ ifeq "$(shell uname -s)" "Darwin" PLATFORM := MacOSX APPNAME := VeraCrypt export VC_OSX_TARGET ?= 10.7 #check to see if XCode 3 path exists.Otherwise, use XCode 4 path VC_OSX_SDK := /Developer/SDKs/MacOSX$(VC_OSX_TARGET).sdk ifeq ($(wildcard $(VC_OSX_SDK)/SDKSettings.plist),) VC_OSX_SDK := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(VC_OSX_TARGET).sdk endif CC := gcc CXX := g++ C_CXX_FLAGS += -DTC_UNIX -DTC_BSD -DTC_MACOSX -mmacosx-version-min=$(VC_OSX_TARGET) -isysroot $(VC_OSX_SDK) LFLAGS += -mmacosx-version-min=$(VC_OSX_TARGET) -Wl,-syslibroot $(VC_OSX_SDK) WX_CONFIGURE_FLAGS += --with-macosx-version-min=$(VC_OSX_TARGET) --with-macosx-sdk=$(VC_OSX_SDK) ifeq "$(CPU_ARCH)" "x64" CPU_ARCH = x86 endif AS := $(BASE_DIR)/Build/Tools/MacOSX/nasm ASFLAGS += --prefix _ ifeq "$(TC_BUILD_CONFIG)" "Release" export DISABLE_PRECOMPILED_HEADERS := 1 S := $(C_CXX_FLAGS) C_CXX_FLAGS = $(subst -MMD,,$(S)) C_CXX_FLAGS += -gfull -arch i386 -arch x86_64 LFLAGS += -Wl,-dead_strip -arch i386 -arch x86_64 WX_CONFIGURE_FLAGS += --enable-universal_binary=i386,x86_64 WXCONFIG_CFLAGS += -gfull WXCONFIG_CXXFLAGS += -gfull else WX_CONFIGURE_FLAGS += --disable-universal_binary endif endif #------ FreeBSD configuration ------ ifeq "$(shell uname -s)" "FreeBSD" PLATFORM := FreeBSD PLATFORM_UNSUPPORTED := 1 C_CXX_FLAGS += -DTC_UNIX -DTC_BSD -DTC_FREEBSD endif #------ Solaris configuration ------ ifeq "$(shell uname -s)" "SunOS" PLATFORM := Solaris PLATFORM_UNSUPPORTED := 1 C_CXX_FLAGS += -DTC_UNIX -DTC_SOLARIS WX_CONFIGURE_FLAGS += --with-gtk endif #------ Common configuration ------ CFLAGS := $(C_CXX_FLAGS) $(CFLAGS) $(TC_EXTRA_CFLAGS) CXXFLAGS := $(C_CXX_FLAGS)
/*
  zip_crypto_openssl.h -- definitions for OpenSSL wrapper.
  Copyright (C) 2018-2021 Dieter Baron and Thomas Klausner

  This file is part of libzip, a library to manipulate ZIP archives.
  The authors can be contacted at <info@libzip.org>

  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. The names of the authors may not be used to endorse or promote
  products derived from this software without specific prior
  written permission.

  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
  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 AUTHORS 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.
*/

#ifndef HAD_ZIP_CRYPTO_OPENSSL_H
#define HAD_ZIP_CRYPTO_OPENSSL_H

#define HAVE_SECURE_RANDOM

#include <openssl/evp.h>
#include <openssl/hmac.h>

#if OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x02070000fL)
#define USE_OPENSSL_1_0_API
#elif OPENSSL_VERSION_NUMBER < 0x3000000fL
#define USE_OPENSSL_1_1_API
#else
#define USE_OPENSSL_3_API
#endif

#define _zip_crypto_aes_t EVP_CIPHER_CTX
#ifdef USE_OPENSSL_3_API
struct _zip_crypto_hmac_t {
    EVP_MAC *mac;
    EVP_MAC_CTX *ctx;
};
typedef struct _zip_crypto_hmac_t _zip_crypto_hmac_t;
#define _zip_crypto_hmac(hmac, data, length) (EVP_MAC_update((hmac->ctx), (data), (length)) == 1)
#else
#define _zip_crypto_hmac_t HMAC_CTX
#define _zip_crypto_hmac(hmac, data, length) (HMAC_Update((hmac), (data), (length)) == 1)
#endif

void _zip_crypto_aes_free(_zip_crypto_aes_t *aes);
bool _zip_crypto_aes_encrypt_block(_zip_crypto_aes_t *aes, const zip_uint8_t *in, zip_uint8_t *out);
_zip_crypto_aes_t *_zip_crypto_aes_new(const zip_uint8_t *key, zip_uint16_t key_size, zip_error_t *error);

void _zip_crypto_hmac_free(_zip_crypto_hmac_t *hmac);
_zip_crypto_hmac_t *_zip_crypto_hmac_new(const zip_uint8_t *secret, zip_uint64_t secret_length, zip_error_t *error);
bool _zip_crypto_hmac_output(_zip_crypto_hmac_t *hmac, zip_uint8_t *data);

#define _zip_crypto_pbkdf2(key, key_length, salt, salt_length, iterations, output, output_length) (PKCS5_PBKDF2_HMAC_SHA1((const char *)(key), (key_length), (salt), (salt_length), (iterations), (output_length), (output)))

#endif /*  HAD_ZIP_CRYPTO_OPENSSL_H */