2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2020-11-26 22:18:57 +08:00
|
|
|
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:56:39 +08:00
|
|
|
*
|
2018-12-06 20:44:44 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* 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
|
1998-12-21 18:56:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-12-28 10:41:17 +08:00
|
|
|
#include <openssl/e_os2.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/md5.h>
|
1998-12-21 18:56:39 +08:00
|
|
|
|
1999-05-13 21:16:42 +08:00
|
|
|
#ifdef MD5_ASM
|
2016-05-01 20:14:34 +08:00
|
|
|
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
|
2021-10-28 00:50:30 +08:00
|
|
|
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
|
|
|
|
defined(_M_X64) || defined(__aarch64__)
|
2020-11-16 09:57:52 +08:00
|
|
|
# define md5_block_data_order ossl_md5_block_asm_data_order
|
2005-07-20 06:37:57 +08:00
|
|
|
# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
|
2020-11-16 09:57:52 +08:00
|
|
|
# define md5_block_data_order ossl_md5_block_asm_data_order
|
2012-09-24 04:39:53 +08:00
|
|
|
# elif defined(__sparc) || defined(__sparc__)
|
2020-11-16 09:57:52 +08:00
|
|
|
# define md5_block_data_order ossl_md5_block_asm_data_order
|
1999-05-13 21:16:42 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
void md5_block_data_order(MD5_CTX *c, const void *p, size_t num);
|
1998-12-21 18:56:39 +08:00
|
|
|
|
1999-05-13 21:16:42 +08:00
|
|
|
#define DATA_ORDER_IS_LITTLE_ENDIAN
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
#define HASH_LONG MD5_LONG
|
|
|
|
#define HASH_CTX MD5_CTX
|
|
|
|
#define HASH_CBLOCK MD5_CBLOCK
|
|
|
|
#define HASH_UPDATE MD5_Update
|
|
|
|
#define HASH_TRANSFORM MD5_Transform
|
|
|
|
#define HASH_FINAL MD5_Final
|
|
|
|
#define HASH_MAKE_STRING(c,s) do { \
|
|
|
|
unsigned long ll; \
|
|
|
|
ll=(c)->A; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->B; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->C; (void)HOST_l2c(ll,(s)); \
|
|
|
|
ll=(c)->D; (void)HOST_l2c(ll,(s)); \
|
|
|
|
} while (0)
|
|
|
|
#define HASH_BLOCK_DATA_ORDER md5_block_data_order
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/md32_common.h"
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2015-01-05 08:34:00 +08:00
|
|
|
/*-
|
2015-01-22 11:40:55 +08:00
|
|
|
#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
|
|
|
|
#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
|
1998-12-21 18:56:39 +08:00
|
|
|
*/
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2017-10-11 05:55:09 +08:00
|
|
|
* As pointed out by Wei Dai, the above can be simplified to the code
|
|
|
|
* below. Wei attributes these optimizations to Peter Gutmann's
|
2015-01-22 11:40:55 +08:00
|
|
|
* SHS code, and he attributes it to Rich Schroeppel.
|
1998-12-21 18:56:39 +08:00
|
|
|
*/
|
2015-01-22 11:40:55 +08:00
|
|
|
#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
|
|
|
|
#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c))
|
|
|
|
#define H(b,c,d) ((b) ^ (c) ^ (d))
|
|
|
|
#define I(b,c,d) (((~(d)) | (b)) ^ (c))
|
1998-12-21 18:56:39 +08:00
|
|
|
|
|
|
|
#define R0(a,b,c,d,k,s,t) { \
|
2015-01-22 11:40:55 +08:00
|
|
|
a+=((k)+(t)+F((b),(c),(d))); \
|
|
|
|
a=ROTATE(a,s); \
|
2019-10-31 21:17:31 +08:00
|
|
|
a+=b; };
|
1998-12-21 18:56:39 +08:00
|
|
|
|
|
|
|
#define R1(a,b,c,d,k,s,t) { \
|
2015-01-22 11:40:55 +08:00
|
|
|
a+=((k)+(t)+G((b),(c),(d))); \
|
|
|
|
a=ROTATE(a,s); \
|
|
|
|
a+=b; };
|
1998-12-21 18:56:39 +08:00
|
|
|
|
|
|
|
#define R2(a,b,c,d,k,s,t) { \
|
2015-01-22 11:40:55 +08:00
|
|
|
a+=((k)+(t)+H((b),(c),(d))); \
|
|
|
|
a=ROTATE(a,s); \
|
|
|
|
a+=b; };
|
1998-12-21 18:56:39 +08:00
|
|
|
|
|
|
|
#define R3(a,b,c,d,k,s,t) { \
|
2015-01-22 11:40:55 +08:00
|
|
|
a+=((k)+(t)+I((b),(c),(d))); \
|
|
|
|
a=ROTATE(a,s); \
|
|
|
|
a+=b; };
|