Skip to content

Commit

Permalink
libressl 3.9.0 でビルドできるよう修正
Browse files Browse the repository at this point in the history
- 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なので対応した
  • Loading branch information
zmatsuo committed Mar 24, 2024
1 parent 9635fcd commit af21a56
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 61 deletions.
6 changes: 6 additions & 0 deletions libs/buildall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions libs/buildlibressl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 3 additions & 1 deletion libs/include/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

- compat/stdlib.h
- libressl内の関数をコールするためプロトタイプを定義したヘッダ
- cmakeビルド時のみ使用される
- libressl内の互換関数をコールするためのヘッダ
- libresslを展開するときにコピーされる
Empty file added libs/include/compat/.gitkeep
Empty file.
36 changes: 0 additions & 36 deletions libs/include/compat/stdlib.h

This file was deleted.

2 changes: 2 additions & 0 deletions ttssh2/ttxssh/.editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion ttssh2/ttxssh/arc4random.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
#include <process.h>

#define KEYSTREAM_ONLY
#include "ttxssh.h"

/*
* このソースは OpenSSL のときだけ使われる
* LibreSSL のときは libressl/crypto/compat/arc4random.c,
* crypto/compat/getentropy_win.c が使われる
*/
#include "openssl/opensslv.h" // for LIBRESSL_VERSION_NUMBER
#ifndef LIBRESSL_VERSION_NUMBER

#include "arc4random.h"
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ D. J. Bernstein
Public domain.
*/

// #include "includes.h"

/*
* このソースは OpenSSL のときだけ使われる
* LibreSSL のときは libressl/crypto/compat/chacha_private.h が使われる
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/cipher-3des1.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// #include "includes.h"

#include <sys/types.h>
#include <string.h>
#include <openssl/evp.h>
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_bcrypt_pbkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

//#include "includes.h"

#ifndef HAVE_BCRYPT_PBKDF

#include <sys/types.h>
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_blf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#ifndef _BLF_H_
#define _BLF_H_

//#include "includes.h"
#include "ed25519_crypto_api.h"
#include <malloc.h>

Expand Down Expand Up @@ -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 */

2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_blowfish.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
10 changes: 9 additions & 1 deletion ttssh2/ttxssh/ed25519_crypto_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@
#include <stdio.h>
#include <stdlib.h>

#include "openssl/opensslv.h" // for LIBRESSL_VERSION_NUMBER
#ifndef LIBRESSL_VERSION_NUMBER
#include "arc4random.h"
#else
#if defined(__MINGW32__) || (_MSC_VER >= 1600)
#include <stdint.h>
#else
// VS2008より古いと stdint.h がないので互換ヘッダを使う
// TODO libressl が 2008 でビルドできるかは不明
#include "compat/stdint.h"
#endif
// include LibreSSL header file
#include <compat/stdlib.h>
#include "compat/stdlib.h"
#endif

typedef unsigned char u_int8_t;
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_fe25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<<WINDOWSIZE)-1)

Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_ge25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* Copied from supercop-20130419/crypto_sign/ed25519/ref/ge25519.c
*/

//#include "includes.h"

#include "ed25519_fe25519.h"
#include "ed25519_sc25519.h"
#include "ed25519_ge25519.h"
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_sc25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* Copied from supercop-20130419/crypto_sign/ed25519/ref/sc25519.c
*/

//#include "includes.h"

#include "ed25519_sc25519.h"

/*Arithmetic modulo the group order m = 2^252 + 27742317777372353535851937790883648493 = 7237005577332262213973186563042994240857116359379907606001950938285454250989 */
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/ed25519_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Copied from nacl-20110221/crypto_verify/32/ref/verify.c
*/

//#include "includes.h"

#include "ed25519_crypto_api.h"

int crypto_verify_32(const unsigned char *x,const unsigned char *y)
Expand Down
2 changes: 0 additions & 2 deletions ttssh2/ttxssh/poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/* $OpenBSD: poly1305.c,v 1.3 2013/12/19 22:57:13 djm Exp $ */

// #include "includes.h"

// for Visual Studio 2005
#pragma warning(disable : 4244)

Expand Down

0 comments on commit af21a56

Please sign in to comment.