Skip to content

Commit ef76088

Browse files
committed
Merge branch 'maint'
* maint: Update MD5 implementation from OpenSSL 3.5.0 to 3.6.0 Add update script for OpenSSL MD5 implementation
2 parents 22d2d2c + 3ccfc87 commit ef76088

File tree

9 files changed

+417
-62
lines changed

9 files changed

+417
-62
lines changed

erts/emulator/openssl/README

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
This directory contains a *very* small part of OpenSSL. Currently only parts
2-
of the OpenSSL MD5 implementation.
1+
%CopyrightBegin%
32

4-
The files that has been taken from the 3.1.4 version of OpenSSL:
3+
SPDX-License-Identifier: Apache-2.0
4+
5+
Copyright Ericsson AB 2025. All Rights Reserved.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
%CopyrightEnd%
20+
21+
22+
This directory contains a *very* small part of OpenSSL. Currently only
23+
parts of the OpenSSL MD5 implementation.
24+
25+
The files that has been taken from OpenSSL:
526

627
./LICENSE.txt
728
./crypto/md5/md5_local.h
829
./crypto/md5/md5_dgst.c
930
./include/crypto/md32_common.h
1031
./include/openssl_local/md5.h (renamed from include/openssl/md5.h)
1132

12-
The openssl.diff file contains the diff between the original files and the ones
13-
included in OTP.
14-
15-
Ignoring LICENSE.txt (which contains the full Apache 2.0 license) the
16-
copyright and license notice of the above OpenSSL files are as follows
17-
(copyright years differ a bit):
18-
19-
/*
20-
* Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
21-
*
22-
* Licensed under the Apache License 2.0 (the "License"). You may not use
23-
* this file except in compliance with the License. You can obtain a copy
24-
* in the file LICENSE in the source distribution or at
25-
* https://www.openssl.org/source/license.html
26-
*/
33+
The OpenSSL version that these files currently has been taken from can
34+
be found in the ./vendor.info file.
2735

36+
Update these files from the upstream OpenSSL repository by running the
37+
'./update' script. The script will update the files taken from OpenSSL
38+
and then mirror those to 'lib/erl_interface/src/openssl'. These two
39+
MD5 implementations should be kept in sync. Run "./update help" for
40+
more information about the script.

erts/emulator/openssl/crypto/md5/md5_local.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -20,9 +20,10 @@
2020

2121
#ifdef MD5_ASM
2222
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
23-
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
24-
defined(_M_X64) || defined(__aarch64__) || \
25-
(defined(__loongarch__) && __loongarch_grlen == 64)
23+
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
24+
defined(_M_X64) || defined(__aarch64__) || \
25+
(defined(__loongarch__) && __loongarch_grlen == 64) || \
26+
(defined(__riscv) && __riscv_xlen == 64)
2627
# define md5_block_data_order ossl_md5_block_asm_data_order
2728
# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
2829
# define md5_block_data_order ossl_md5_block_asm_data_order

erts/emulator/openssl/include/crypto/md32_common.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
2+
* Copyright 1999-2025 The OpenSSL Project Authors. All Rights Reserved.
33
*
44
* Licensed under the Apache License 2.0 (the "License"). You may not use
55
* this file except in compliance with the License. You can obtain a copy
@@ -65,6 +65,19 @@
6565

6666
#if !defined(ERLANG_OPENSSL_INTEGRATION)
6767
#include <openssl/crypto.h>
68+
/*
69+
* For ossl_(un)likely
70+
*/
71+
# include <internal/common.h>
72+
#else
73+
/* Cut from <internal/common.h> */
74+
# if defined(__GNUC__) || defined(__clang__)
75+
# define ossl_likely(x) __builtin_expect(!!(x), 1)
76+
# define ossl_unlikely(x) __builtin_expect(!!(x), 0)
77+
# else
78+
# define ossl_likely(x) (x)
79+
# define ossl_unlikely(x) (x)
80+
# endif
6881
#endif
6982

7083
#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
@@ -156,18 +169,18 @@ int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len)
156169
HASH_LONG l;
157170
size_t n;
158171

159-
if (len == 0)
172+
if (ossl_unlikely(len == 0))
160173
return 1;
161174

162175
l = (c->Nl + (((HASH_LONG) len) << 3)) & 0xffffffffUL;
163-
if (l < c->Nl) /* overflow */
176+
if (ossl_unlikely(l < c->Nl)) /* overflow */
164177
c->Nh++;
165178
c->Nh += (HASH_LONG) (len >> 29); /* might cause compiler warning on
166179
* 16-bit */
167180
c->Nl = l;
168181

169182
n = c->num;
170-
if (n != 0) {
183+
if (ossl_likely(n != 0)) {
171184
p = (unsigned char *)c->data;
172185

173186
if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) {

0 commit comments

Comments
 (0)