From af21a56407763ce1bf5cc7c21c5f452991c71825 Mon Sep 17 00:00:00 2001 From: zmatsuo <6488847+zmatsuo@users.noreply.github.com> Date: Mon, 25 Mar 2024 00:56:12 +0900 Subject: [PATCH] =?UTF-8?q?libressl=203.9.0=20=E3=81=A7=E3=83=93=E3=83=AB?= =?UTF-8?q?=E3=83=89=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ed25519_crypto_api.h - 意図した ifdef になっていなかったので修正 - libressl 3.9.0 から、ライブラリ内の arc4random() が別名になった - includeを整理 - cmakeビルド時に使用する libs/include/compat/stdlib.h を libressl からコピーするようにした - libressl 3.9.0 から arc4random() が別名になった - .editorconfig - 一部ファイルの改行コードがLFなので対応した --- libs/buildall.cmake | 6 +++++ libs/buildlibressl.cmake | 16 +++++++++++++ libs/include/README.md | 4 +++- libs/include/compat/.gitkeep | 0 libs/include/compat/stdlib.h | 36 ---------------------------- ttssh2/ttxssh/.editorconfig | 2 ++ ttssh2/ttxssh/arc4random.c | 2 +- ttssh2/ttxssh/chacha.c | 2 -- ttssh2/ttxssh/cipher-3des1.c | 2 -- ttssh2/ttxssh/ed25519.c | 2 -- ttssh2/ttxssh/ed25519_bcrypt_pbkdf.c | 2 -- ttssh2/ttxssh/ed25519_blf.h | 2 -- ttssh2/ttxssh/ed25519_blowfish.c | 2 -- ttssh2/ttxssh/ed25519_crypto_api.h | 10 +++++++- ttssh2/ttxssh/ed25519_fe25519.c | 2 -- ttssh2/ttxssh/ed25519_ge25519.c | 2 -- ttssh2/ttxssh/ed25519_sc25519.c | 2 -- ttssh2/ttxssh/ed25519_verify.c | 2 -- ttssh2/ttxssh/poly1305.c | 2 -- 19 files changed, 37 insertions(+), 61 deletions(-) create mode 100644 libs/include/compat/.gitkeep delete mode 100644 libs/include/compat/stdlib.h create mode 100644 ttssh2/ttxssh/.editorconfig diff --git a/libs/buildall.cmake b/libs/buildall.cmake index 056274dd7..88ff13301 100644 --- a/libs/buildall.cmake +++ b/libs/buildall.cmake @@ -13,6 +13,12 @@ if("${CMAKE_GENERATOR}" STREQUAL "") message(FATAL_ERROR "set CMAKE_GENERATOR!") endif() +if(${CMAKE_GENERATOR} MATCHES "Visual Studio") + if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "CYGWIN") + message(FATAL_ERROR "cmake command is from cygwin") + endif() +endif() + if((${CMAKE_GENERATOR} MATCHES "Visual Studio 8 2005") OR (${CMAKE_GENERATOR} MATCHES "Visual Studio 9 2008")) set(BUILD_SSL_LIBRARY OFF) diff --git a/libs/buildlibressl.cmake b/libs/buildlibressl.cmake index bb388fed9..ebc376425 100644 --- a/libs/buildlibressl.cmake +++ b/libs/buildlibressl.cmake @@ -60,6 +60,22 @@ if(${SRC_DIR}/COPYING IS_NEWER_THAN ${CMAKE_CURRENT_LIST_DIR}/doc_help/LibreSSL- ${CMAKE_CURRENT_LIST_DIR}/doc_help/LibreSSL-LICENSE.txt) endif() +function(file_copy SRC DEST_DIR DEST) + set(SRC_FILE ${SRC}) + set(DEST_FILE ${DEST_DIR}/${DEST}) + file(SHA256 ${SRC_FILE} SRC_HASH) + if (EXISTS ${DEST_FILE}) + file(SHA256 ${DEST_FILE} DEST_HASH) + else() + set(DEST_HASH "0") + endif() + if (NOT ${SRC_HASH} STREQUAL ${DEST_HASH}) + file(COPY ${SRC_FILE} DESTINATION ${DEST_DIR}) + endif() +endfunction() + +file_copy(${SRC_DIR}/include/compat/stdlib.h ${CMAKE_CURRENT_LIST_DIR}/include/compat stdlib.h) + ######################################## file(MAKE_DIRECTORY "${BUILD_DIR}") diff --git a/libs/include/README.md b/libs/include/README.md index e96ea4f82..7bab56713 100644 --- a/libs/include/README.md +++ b/libs/include/README.md @@ -1,3 +1,5 @@  - compat/stdlib.h - - libressl内の関数をコールするためプロトタイプを定義したヘッダ + - cmakeビルド時のみ使用される + - libressl内の互換関数をコールするためのヘッダ + - libresslを展開するときにコピーされる diff --git a/libs/include/compat/.gitkeep b/libs/include/compat/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/libs/include/compat/stdlib.h b/libs/include/compat/stdlib.h deleted file mode 100644 index e7205c035..000000000 --- a/libs/include/compat/stdlib.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * (C) 2022- TeraTerm 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. The name of the author 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. - */ - -#pragma once - -/* - * libressl ̊֐ - * BSD ̓֐,stdlib.h - */ -uint32_t arc4random(void); -void arc4random_buf(void *_buf, size_t n); diff --git a/ttssh2/ttxssh/.editorconfig b/ttssh2/ttxssh/.editorconfig new file mode 100644 index 000000000..80f2be05d --- /dev/null +++ b/ttssh2/ttxssh/.editorconfig @@ -0,0 +1,2 @@ +[{cipher-chachapoly-libcrypto.c,ed25519.c,ed25519_bcrypt_pbkdf.c,ed25519_blowfish.c,ed25519_fe25519.c,ed25519_ge25519.c,ssherr.c,arc4random.h,chacha.h,cipher-chachapoly.h,ed25519_blf.h,ed25519_fe25519.h,hostkey.h,mac.h,poly1305.h,ssherr.h}] +end_of_line = lf diff --git a/ttssh2/ttxssh/arc4random.c b/ttssh2/ttxssh/arc4random.c index c50a2c3d7..08c9ade41 100644 --- a/ttssh2/ttxssh/arc4random.c +++ b/ttssh2/ttxssh/arc4random.c @@ -39,13 +39,13 @@ #include #define KEYSTREAM_ONLY -#include "ttxssh.h" /* * ̃\[X OpenSSL ̂Ƃg * LibreSSL ̂Ƃ libressl/crypto/compat/arc4random.c, * crypto/compat/getentropy_win.c g */ +#include "openssl/opensslv.h" // for LIBRESSL_VERSION_NUMBER #ifndef LIBRESSL_VERSION_NUMBER #include "arc4random.h" diff --git a/ttssh2/ttxssh/chacha.c b/ttssh2/ttxssh/chacha.c index 448ffe254..c6e96c08e 100755 --- a/ttssh2/ttxssh/chacha.c +++ b/ttssh2/ttxssh/chacha.c @@ -6,8 +6,6 @@ D. J. Bernstein Public domain. */ -// #include "includes.h" - /* * ̃\[X OpenSSL ̂Ƃg * LibreSSL ̂Ƃ libressl/crypto/compat/chacha_private.h g diff --git a/ttssh2/ttxssh/cipher-3des1.c b/ttssh2/ttxssh/cipher-3des1.c index 02a9d1aec..d3fd5d15e 100644 --- a/ttssh2/ttxssh/cipher-3des1.c +++ b/ttssh2/ttxssh/cipher-3des1.c @@ -20,8 +20,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// #include "includes.h" - #include #include #include diff --git a/ttssh2/ttxssh/ed25519.c b/ttssh2/ttxssh/ed25519.c index e884b5f46..9b12d4ce7 100644 --- a/ttssh2/ttxssh/ed25519.c +++ b/ttssh2/ttxssh/ed25519.c @@ -6,10 +6,8 @@ * Copied from supercop-20130419/crypto_sign/ed25519/ref/ed25519.c */ -//#include "includes.h" #include "ed25519_crypto_api.h" #include "ed25519_ge25519.h" -#include "ttxssh.h" static void get_hram(unsigned char *hram, const unsigned char *sm, const unsigned char *pk, unsigned char *playground, unsigned long long smlen) { diff --git a/ttssh2/ttxssh/ed25519_bcrypt_pbkdf.c b/ttssh2/ttxssh/ed25519_bcrypt_pbkdf.c index 6f0ea3c9d..06e885d53 100644 --- a/ttssh2/ttxssh/ed25519_bcrypt_pbkdf.c +++ b/ttssh2/ttxssh/ed25519_bcrypt_pbkdf.c @@ -15,8 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -//#include "includes.h" - #ifndef HAVE_BCRYPT_PBKDF #include diff --git a/ttssh2/ttxssh/ed25519_blf.h b/ttssh2/ttxssh/ed25519_blf.h index 00002a039..c06b362eb 100644 --- a/ttssh2/ttxssh/ed25519_blf.h +++ b/ttssh2/ttxssh/ed25519_blf.h @@ -34,7 +34,6 @@ #ifndef _BLF_H_ #define _BLF_H_ -//#include "includes.h" #include "ed25519_crypto_api.h" #include @@ -92,4 +91,3 @@ u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , u_int16_t *); #endif /* !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) */ #endif /* _BLF_H */ - diff --git a/ttssh2/ttxssh/ed25519_blowfish.c b/ttssh2/ttxssh/ed25519_blowfish.c index aae5367e5..4d0bb7257 100644 --- a/ttssh2/ttxssh/ed25519_blowfish.c +++ b/ttssh2/ttxssh/ed25519_blowfish.c @@ -39,8 +39,6 @@ * Bruce Schneier. */ -//#include "includes.h" - #if !defined(HAVE_BCRYPT_PBKDF) && (!defined(HAVE_BLOWFISH_INITSTATE) || \ !defined(HAVE_BLOWFISH_EXPAND0STATE) || !defined(HAVE_BLF_ENC)) diff --git a/ttssh2/ttxssh/ed25519_crypto_api.h b/ttssh2/ttxssh/ed25519_crypto_api.h index 8432f067d..a92e49c8b 100644 --- a/ttssh2/ttxssh/ed25519_crypto_api.h +++ b/ttssh2/ttxssh/ed25519_crypto_api.h @@ -32,11 +32,19 @@ #include #include +#include "openssl/opensslv.h" // for LIBRESSL_VERSION_NUMBER #ifndef LIBRESSL_VERSION_NUMBER #include "arc4random.h" #else + #if defined(__MINGW32__) || (_MSC_VER >= 1600) + #include + #else + // VS2008Â stdint.h Ȃ̂Ō݊wb_g + // TODO libressl 2008 Ńrhł邩͕s + #include "compat/stdint.h" + #endif // include LibreSSL header file - #include + #include "compat/stdlib.h" #endif typedef unsigned char u_int8_t; diff --git a/ttssh2/ttxssh/ed25519_fe25519.c b/ttssh2/ttxssh/ed25519_fe25519.c index a2968306b..6afa17a09 100644 --- a/ttssh2/ttxssh/ed25519_fe25519.c +++ b/ttssh2/ttxssh/ed25519_fe25519.c @@ -6,8 +6,6 @@ * Copied from supercop-20130419/crypto_sign/ed25519/ref/fe25519.c */ -//#include "includes.h" - #define WINDOWSIZE 1 /* Should be 1,2, or 4 */ #define WINDOWMASK ((1<