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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_SIGNATURE_VERIFIER_H_
6 #define CRYPTO_SIGNATURE_VERIFIER_H_
9 #include "build/build_config.h"
13 #include "base/basictypes.h"
14 #include "crypto/crypto_export.h"
16 #if !defined(USE_OPENSSL)
17 typedef struct VFYContextStr VFYContext
;
22 // The SignatureVerifier class verifies a signature using a bare public key
23 // (as opposed to a certificate).
24 class CRYPTO_EXPORT SignatureVerifier
{
29 // Streaming interface:
31 // Initiates a signature verification operation. This should be followed
32 // by one or more VerifyUpdate calls and a VerifyFinal call.
34 // The signature algorithm is specified as a DER encoded ASN.1
35 // AlgorithmIdentifier structure:
36 // AlgorithmIdentifier ::= SEQUENCE {
37 // algorithm OBJECT IDENTIFIER,
38 // parameters ANY DEFINED BY algorithm OPTIONAL }
40 // The signature is encoded according to the signature algorithm, but it
41 // must not be further encoded in an ASN.1 BIT STRING.
42 // Note: An RSA signatures is actually a big integer. It must be in the
43 // big-endian byte order.
45 // The public key is specified as a DER encoded ASN.1 SubjectPublicKeyInfo
46 // structure, which contains not only the public key but also its type
48 // SubjectPublicKeyInfo ::= SEQUENCE {
49 // algorithm AlgorithmIdentifier,
50 // subjectPublicKey BIT STRING }
51 bool VerifyInit(const uint8
* signature_algorithm
,
52 int signature_algorithm_len
,
53 const uint8
* signature
,
55 const uint8
* public_key_info
,
56 int public_key_info_len
);
58 // Feeds a piece of the data to the signature verifier.
59 void VerifyUpdate(const uint8
* data_part
, int data_part_len
);
61 // Concludes a signature verification operation. Returns true if the
62 // signature is valid. Returns false if the signature is invalid or an
66 // Note: we can provide a one-shot interface if there is interest:
67 // bool Verify(const uint8* data,
69 // const uint8* signature_algorithm,
70 // int signature_algorithm_len,
71 // const uint8* signature,
73 // const uint8* public_key_info,
74 // int public_key_info_len);
79 std::vector
<uint8
> signature_
;
81 #if defined(USE_OPENSSL)
83 VerifyContext
* verify_context_
;
85 VFYContext
* vfy_context_
;
91 #endif // CRYPTO_SIGNATURE_VERIFIER_H_