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_
8 #include "build/build_config.h"
12 #include "base/basictypes.h"
13 #include "crypto/crypto_export.h"
15 #if !defined(USE_OPENSSL)
16 typedef struct VFYContextStr VFYContext
;
21 // The SignatureVerifier class verifies a signature using a bare public key
22 // (as opposed to a certificate).
23 class CRYPTO_EXPORT SignatureVerifier
{
28 // Streaming interface:
30 // Initiates a signature verification operation. This should be followed
31 // by one or more VerifyUpdate calls and a VerifyFinal call.
33 // The signature algorithm is specified as a DER encoded ASN.1
34 // AlgorithmIdentifier structure:
35 // AlgorithmIdentifier ::= SEQUENCE {
36 // algorithm OBJECT IDENTIFIER,
37 // parameters ANY DEFINED BY algorithm OPTIONAL }
39 // The signature is encoded according to the signature algorithm, but it
40 // 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
42 // big-endian byte order.
44 // 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
47 // SubjectPublicKeyInfo ::= SEQUENCE {
48 // algorithm AlgorithmIdentifier,
49 // subjectPublicKey BIT STRING }
50 bool VerifyInit(const uint8
* signature_algorithm
,
51 int signature_algorithm_len
,
52 const uint8
* signature
,
54 const uint8
* public_key_info
,
55 int public_key_info_len
);
57 // Feeds a piece of the data to the signature verifier.
58 void VerifyUpdate(const uint8
* data_part
, int data_part_len
);
60 // Concludes a signature verification operation. Returns true if the
61 // signature is valid. Returns false if the signature is invalid or an
65 // Note: we can provide a one-shot interface if there is interest:
66 // bool Verify(const uint8* data,
68 // const uint8* signature_algorithm,
69 // int signature_algorithm_len,
70 // const uint8* signature,
72 // const uint8* public_key_info,
73 // int public_key_info_len);
78 std::vector
<uint8
> signature_
;
80 #if defined(USE_OPENSSL)
82 VerifyContext
* verify_context_
;
84 VFYContext
* vfy_context_
;
90 #endif // CRYPTO_SIGNATURE_VERIFIER_H_