Skip to content

Commit e270511

Browse files
committed
erts,erl_interface: Add alternative to openssl for MD5
Backported from 29(master) to 28 from af62c54 and 6281ea6 Made optional with configure --disable-builtin-openssl or with --enable-use-embedded-3pp-alternatives.
1 parent c99c94a commit e270511

21 files changed

Lines changed: 652 additions & 59 deletions

File tree

erts/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
/* Define if builtin errno id should be used */
8282
#undef ERTS_USE_BUILTIN_ERRNO_ID
8383

84+
/* Define if builtin OpenSSL should be used for MD5 */
85+
#undef ERTS_USE_BUILTIN_OPENSSL
86+
8487
/* Define if builtin ryu should be used */
8588
#undef ERTS_USE_BUILTIN_RYU
8689

erts/configure

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ SYSTEMD_DAEMON_LIBS
672672
SOCKET_LIBS
673673
Z_LIB
674674
LIBZSTD
675+
ERTS_USE_BUILTIN_OPENSSL
675676
ERTS_USE_BUILTIN_ERRNO_ID
676677
TERMCAP_LIB
677678
THR_DEFS
@@ -858,6 +859,7 @@ with_threadnames
858859
enable_use_embedded_3pp_alternatives
859860
enable_builtin_errno_id
860861
enable_builtin_ryu
862+
enable_builtin_openssl
861863
enable_builtin_zstd
862864
enable_builtin_zlib
863865
enable_esock
@@ -1622,6 +1624,10 @@ Optional Features:
16221624
--enable-builtin-ryu use our own built-in ryu for float to short string
16231625
(default)
16241626
--disable-builtin-ryu use C++17 as an alternative for built-in ryu
1627+
--enable-builtin-openssl
1628+
use our own built-in OpenSSL for MD5 (default)
1629+
--disable-builtin-openssl
1630+
use an alternative for built-in OpenSSL
16251631
--enable-builtin-zstd force use of our own built-in zstd (default)
16261632
--disable-builtin-zstd try to find a static libzstd on the system to use
16271633
--enable-builtin-zlib force use of our own built-in zlib
@@ -16682,12 +16688,14 @@ then :
1668216688
no)
1668316689
builtin_errno_id=yes
1668416690
builtin_ryu=yes
16691+
builtin_openssl=yes
1668516692
builtin_zstd=yes
1668616693
builtin_zlib=yes
1668716694
;;
1668816695
*)
1668916696
builtin_errno_id=no
1669016697
builtin_ryu=no
16698+
builtin_openssl=no
1669116699
builtin_zstd=no
1669216700
builtin_zlib=no
1669316701
;;
@@ -16750,6 +16758,33 @@ fi
1675016758

1675116759

1675216760

16761+
# Check whether --enable-builtin-openssl was given.
16762+
if test ${enable_builtin_openssl+y}
16763+
then :
16764+
enableval=$enable_builtin_openssl; case "$enableval" in
16765+
no) builtin_openssl=no ;;
16766+
*) builtin_openssl=yes ;;
16767+
esac
16768+
fi
16769+
16770+
16771+
if test "$builtin_openssl" = "no"
16772+
then :
16773+
16774+
ERTS_USE_BUILTIN_OPENSSL=no
16775+
16776+
else case e in #(
16777+
e)
16778+
16779+
printf "%s\n" "#define ERTS_USE_BUILTIN_OPENSSL 1" >>confdefs.h
16780+
16781+
ERTS_USE_BUILTIN_OPENSSL=yes
16782+
;;
16783+
esac
16784+
fi
16785+
16786+
16787+
1675316788
# Check whether --enable-builtin-zstd was given.
1675416789
if test ${enable_builtin_zstd+y}
1675516790
then :

