Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: crypto/signature_creator.h

Issue 560583002: Generalize crypto::SignatureCreator to allow choice of hash function, so as to support SHA256 (not … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, fix some lint issues, and a shameful missing ")" Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/policy/core/common/cloud/policy_builder.cc ('k') | crypto/signature_creator_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CRYPTO_SIGNATURE_CREATOR_H_ 5 #ifndef CRYPTO_SIGNATURE_CREATOR_H_
6 #define CRYPTO_SIGNATURE_CREATOR_H_ 6 #define CRYPTO_SIGNATURE_CREATOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "crypto/crypto_export.h" 12 #include "crypto/crypto_export.h"
13 13
14 #if defined(USE_OPENSSL) 14 #if defined(USE_OPENSSL)
15 // Forward declaration for openssl/*.h 15 // Forward declaration for openssl/*.h
16 typedef struct env_md_ctx_st EVP_MD_CTX; 16 typedef struct env_md_ctx_st EVP_MD_CTX;
17 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 17 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
18 // Forward declaration. 18 // Forward declaration.
19 struct SGNContextStr; 19 struct SGNContextStr;
20 #endif 20 #endif
21 21
22 namespace crypto { 22 namespace crypto {
23 23
24 class RSAPrivateKey; 24 class RSAPrivateKey;
25 25
26 // Signs data using a bare private key (as opposed to a full certificate). 26 // Signs data using a bare private key (as opposed to a full certificate).
27 // Currently can only sign data using SHA-1 with RSA encryption. 27 // Currently can only sign data using SHA-1 or SHA-256 with RSA PKCS#1v1.5.
28 class CRYPTO_EXPORT SignatureCreator { 28 class CRYPTO_EXPORT SignatureCreator {
29 public: 29 public:
30 // The set of supported hash functions. Extend as required.
31 enum HashAlgorithm {
32 SHA1,
33 SHA256,
34 };
35
30 ~SignatureCreator(); 36 ~SignatureCreator();
31 37
32 // Create an instance. The caller must ensure that the provided PrivateKey 38 // Create an instance. The caller must ensure that the provided PrivateKey
33 // instance outlives the created SignatureCreator. 39 // instance outlives the created SignatureCreator. Uses the HashAlgorithm
34 static SignatureCreator* Create(RSAPrivateKey* key); 40 // specified.
41 static SignatureCreator* Create(RSAPrivateKey* key, HashAlgorithm hash_alg);
35 42
36 // Signs the precomputed SHA-1 digest |data| using private |key| as 43
44 // Signs the precomputed |hash_alg| digest |data| using private |key| as
37 // specified in PKCS #1 v1.5. 45 // specified in PKCS #1 v1.5.
38 static bool Sign(RSAPrivateKey* key, 46 static bool Sign(RSAPrivateKey* key,
47 HashAlgorithm hash_alg,
39 const uint8* data, 48 const uint8* data,
40 int data_len, 49 int data_len,
41 std::vector<uint8>* signature); 50 std::vector<uint8>* signature);
42 51
43 // Update the signature with more data. 52 // Update the signature with more data.
44 bool Update(const uint8* data_part, int data_part_len); 53 bool Update(const uint8* data_part, int data_part_len);
45 54
46 // Finalize the signature. 55 // Finalize the signature.
47 bool Final(std::vector<uint8>* signature); 56 bool Final(std::vector<uint8>* signature);
48 57
49 private: 58 private:
50 // Private constructor. Use the Create() method instead. 59 // Private constructor. Use the Create() method instead.
51 SignatureCreator(); 60 SignatureCreator();
52 61
53 RSAPrivateKey* key_; 62 RSAPrivateKey* key_;
54 63
55 #if defined(USE_OPENSSL) 64 #if defined(USE_OPENSSL)
56 EVP_MD_CTX* sign_context_; 65 EVP_MD_CTX* sign_context_;
57 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 66 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
58 SGNContextStr* sign_context_; 67 SGNContextStr* sign_context_;
59 #endif 68 #endif
60 69
61 DISALLOW_COPY_AND_ASSIGN(SignatureCreator); 70 DISALLOW_COPY_AND_ASSIGN(SignatureCreator);
62 }; 71 };
63 72
64 } // namespace crypto 73 } // namespace crypto
65 74
66 #endif // CRYPTO_SIGNATURE_CREATOR_H_ 75 #endif // CRYPTO_SIGNATURE_CREATOR_H_
OLDNEW
« no previous file with comments | « components/policy/core/common/cloud/policy_builder.cc ('k') | crypto/signature_creator_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698