1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_CRYPTO_SIGNATURE_VERIFIER_H_
6 #define BASE_CRYPTO_SIGNATURE_VERIFIER_H_
8 #include "build/build_config.h"
12 #elif defined(OS_MACOSX)
13 #include <Security/cssm.h>
21 #include "base/basictypes.h"
25 // The SignatureVerifier class verifies a signature using a bare public key
26 // (as opposed to a certificate).
27 class SignatureVerifier
{
32 // Streaming interface:
34 // Initiates a signature verification operation. This should be followed
35 // by one or more VerifyUpdate calls and a VerifyFinal call.
37 // The signature algorithm is specified as a DER encoded ASN.1
38 // AlgorithmIdentifier structure:
39 // AlgorithmIdentifier ::= SEQUENCE {
40 // algorithm OBJECT IDENTIFIER,
41 // parameters ANY DEFINED BY algorithm OPTIONAL }
43 // The signature is encoded according to the signature algorithm, but it
44 // must not be further encoded in an ASN.1 BIT STRING.
45 // Note: An RSA signatures is actually a big integer. It must be in the
46 // big-endian byte order.
48 // The public key is specified as a DER encoded ASN.1 SubjectPublicKeyInfo
49 // structure, which contains not only the public key but also its type
51 // SubjectPublicKeyInfo ::= SEQUENCE {
52 // algorithm AlgorithmIdentifier,
53 // subjectPublicKey BIT STRING }
54 bool VerifyInit(const uint8
* signature_algorithm
,
55 int signature_algorithm_len
,
56 const uint8
* signature
,
58 const uint8
* public_key_info
,
59 int public_key_info_len
);
61 // Feeds a piece of the data to the signature verifier.
62 void VerifyUpdate(const uint8
* data_part
, int data_part_len
);
64 // Concludes a signature verification operation. Returns true if the
65 // signature is valid. Returns false if the signature is invalid or an
69 // Note: we can provide a one-shot interface if there is interest:
70 // bool Verify(const uint8* data,
72 // const uint8* signature_algorithm,
73 // int signature_algorithm_len,
74 // const uint8* signature,
76 // const uint8* public_key_info,
77 // int public_key_info_len);
82 std::vector
<uint8
> signature_
;
85 VFYContext
* vfy_context_
;
86 #elif defined(OS_MACOSX)
87 std::vector
<uint8
> public_key_info_
;
89 CSSM_CSP_HANDLE csp_handle_
;
91 CSSM_CC_HANDLE sig_handle_
;
97 HCRYPTHASH hash_object_
;
99 HCRYPTKEY public_key_
;
105 #endif // BASE_CRYPTO_SIGNATURE_VERIFIER_H_