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

Side by Side Diff: crypto/signature_verifier.h

Issue 17776003: Add SignatureVerifier::VerifyInitRSAPSS for verifying RSA-PSS signatures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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_VERIFIER_H_ 5 #ifndef CRYPTO_SIGNATURE_VERIFIER_H_
6 #define CRYPTO_SIGNATURE_VERIFIER_H_ 6 #define CRYPTO_SIGNATURE_VERIFIER_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "crypto/crypto_export.h" 13 #include "crypto/crypto_export.h"
14 14
15 #if !defined(USE_OPENSSL) 15 #if defined(USE_OPENSSL)
16 typedef struct env_md_st EVP_MD;
17 typedef struct evp_pkey_ctx_st EVP_PKEY_CTX;
18 #else
19 typedef struct HASHContextStr HASHContext;
20 typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
16 typedef struct VFYContextStr VFYContext; 21 typedef struct VFYContextStr VFYContext;
17 #endif 22 #endif
18 23
19 namespace crypto { 24 namespace crypto {
20 25
21 // The SignatureVerifier class verifies a signature using a bare public key 26 // The SignatureVerifier class verifies a signature using a bare public key
22 // (as opposed to a certificate). 27 // (as opposed to a certificate).
23 class CRYPTO_EXPORT SignatureVerifier { 28 class CRYPTO_EXPORT SignatureVerifier {
24 public: 29 public:
30 // The set of supported hash functions. Extend as required.
31 enum HashAlgorithm {
32 SHA1,
33 SHA256,
34 };
35
25 SignatureVerifier(); 36 SignatureVerifier();
26 ~SignatureVerifier(); 37 ~SignatureVerifier();
27 38
28 // Streaming interface: 39 // Streaming interface:
29 40
30 // Initiates a signature verification operation. This should be followed 41 // Initiates a signature verification operation. This should be followed
31 // by one or more VerifyUpdate calls and a VerifyFinal call. 42 // by one or more VerifyUpdate calls and a VerifyFinal call.
43 // NOTE: for RSA-PSS signatures, use VerifyInitRSAPSS instead.
32 // 44 //
33 // The signature algorithm is specified as a DER encoded ASN.1 45 // The signature algorithm is specified as a DER encoded ASN.1
34 // AlgorithmIdentifier structure: 46 // AlgorithmIdentifier structure:
35 // AlgorithmIdentifier ::= SEQUENCE { 47 // AlgorithmIdentifier ::= SEQUENCE {
36 // algorithm OBJECT IDENTIFIER, 48 // algorithm OBJECT IDENTIFIER,
37 // parameters ANY DEFINED BY algorithm OPTIONAL } 49 // parameters ANY DEFINED BY algorithm OPTIONAL }
38 // 50 //
39 // The signature is encoded according to the signature algorithm, but it 51 // The signature is encoded according to the signature algorithm, but it
40 // must not be further encoded in an ASN.1 BIT STRING. 52 // must not be further encoded in an ASN.1 BIT STRING.
41 // Note: An RSA signatures is actually a big integer. It must be in the 53 // Note: An RSA signatures is actually a big integer. It must be in the
42 // big-endian byte order. 54 // big-endian byte order.
43 // 55 //
44 // The public key is specified as a DER encoded ASN.1 SubjectPublicKeyInfo 56 // The public key is specified as a DER encoded ASN.1 SubjectPublicKeyInfo
45 // structure, which contains not only the public key but also its type 57 // structure, which contains not only the public key but also its type
46 // (algorithm): 58 // (algorithm):
47 // SubjectPublicKeyInfo ::= SEQUENCE { 59 // SubjectPublicKeyInfo ::= SEQUENCE {
48 // algorithm AlgorithmIdentifier, 60 // algorithm AlgorithmIdentifier,
49 // subjectPublicKey BIT STRING } 61 // subjectPublicKey BIT STRING }
50 bool VerifyInit(const uint8* signature_algorithm, 62 bool VerifyInit(const uint8* signature_algorithm,
51 int signature_algorithm_len, 63 int signature_algorithm_len,
52 const uint8* signature, 64 const uint8* signature,
53 int signature_len, 65 int signature_len,
54 const uint8* public_key_info, 66 const uint8* public_key_info,
55 int public_key_info_len); 67 int public_key_info_len);
56 68
69 // Initiates a RSA-PSS signature verification operation. This should be
70 // followed by one or more VerifyUpdate calls and a VerifyFinal call.
71 //
72 // The RSA-PSS signature algorithm parameters are specified with the
73 // |hash_alg|, |mask_hash_alg|, and |salt_len| arguments.
74 //
75 // An RSA-PSS signature is encoded as a big integer in the big-endian byte
agl 2013/06/26 15:21:10 s/the //
wtc 2013/06/27 02:23:51 Done.
76 // order. It must not be further encoded in an ASN.1 BIT STRING.
77 //
78 // The public key is specified as a DER encoded ASN.1 SubjectPublicKeyInfo
79 // structure, which contains not only the public key but also its type
80 // (algorithm):
81 // SubjectPublicKeyInfo ::= SEQUENCE {
82 // algorithm AlgorithmIdentifier,
83 // subjectPublicKey BIT STRING }
84 bool VerifyInitRSAPSS(HashAlgorithm hash_alg,
85 HashAlgorithm mask_hash_alg,
86 int salt_len,
87 const uint8* signature,
88 int signature_len,
agl 2013/06/26 15:21:10 nit: size_t for lengths?
wtc 2013/06/27 02:23:51 I will do this in a separate cleanup CL because it
89 const uint8* public_key_info,
90 int public_key_info_len);
91
57 // Feeds a piece of the data to the signature verifier. 92 // Feeds a piece of the data to the signature verifier.
58 void VerifyUpdate(const uint8* data_part, int data_part_len); 93 void VerifyUpdate(const uint8* data_part, int data_part_len);
59 94
60 // Concludes a signature verification operation. Returns true if the 95 // Concludes a signature verification operation. Returns true if the
61 // signature is valid. Returns false if the signature is invalid or an 96 // signature is valid. Returns false if the signature is invalid or an
62 // error occurred. 97 // error occurred.
63 bool VerifyFinal(); 98 bool VerifyFinal();
64 99
65 // Note: we can provide a one-shot interface if there is interest: 100 // Note: we can provide a one-shot interface if there is interest:
66 // bool Verify(const uint8* data, 101 // bool Verify(const uint8* data,
67 // int data_len, 102 // int data_len,
68 // const uint8* signature_algorithm, 103 // const uint8* signature_algorithm,
69 // int signature_algorithm_len, 104 // int signature_algorithm_len,
70 // const uint8* signature, 105 // const uint8* signature,
71 // int signature_len, 106 // int signature_len,
72 // const uint8* public_key_info, 107 // const uint8* public_key_info,
73 // int public_key_info_len); 108 // int public_key_info_len);
74 109
75 private: 110 private:
111 #if defined(USE_OPENSSL)
112 bool CommonInit(const EVP_MD* digest,
113 const uint8* signature,
114 int signature_len,
115 const uint8* public_key_info,
116 int public_key_info_len,
117 EVP_PKEY_CTX** pkey_ctx);
118 #else
119 static SECKEYPublicKey* DecodePublicKeyInfo(const uint8* public_key_info,
120 int public_key_info_len);
121 #endif
122
76 void Reset(); 123 void Reset();
77 124
78 std::vector<uint8> signature_; 125 std::vector<uint8> signature_;
79 126
80 #if defined(USE_OPENSSL) 127 #if defined(USE_OPENSSL)
81 struct VerifyContext; 128 struct VerifyContext;
82 VerifyContext* verify_context_; 129 VerifyContext* verify_context_;
83 #else 130 #else
131 // Used for all signature types except RSA-PSS.
84 VFYContext* vfy_context_; 132 VFYContext* vfy_context_;
133
134 // Used for RSA-PSS signatures.
135 HashAlgorithm hash_alg_;
136 HashAlgorithm mask_hash_alg_;
137 unsigned int salt_len_;
138 SECKEYPublicKey* public_key_;
139 HASHContext* hash_context_;
85 #endif 140 #endif
86 }; 141 };
87 142
88 } // namespace crypto 143 } // namespace crypto
89 144
90 #endif // CRYPTO_SIGNATURE_VERIFIER_H_ 145 #endif // CRYPTO_SIGNATURE_VERIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698