erts/configure.ac

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,12 +1264,14 @@ AS_HELP_STRING([--disable-use-embedded-3pp-alternatives],
12641264
no)
12651265
builtin_errno_id=yes
12661266
builtin_ryu=yes
1267+
builtin_openssl=yes
12671268
builtin_zstd=yes
12681269
builtin_zlib=yes
12691270
;;
12701271
*)
12711272
builtin_errno_id=no
12721273
builtin_ryu=no
1274+
builtin_openssl=no
12731275
builtin_zstd=no
12741276
builtin_zlib=no
12751277
;;
@@ -1321,6 +1323,30 @@ AS_HELP_STRING([--disable-builtin-ryu],
13211323
*) builtin_ryu=yes ;;
13221324
esac])
13231325

1326+
dnl -------------
1327+
dnl openssl (MD5)
1328+
dnl -------------
1329+
1330+
AC_ARG_ENABLE(builtin-openssl,
1331+
AS_HELP_STRING([--enable-builtin-openssl],
1332+
[use our own built-in OpenSSL for MD5 (default)])
1333+
AS_HELP_STRING([--disable-builtin-openssl],
1334+
[use an alternative for built-in OpenSSL]),
1335+
[case "$enableval" in
1336+
no) builtin_openssl=no ;;
1337+
*) builtin_openssl=yes ;;
1338+
esac])
1339+
1340+
AS_IF([test "$builtin_openssl" = "no"],
1341+
[
1342+
ERTS_USE_BUILTIN_OPENSSL=no
1343+
],
1344+
[
1345+
AC_DEFINE(ERTS_USE_BUILTIN_OPENSSL, [1], [Define if builtin OpenSSL should be used for MD5])
1346+
ERTS_USE_BUILTIN_OPENSSL=yes
1347+
])
1348+
AC_SUBST(ERTS_USE_BUILTIN_OPENSSL)
1349+
13241350
dnl -------------
13251351
dnl zstd
13261352
dnl -------------

erts/emulator/Makefile.in

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ NO_INLINE_FUNCTIONS=false
3939
USING_VC=@MIXED_VC@
4040
VISIBILITY_HIDDEN=@VISIBILITY_HIDDEN@
4141
ERTS_USE_BUILTIN_RYU=@ERTS_USE_BUILTIN_RYU@
42+
ERTS_USE_BUILTIN_OPENSSL=@ERTS_USE_BUILTIN_OPENSSL@
4243

4344
OPCODE_TABLES = \
4445
$(ERL_TOP)/lib/compiler/src/genop.tab \
@@ -394,13 +395,15 @@ LIBS += $(RYU_LIBRARY)
394395
endif
395396
endif
396397

398+
ifeq ($(ERTS_USE_BUILTIN_OPENSSL),yes)
397399
DEPLIBS += $(OPENSSL_LIB)
398400
ifeq ($(TARGET),win32)
399401
LIBS += -L$(OPENSSL_OBJDIR) -l$(OPENSSL_LIB_NAME)
400402
else
401403
# Build on darwin fails if -l$(OPENSSL_LIB_NAME) is used
402404
LIBS += $(OPENSSL_LIB)
403405
endif
406+
endif
404407

405408
ifdef LIBZSTD
406409
# Use system libzstd
@@ -542,7 +545,9 @@ include pcre/pcre.mk
542545
ifeq ($(ERTS_USE_BUILTIN_RYU),yes)
543546
include ryu/ryu.mk
544547
endif
548+
ifeq ($(ERTS_USE_BUILTIN_OPENSSL),yes)
545549
include openssl/openssl.mk
550+
endif
546551
include zstd/zstd.mk
547552

548553
$(ERTS_LIB):
@@ -859,7 +864,10 @@ endif
859864
ifeq ($(ERTS_USE_BUILTIN_RYU),yes)
860865
COMMON_INCLUDES += -Iryu
861866
endif
862-
COMMON_INCLUDES += -Ipcre -Iopenssl/include
867+
ifeq ($(ERTS_USE_BUILTIN_OPENSSL),yes)
868+
COMMON_INCLUDES += -Iopenssl/include
869+
endif
870+
COMMON_INCLUDES += -Ipcre
863871
COMMON_INCLUDES += -I../include -I../include/$(TARGET)
864872
COMMON_INCLUDES += -I../include/internal -I../include/internal/$(TARGET)
865873

