line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/** |
2
|
|
|
|
|
|
|
* @file md5sha1.c |
3
|
|
|
|
|
|
|
* @version 950bba4 (HEAD -> master) |
4
|
|
|
|
|
|
|
* |
5
|
|
|
|
|
|
|
* Combined MD5+SHA1 hash for SSL 3.0 and TLS 1.0/1.1 handshake hash. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
/* |
8
|
|
|
|
|
|
|
* Copyright (c) 2013-2017 INSIDE Secure Corporation |
9
|
|
|
|
|
|
|
* Copyright (c) PeerSec Networks, 2002-2011 |
10
|
|
|
|
|
|
|
* All Rights Reserved |
11
|
|
|
|
|
|
|
* |
12
|
|
|
|
|
|
|
* The latest version of this code is available at http://www.matrixssl.org |
13
|
|
|
|
|
|
|
* |
14
|
|
|
|
|
|
|
* This software is open source; you can redistribute it and/or modify |
15
|
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by |
16
|
|
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
17
|
|
|
|
|
|
|
* (at your option) any later version. |
18
|
|
|
|
|
|
|
* |
19
|
|
|
|
|
|
|
* This General Public License does NOT permit incorporating this software |
20
|
|
|
|
|
|
|
* into proprietary programs. If you are unable to comply with the GPL, a |
21
|
|
|
|
|
|
|
* commercial license for this software may be purchased from INSIDE at |
22
|
|
|
|
|
|
|
* http://www.insidesecure.com/ |
23
|
|
|
|
|
|
|
* |
24
|
|
|
|
|
|
|
* This program is distributed in WITHOUT ANY WARRANTY; without even the |
25
|
|
|
|
|
|
|
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
26
|
|
|
|
|
|
|
* See the GNU General Public License for more details. |
27
|
|
|
|
|
|
|
* |
28
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License |
29
|
|
|
|
|
|
|
* along with this program; if not, write to the Free Software |
30
|
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
31
|
|
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html |
32
|
|
|
|
|
|
|
*/ |
33
|
|
|
|
|
|
|
/******************************************************************************/ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#include "../cryptoImpl.h" |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#ifdef USE_MATRIX_MD5SHA1 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# if !defined(USE_MD5) || !defined(USE_SHA1) |
40
|
|
|
|
|
|
|
# error USE_MD5 and USE_SHA1 required |
41
|
|
|
|
|
|
|
# endif |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
/******************************************************************************/ |
44
|
|
|
|
|
|
|
/** |
45
|
|
|
|
|
|
|
Maintain MD5 and SHA1 hashes of the same data. |
46
|
|
|
|
|
|
|
@note This could be done more optimally, give the use of this in TLS. |
47
|
|
|
|
|
|
|
Some state is shared between the two contexts, and some paralellism |
48
|
|
|
|
|
|
|
could be used in calculation. |
49
|
|
|
|
|
|
|
*/ |
50
|
12313
|
|
|
|
|
|
int32_t psMd5Sha1Init(psMd5Sha1_t *md) |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
int32_t rc; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# ifdef CRYPTO_ASSERT |
55
|
|
|
|
|
|
|
psAssert(md); |
56
|
|
|
|
|
|
|
# endif |
57
|
12313
|
50
|
|
|
|
|
if ((rc = psMd5Init(&md->md5)) < 0) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
|
return rc; |
60
|
|
|
|
|
|
|
} |
61
|
12313
|
50
|
|
|
|
|
if ((rc = psSha1Init(&md->sha1)) < 0) |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
/* We call Final to clear the state, ignoring the output */ |
64
|
0
|
|
|
|
|
|
psMd5Final(&md->md5, NULL); |
65
|
0
|
|
|
|
|
|
return rc; |
66
|
|
|
|
|
|
|
} |
67
|
12313
|
|
|
|
|
|
return PS_SUCCESS; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
/** |
71
|
|
|
|
|
|
|
Update MD5 and SHA1 hashes of the same data. |
72
|
|
|
|
|
|
|
*/ |
73
|
27667
|
|
|
|
|
|
void psMd5Sha1Update(psMd5Sha1_t *md, const unsigned char *buf, |
74
|
|
|
|
|
|
|
uint32_t len) |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
# ifdef CRYPTO_ASSERT |
77
|
|
|
|
|
|
|
psAssert(md && buf); |
78
|
|
|
|
|
|
|
# endif |
79
|
27667
|
|
|
|
|
|
psMd5Update(&md->md5, buf, len); |
80
|
27667
|
|
|
|
|
|
psSha1Update(&md->sha1, buf, len); |
81
|
27667
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
/** |
84
|
|
|
|
|
|
|
Finalize output of the combined MD5-SHA1 |
85
|
|
|
|
|
|
|
The output is 36 bytes, first the 16 bytes MD5 then the 20 bytes SHA1 |
86
|
|
|
|
|
|
|
*/ |
87
|
0
|
|
|
|
|
|
void psMd5Sha1Final(psMd5Sha1_t *md, unsigned char hash[MD5SHA1_HASHLEN]) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
# ifdef CRYPTO_ASSERT |
90
|
|
|
|
|
|
|
psAssert(md && hash); |
91
|
|
|
|
|
|
|
# endif |
92
|
0
|
|
|
|
|
|
psMd5Final(&md->md5, hash); |
93
|
0
|
|
|
|
|
|
psSha1Final(&md->sha1, hash + MD5_HASHLEN); |
94
|
0
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#endif /* USE_MATRIX_MD5SHA1 */ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
/******************************************************************************/ |
99
|
|
|
|
|
|
|
|