aboutsummaryrefslogtreecommitdiff
path: root/crypto/md5
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/md5')
-rw-r--r--crypto/md5/asm/md5-586.pl10
-rw-r--r--crypto/md5/asm/md5-sparcv9.pl23
-rwxr-xr-xcrypto/md5/asm/md5-x86_64.pl28
-rw-r--r--crypto/md5/build.info41
-rw-r--r--crypto/md5/md5_dgst.c10
-rw-r--r--crypto/md5/md5_local.h10
-rw-r--r--crypto/md5/md5_one.c10
-rw-r--r--crypto/md5/md5_sha1.c108
8 files changed, 199 insertions, 41 deletions
diff --git a/crypto/md5/asm/md5-586.pl b/crypto/md5/asm/md5-586.pl
index 7986a2413da2..8dd8fa0cf765 100644
--- a/crypto/md5/asm/md5-586.pl
+++ b/crypto/md5/asm/md5-586.pl
@@ -1,7 +1,7 @@
#! /usr/bin/env perl
# Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
#
-# Licensed under the OpenSSL license (the "License"). You may not use
+# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
@@ -18,8 +18,10 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
push(@INC,"${dir}","${dir}../../perlasm");
require "x86asm.pl";
-$output=pop;
-open STDOUT,">$output";
+# $output is the last argument if it looks like a file (it has an extension)
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+
+$output and open STDOUT,">$output";
&asm_init($ARGV[0]);
@@ -40,7 +42,7 @@ $X="esi";
0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
);
-&md5_block("md5_block_asm_data_order");
+&md5_block("ossl_md5_block_asm_data_order");
&asm_finish();
close STDOUT or die "error closing STDOUT: $!";
diff --git a/crypto/md5/asm/md5-sparcv9.pl b/crypto/md5/asm/md5-sparcv9.pl
index 3595e3d32fc9..c41ccf6ba901 100644
--- a/crypto/md5/asm/md5-sparcv9.pl
+++ b/crypto/md5/asm/md5-sparcv9.pl
@@ -1,7 +1,7 @@
#! /usr/bin/env perl
-# Copyright 2012-2020 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2012-2021 The OpenSSL Project Authors. All Rights Reserved.
#
-# Licensed under the OpenSSL license (the "License"). You may not use
+# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
@@ -24,8 +24,10 @@
# single-process result on 8-core processor, or ~11GBps per 2.85GHz
# socket.
-$output=pop;
-open STDOUT,">$output";
+# $output is the last argument if it looks like a file (it has an extension)
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+
+$output and open STDOUT,">$output";
use integer;
@@ -201,7 +203,10 @@ ___
}
$code.=<<___;
-#include "sparc_arch.h"
+#ifndef __ASSEMBLER__
+# define __ASSEMBLER__ 1
+#endif
+#include "crypto/sparc_arch.h"
#ifdef __arch64__
.register %g2,#scratch
@@ -214,9 +219,9 @@ $code.=<<___;
SPARC_PIC_THUNK(%g1)
#endif
-.globl md5_block_asm_data_order
+.globl ossl_md5_block_asm_data_order
.align 32
-md5_block_asm_data_order:
+ossl_md5_block_asm_data_order:
SPARC_LOAD_ADDRESS_LEAF(OPENSSL_sparcv9cap_P,%g1,%g5)
ld [%g1+4],%g1 ! OPENSSL_sparcv9cap_P[1]
@@ -369,8 +374,8 @@ $code.=<<___;
wr %g0,$saved_asi,%asi
ret
restore
-.type md5_block_asm_data_order,#function
-.size md5_block_asm_data_order,(.-md5_block_asm_data_order)
+.type ossl_md5_block_asm_data_order,#function
+.size ossl_md5_block_asm_data_order,(.-ossl_md5_block_asm_data_order)
.asciz "MD5 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
.align 4
diff --git a/crypto/md5/asm/md5-x86_64.pl b/crypto/md5/asm/md5-x86_64.pl
index c6a172d448c6..6625fb7d08aa 100755
--- a/crypto/md5/asm/md5-x86_64.pl
+++ b/crypto/md5/asm/md5-x86_64.pl
@@ -2,7 +2,7 @@
# Author: Marc Bevand <bevand_m (at) epita.fr>
# Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
#
-# Licensed under the OpenSSL license (the "License"). You may not use
+# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
@@ -119,9 +119,10 @@ EOF
}
no warnings qw(uninitialized);
-my $flavour = shift;
-my $output = shift;
-if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
+# $output is the last argument if it looks like a file (it has an extension)
+# $flavour is the first argument if it doesn't look like a file
+my $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
+my $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
my $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
@@ -130,16 +131,17 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
die "can't locate x86_64-xlate.pl";
-open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
+open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
+ or die "can't call $xlate: $!";
*STDOUT=*OUT;
$code .= <<EOF;
.text
.align 16
-.globl md5_block_asm_data_order
-.type md5_block_asm_data_order,\@function,3
-md5_block_asm_data_order:
+.globl ossl_md5_block_asm_data_order
+.type ossl_md5_block_asm_data_order,\@function,3
+ossl_md5_block_asm_data_order:
.cfi_startproc
push %rbp
.cfi_push %rbp
@@ -281,7 +283,7 @@ $code .= <<EOF;
.Lepilogue:
ret
.cfi_endproc
-.size md5_block_asm_data_order,.-md5_block_asm_data_order
+.size ossl_md5_block_asm_data_order,.-ossl_md5_block_asm_data_order
EOF
# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
@@ -376,13 +378,13 @@ se_handler:
.section .pdata
.align 4
- .rva .LSEH_begin_md5_block_asm_data_order
- .rva .LSEH_end_md5_block_asm_data_order
- .rva .LSEH_info_md5_block_asm_data_order
+ .rva .LSEH_begin_ossl_md5_block_asm_data_order
+ .rva .LSEH_end_ossl_md5_block_asm_data_order
+ .rva .LSEH_info_ossl_md5_block_asm_data_order
.section .xdata
.align 8
-.LSEH_info_md5_block_asm_data_order:
+.LSEH_info_ossl_md5_block_asm_data_order:
.byte 9,0,0,0
.rva se_handler
___
diff --git a/crypto/md5/build.info b/crypto/md5/build.info
index e641fecd0d6e..9a325386065b 100644
--- a/crypto/md5/build.info
+++ b/crypto/md5/build.info
@@ -1,11 +1,40 @@
LIBS=../../libcrypto
-SOURCE[../../libcrypto]=\
- md5_dgst.c md5_one.c {- $target{md5_asm_src} -}
-GENERATE[md5-586.s]=asm/md5-586.pl \
- $(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS)
+$MD5ASM=
+IF[{- !$disabled{asm} -}]
+ $MD5ASM_x86=md5-586.S
+ $MD5ASM_x86_64=md5-x86_64.s
+ $MD5ASM_sparcv9=md5-sparcv9.S
-GENERATE[md5-x86_64.s]=asm/md5-x86_64.pl $(PERLASM_SCHEME)
+ # Now that we have defined all the arch specific variables, use the
+ # appropriate one, and define the appropriate macros
+ IF[$MD5ASM_{- $target{asm_arch} -}]
+ $MD5ASM=$MD5ASM_{- $target{asm_arch} -}
+ $MD5DEF=MD5_ASM
+ ENDIF
+ENDIF
-GENERATE[md5-sparcv9.S]=asm/md5-sparcv9.pl $(PERLASM_SCHEME)
+$COMMON=md5_dgst.c md5_one.c md5_sha1.c $MD5ASM
+SOURCE[../../libcrypto]=$COMMON
+
+# A no-deprecated no-shared build ends up with double function definitions
+# without conditioning this on dso. The issue is MD5 which is needed in the
+# legacy provider for one of the spliced algorithms, however it resides in the
+# default provider. A no-deprecated build removes the external definition from
+# libcrypto and this means that the code needs to be in liblegacy. However,
+# when building without 'dso', liblegacy is included in libcrypto.
+IF[{- !$disabled{module} && !$disabled{shared} -}]
+ SOURCE[../../providers/liblegacy.a]=$COMMON
+ENDIF
+
+# Implementations are now spread across several libraries, so the defines
+# need to be applied to all affected libraries and modules.
+DEFINE[../../libcrypto]=$MD5DEF
+DEFINE[../../providers/liblegacy.a]=$MD5DEF
+
+GENERATE[md5-586.S]=asm/md5-586.pl
+
+GENERATE[md5-x86_64.s]=asm/md5-x86_64.pl
+
+GENERATE[md5-sparcv9.S]=asm/md5-sparcv9.pl
INCLUDE[md5-sparcv9.o]=..
diff --git a/crypto/md5/md5_dgst.c b/crypto/md5/md5_dgst.c
index d84cba37ae98..913b1ea5cad6 100644
--- a/crypto/md5/md5_dgst.c
+++ b/crypto/md5/md5_dgst.c
@@ -1,12 +1,18 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
+/*
+ * MD5 low level APIs are deprecated for public use, but still ok for
+ * internal use.
+ */
+#include "internal/deprecated.h"
+
#include <stdio.h>
#include "md5_local.h"
#include <openssl/opensslv.h>
diff --git a/crypto/md5/md5_local.h b/crypto/md5/md5_local.h
index b0087bea81c4..22a0e0f62aed 100644
--- a/crypto/md5/md5_local.h
+++ b/crypto/md5/md5_local.h
@@ -1,7 +1,7 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
@@ -15,11 +15,11 @@
#ifdef MD5_ASM
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
-# define md5_block_data_order md5_block_asm_data_order
+# define md5_block_data_order ossl_md5_block_asm_data_order
# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
-# define md5_block_data_order md5_block_asm_data_order
+# define md5_block_data_order ossl_md5_block_asm_data_order
# elif defined(__sparc) || defined(__sparc__)
-# define md5_block_data_order md5_block_asm_data_order
+# define md5_block_data_order ossl_md5_block_asm_data_order
# endif
#endif
diff --git a/crypto/md5/md5_one.c b/crypto/md5/md5_one.c
index c3bf2f88f0ba..fe9b3df29e83 100644
--- a/crypto/md5/md5_one.c
+++ b/crypto/md5/md5_one.c
@@ -1,12 +1,18 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
+/*
+ * MD5 low level APIs are deprecated for public use, but still ok for
+ * internal use.
+ */
+#include "internal/deprecated.h"
+
#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
diff --git a/crypto/md5/md5_sha1.c b/crypto/md5/md5_sha1.c
new file mode 100644
index 000000000000..56defab163fa
--- /dev/null
+++ b/crypto/md5/md5_sha1.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/*
+ * MD5 and SHA-1 low level APIs are deprecated for public use, but still ok for
+ * internal use.
+ */
+#include "internal/deprecated.h"
+
+#include <string.h>
+#include "prov/md5_sha1.h"
+#include <openssl/evp.h>
+
+int ossl_md5_sha1_init(MD5_SHA1_CTX *mctx)
+{
+ if (!MD5_Init(&mctx->md5))
+ return 0;
+ return SHA1_Init(&mctx->sha1);
+}
+
+int ossl_md5_sha1_update(MD5_SHA1_CTX *mctx, const void *data, size_t count)
+{
+ if (!MD5_Update(&mctx->md5, data, count))
+ return 0;
+ return SHA1_Update(&mctx->sha1, data, count);
+}
+
+int ossl_md5_sha1_final(unsigned char *md, MD5_SHA1_CTX *mctx)
+{
+ if (!MD5_Final(md, &mctx->md5))
+ return 0;
+ return SHA1_Final(md + MD5_DIGEST_LENGTH, &mctx->sha1);
+}
+
+int ossl_md5_sha1_ctrl(MD5_SHA1_CTX *mctx, int cmd, int mslen, void *ms)
+{
+ unsigned char padtmp[48];
+ unsigned char md5tmp[MD5_DIGEST_LENGTH];
+ unsigned char sha1tmp[SHA_DIGEST_LENGTH];
+
+ if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
+ return -2;
+
+ if (mctx == NULL)
+ return 0;
+
+ /* SSLv3 client auth handling: see RFC-6101 5.6.8 */
+ if (mslen != 48)
+ return 0;
+
+ /* At this point hash contains all handshake messages, update
+ * with master secret and pad_1.
+ */
+
+ if (ossl_md5_sha1_update(mctx, ms, mslen) <= 0)
+ return 0;
+
+ /* Set padtmp to pad_1 value */
+ memset(padtmp, 0x36, sizeof(padtmp));
+
+ if (!MD5_Update(&mctx->md5, padtmp, sizeof(padtmp)))
+ return 0;
+
+ if (!MD5_Final(md5tmp, &mctx->md5))
+ return 0;
+
+ if (!SHA1_Update(&mctx->sha1, padtmp, 40))
+ return 0;
+
+ if (!SHA1_Final(sha1tmp, &mctx->sha1))
+ return 0;
+
+ /* Reinitialise context */
+
+ if (!ossl_md5_sha1_init(mctx))
+ return 0;
+
+ if (ossl_md5_sha1_update(mctx, ms, mslen) <= 0)
+ return 0;
+
+ /* Set padtmp to pad_2 value */
+ memset(padtmp, 0x5c, sizeof(padtmp));
+
+ if (!MD5_Update(&mctx->md5, padtmp, sizeof(padtmp)))
+ return 0;
+
+ if (!MD5_Update(&mctx->md5, md5tmp, sizeof(md5tmp)))
+ return 0;
+
+ if (!SHA1_Update(&mctx->sha1, padtmp, 40))
+ return 0;
+
+ if (!SHA1_Update(&mctx->sha1, sha1tmp, sizeof(sha1tmp)))
+ return 0;
+
+ /* Now when ctx is finalised it will return the SSL v3 hash value */
+
+ OPENSSL_cleanse(md5tmp, sizeof(md5tmp));
+ OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
+
+ return 1;
+}