Skip to content

Commit 686a1b9

Browse files
committed
Merge branch 'openssl-25519/448'
Adds support for X25519/448 and Ed25519/448 via OpenSSL 1.1.1.
2 parents 2421b7d + a4e698b commit 686a1b9

22 files changed

+1956
-32
lines changed

.travis.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ env:
3838
matrix:
3939
include:
4040
- env: TEST=sonarcloud
41-
if: type = push
41+
if: type = push AND env(SONAR_TOKEN) IS present
4242
git:
4343
depth: false
4444
addons:
@@ -78,22 +78,13 @@ matrix:
7878
- env: TEST=printf-builtin LEAK_DETECTIVE=yes
7979
- env: TEST=printf-builtin LEAK_DETECTIVE=yes
8080
compiler: clang
81+
# the crypto plugins are build-tested with clang via "all" above
8182
- env: TEST=botan
82-
- env: TEST=botan
83-
compiler: clang
84-
- env: TEST=botan LEAK_DETECTIVE=yes
8583
- env: TEST=botan LEAK_DETECTIVE=yes
86-
compiler: clang
87-
- env: TEST=openssl
8884
- env: TEST=openssl
89-
compiler: clang
9085
- env: TEST=openssl LEAK_DETECTIVE=yes
91-
- env: TEST=openssl LEAK_DETECTIVE=yes
92-
compiler: clang
93-
- env: TEST=gcrypt
86+
- env: TEST=openssl-1.0
87+
- env: TEST=openssl-1.0 LEAK_DETECTIVE=yes
9488
- env: TEST=gcrypt
95-
compiler: clang
96-
- env: TEST=gcrypt LEAK_DETECTIVE=yes
9789
- env: TEST=gcrypt LEAK_DETECTIVE=yes
98-
compiler: clang
9990
- env: TEST=apidoc

scripts/dh_speed.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct {
4747
{"ecp192", ECP_192_BIT},
4848
{"ecp224", ECP_224_BIT},
4949
{"curve25519", CURVE_25519},
50+
{"curve448", CURVE_448},
5051
};
5152

5253
static void start_timing(struct timespec *start)

scripts/test.sh

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ build_botan()
1111
return
1212
fi
1313

14+
echo "$ build_botan()"
15+
1416
# if the leak detective is enabled we have to disable threading support
1517
# (used for std::async) as that causes invalid frees somehow, the
1618
# locking allocator causes a static leak via the first function that
@@ -43,7 +45,9 @@ build_tss2()
4345
return
4446
fi
4547

46-
# the default version of libgcrypt in Ubuntu 14.04 is too old
48+
echo "$ build_tss2()"
49+
50+
# the default version of libgcrypt in Ubuntu 16.04 is too old
4751
sudo apt-get update -qq && \
4852
sudo apt-get install -qq libgcrypt20-dev &&
4953
curl -L $TSS2_SRC | tar xz -C $TRAVIS_BUILD_DIR/.. &&
@@ -55,6 +59,42 @@ build_tss2()
5559
cd -
5660
}
5761