@@ -1205,6 +1213,10 @@ RUN_OBJS += \
12051213
$(OBJDIR)/erl_iolist.o \
12061214
$(OBJDIR)/erl_etp.o
12071215

1216+
ifneq ($(ERTS_USE_BUILTIN_OPENSSL),yes)
1217+
RUN_OBJS += $(OBJDIR)/erl_md5.o
1218+
endif
1219+
12081220
LTTNG_OBJS = $(OBJDIR)/erlang_lttng.o
12091221

12101222
NIF_OBJS = \

erts/emulator/beam/beam_file.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,23 +1262,23 @@ beamfile_read(const byte *data, size_t size, BeamFile *beam) {
12621262

12631263
/* Compute module checksum. Please keep all parsing above this section */
12641264
{
1265-
MD5_CTX md5;
1265+
erts_md5_state md5;
12661266

1267-
MD5Init(&md5);
1267+
erts_md5_init(&md5);
12681268

1269-
MD5Update(&md5,
1269+
erts_md5_update(&md5,
12701270
(byte*)chunks[UTF8_ATOM_CHUNK].data,
12711271
chunks[UTF8_ATOM_CHUNK].size);
1272-
MD5Update(&md5,
1272+
erts_md5_update(&md5,
12731273
(byte*)chunks[CODE_CHUNK].data,
12741274
chunks[CODE_CHUNK].size);
1275-
MD5Update(&md5,
1275+
erts_md5_update(&md5,
12761276
(byte*)chunks[STR_CHUNK].data,
12771277
chunks[STR_CHUNK].size);
1278-
MD5Update(&md5,
1278+
erts_md5_update(&md5,
12791279
(byte*)chunks[IMP_CHUNK].data,
12801280
chunks[IMP_CHUNK].size);
1281-
MD5Update(&md5,
1281+
erts_md5_update(&md5,
12821282
(byte*)chunks[EXP_CHUNK].data,
12831283
chunks[EXP_CHUNK].size);
12841284

@@ -1290,7 +1290,7 @@ beamfile_read(const byte *data, size_t size, BeamFile *beam) {
12901290
* checksum hash, as it's derived using a (broken and superseded)
12911291
* endian-dependent hash function. */
12921292
if (left >= 4) {
1293-
MD5Update(&md5, (byte*)start, 4);
1293+
erts_md5_update(&md5, (byte*)start, 4);
12941294

12951295
start += 4;
12961296
left -= 4;
@@ -1299,9 +1299,9 @@ beamfile_read(const byte *data, size_t size, BeamFile *beam) {
12991299
static byte zero[4] = {0, 0, 0, 0};
13001300

13011301
/* Include: Function Arity Index NumFree */
1302-
MD5Update(&md5, (byte*)start, 20);
1302+
erts_md5_update(&md5, (byte*)start, 20);
13031303
/* Set to zero: OldUniq */
1304-
MD5Update(&md5, (byte*)zero, 4);
1304+
erts_md5_update(&md5, (byte*)zero, 4);
13051305

13061306
start += 24;
13071307
left -= 24;
@@ -1315,18 +1315,18 @@ beamfile_read(const byte *data, size_t size, BeamFile *beam) {
13151315
}
13161316

13171317
if (chunks[LITERAL_CHUNK].size > 0) {
1318-
MD5Update(&md5,
1318+
erts_md5_update(&md5,
13191319
(byte*)chunks[LITERAL_CHUNK].data,
13201320
chunks[LITERAL_CHUNK].size);
13211321
}
13221322

13231323
if (chunks[META_CHUNK].size > 0) {
1324-
MD5Update(&md5,
1324+
erts_md5_update(&md5,
13251325
(byte*)chunks[META_CHUNK].data,
13261326
chunks[META_CHUNK].size);
13271327
}
13281328

1329-
MD5Final(beam->checksum, &md5);
1329+
erts_md5_finish(beam->checksum, &md5);
13301330
}
13311331

13321332
return BEAMFILE_READ_SUCCESS;

0 commit comments

Comments
 (0)