OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/messagedigest.h" | 11 #include "webrtc/base/messagedigest.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include <string.h> | 15 #include <string.h> |
16 | 16 |
17 #include "webrtc/base/basictypes.h" | 17 #include "webrtc/base/basictypes.h" |
| 18 #include "webrtc/base/sslconfig.h" |
| 19 #if SSL_USE_OPENSSL |
18 #include "webrtc/base/openssldigest.h" | 20 #include "webrtc/base/openssldigest.h" |
| 21 #else |
| 22 #include "webrtc/base/md5digest.h" |
| 23 #include "webrtc/base/sha1digest.h" |
| 24 #endif |
19 #include "webrtc/base/stringencode.h" | 25 #include "webrtc/base/stringencode.h" |
20 | 26 |
21 namespace rtc { | 27 namespace rtc { |
22 | 28 |
23 // From RFC 4572. | 29 // From RFC 4572. |
24 const char DIGEST_MD5[] = "md5"; | 30 const char DIGEST_MD5[] = "md5"; |
25 const char DIGEST_SHA_1[] = "sha-1"; | 31 const char DIGEST_SHA_1[] = "sha-1"; |
26 const char DIGEST_SHA_224[] = "sha-224"; | 32 const char DIGEST_SHA_224[] = "sha-224"; |
27 const char DIGEST_SHA_256[] = "sha-256"; | 33 const char DIGEST_SHA_256[] = "sha-256"; |
28 const char DIGEST_SHA_384[] = "sha-384"; | 34 const char DIGEST_SHA_384[] = "sha-384"; |
29 const char DIGEST_SHA_512[] = "sha-512"; | 35 const char DIGEST_SHA_512[] = "sha-512"; |
30 | 36 |
31 static const size_t kBlockSize = 64; // valid for SHA-256 and down | 37 static const size_t kBlockSize = 64; // valid for SHA-256 and down |
32 | 38 |
33 MessageDigest* MessageDigestFactory::Create(const std::string& alg) { | 39 MessageDigest* MessageDigestFactory::Create(const std::string& alg) { |
| 40 #if SSL_USE_OPENSSL |
34 MessageDigest* digest = new OpenSSLDigest(alg); | 41 MessageDigest* digest = new OpenSSLDigest(alg); |
35 if (digest->Size() == 0) { // invalid algorithm | 42 if (digest->Size() == 0) { // invalid algorithm |
36 delete digest; | 43 delete digest; |
37 digest = NULL; | 44 digest = NULL; |
38 } | 45 } |
39 return digest; | 46 return digest; |
| 47 #else |
| 48 MessageDigest* digest = NULL; |
| 49 if (alg == DIGEST_MD5) { |
| 50 digest = new Md5Digest(); |
| 51 } else if (alg == DIGEST_SHA_1) { |
| 52 digest = new Sha1Digest(); |
| 53 } |
| 54 return digest; |
| 55 #endif |
40 } | 56 } |
41 | 57 |
42 bool IsFips180DigestAlgorithm(const std::string& alg) { | 58 bool IsFips180DigestAlgorithm(const std::string& alg) { |
43 // These are the FIPS 180 algorithms. According to RFC 4572 Section 5, | 59 // These are the FIPS 180 algorithms. According to RFC 4572 Section 5, |
44 // "Self-signed certificates (for which legacy certificates are not a | 60 // "Self-signed certificates (for which legacy certificates are not a |
45 // consideration) MUST use one of the FIPS 180 algorithms (SHA-1, | 61 // consideration) MUST use one of the FIPS 180 algorithms (SHA-1, |
46 // SHA-224, SHA-256, SHA-384, or SHA-512) as their signature algorithm, | 62 // SHA-224, SHA-256, SHA-384, or SHA-512) as their signature algorithm, |
47 // and thus also MUST use it to calculate certificate fingerprints." | 63 // and thus also MUST use it to calculate certificate fingerprints." |
48 return alg == DIGEST_SHA_1 || | 64 return alg == DIGEST_SHA_1 || |
49 alg == DIGEST_SHA_224 || | 65 alg == DIGEST_SHA_224 || |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 174 } |
159 | 175 |
160 std::string ComputeHmac(const std::string& alg, const std::string& key, | 176 std::string ComputeHmac(const std::string& alg, const std::string& key, |
161 const std::string& input) { | 177 const std::string& input) { |
162 std::string output; | 178 std::string output; |
163 ComputeHmac(alg, key, input, &output); | 179 ComputeHmac(alg, key, input, &output); |
164 return output; | 180 return output; |
165 } | 181 } |
166 | 182 |
167 } // namespace rtc | 183 } // namespace rtc |
OLD | NEW |