62+
build_openssl()
63+
{
64+
SSL_REV=1.1.1a
65+
SSL_PKG=openssl-$SSL_REV
66+
SSL_DIR=$TRAVIS_BUILD_DIR/../$SSL_PKG
67+
SSL_SRC=https://www.openssl.org/source/$SSL_PKG.tar.gz
68+
SSL_INS=/usr/local/ssl
69+
SSL_OPT="shared no-tls no-dtls no-ssl3 no-zlib no-comp no-idea no-psk no-srp
70+
no-stdio no-tests enable-rfc3779 enable-ec_nistp_64_gcc_128"
71+
72+
if test -d "$SSL_DIR"; then
73+
return
74+
fi
75+
76+
echo "$ build_openssl()"
77+
78+
curl -L $SSL_SRC | tar xz -C $TRAVIS_BUILD_DIR/.. &&
79+
cd $SSL_DIR &&
80+
./config --prefix=$SSL_INS --openssldir=$SSL_INS $SSL_OPT &&
81+
make -j4 >/dev/null &&
82+
sudo make install_sw >/dev/null &&
83+
echo $SSL_INS/lib | sudo tee /etc/ld.so.conf.d/openssl-$SSL_REV.conf >/dev/null &&
84+
sudo ldconfig || exit $?
85+
cd -
86+
}
87+
88+
use_custom_openssl()
89+
{
90+
CFLAGS="$CFLAGS -I/usr/local/ssl/include"
91+
LDFLAGS="$LDFLAGS -L/usr/local/ssl/lib"
92+
export LDFLAGS
93+
if test "$1" = "deps"; then
94+
build_openssl
95+
fi
96+
}
97+
5898
if test -z $TRAVIS_BUILD_DIR; then
5999
TRAVIS_BUILD_DIR=$PWD
60100
fi
@@ -72,9 +112,13 @@ default)
72112
# should be the default, but lets make sure
73113
CONFIG="--with-printf-hooks=glibc"
74114
;;
75-
openssl)
76-
CONFIG="--disable-defaults --enable-pki --enable-openssl"
115+
openssl*)
116+
CONFIG="--disable-defaults --enable-pki --enable-openssl --enable-pem"
77117
DEPS="libssl-dev"
118+
if test "$TEST" != "openssl-1.0"; then
119+
DEPS=""
120+
use_custom_openssl $1
121+
fi
78122
;;
79123
gcrypt)
80124
CONFIG="--disable-defaults --enable-pki --enable-gcrypt --enable-pkcs1"
@@ -119,6 +163,7 @@ all|coverage|sonarcloud)
119163
build_botan
120164
build_tss2
121165
fi
166+
use_custom_openssl $1
122167
;;
123168
win*)
124169
CONFIG="--disable-defaults --enable-svc --enable-ikev2

src/libstrongswan/plugins/curve25519/curve25519_public_key.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ METHOD(public_key_t, get_type, key_type_t,
4949
return KEY_ED25519;
5050
}
5151

52+
/* L = 2^252+27742317777372353535851937790883648493 in little-endian form */
53+
static chunk_t curve25519_order = chunk_from_chars(
54+
0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
55+
0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
56+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10);
58+
5259
METHOD(public_key_t, verify, bool,
5360
private_curve25519_public_key_t *this, signature_scheme_t scheme,
5461
void *params, chunk_t data, chunk_t signature)
@@ -94,6 +101,20 @@ METHOD(public_key_t, verify, bool,
94101
{
95102
return FALSE;
96103
}
104+
/* make sure 0 <= s < L, as per RFC 8032, section 5.1.7 to prevent signature
105+
* malleability. Due to the three-bit check above (forces s < 2^253) there
106+
* is not that much room, but adding L once works with most signatures */
107+
for (i = 31; ; i--)
108+
{
109+
if (sig[i+32] < curve25519_order.ptr[i])
110+
{
111+
break;
112+
}
113+
else if (sig[i+32] > curve25519_order.ptr[i] || i == 0)
114+
{
115+
return FALSE;
116+
}
117+
}
97118

98119
hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA512);
99120
if (!hasher)

src/libstrongswan/plugins/openssl/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ libstrongswan_openssl_la_SOURCES = \
2929
openssl_pkcs12.c openssl_pkcs12.h \
3030
openssl_rng.c openssl_rng.h \
3131
openssl_hmac.c openssl_hmac.h \
32-
openssl_gcm.c openssl_gcm.h
32+
openssl_gcm.c openssl_gcm.h \
33+
openssl_x_diffie_hellman.c openssl_x_diffie_hellman.h \
34+
openssl_ed_private_key.c openssl_ed_private_key.h \
35+
openssl_ed_public_key.c openssl_ed_public_key.h
3336

3437
libstrongswan_openssl_la_LDFLAGS = -module -avoid-version
3538
libstrongswan_openssl_la_LIBADD = $(OPENSSL_LIB)

0 commit comments

Comments
 (0)