blob: eccfcce2d183c40cd71bcf370002078a0c11d2a8 [file] [log] [blame]
[email protected]a502bbe72011-01-07 18:06:451// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]28ae8fe2009-06-05 18:25:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4b559b4d2011-04-14 17:37:145#ifndef CRYPTO_SIGNATURE_CREATOR_H_
6#define CRYPTO_SIGNATURE_CREATOR_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]28ae8fe2009-06-05 18:25:068
[email protected]71a9f842009-09-24 01:21:129#include "build/build_config.h"
10
[email protected]be796bb2010-11-18 15:43:4311#if defined(USE_OPENSSL)
12// Forward declaration for openssl/*.h
13typedef struct env_md_ctx_st EVP_MD_CTX;
14#elif defined(USE_NSS)
[email protected]13555c122009-10-08 01:18:0215// Forward declaration.
16struct SGNContextStr;
[email protected]71a9f842009-09-24 01:21:1217#elif defined(OS_MACOSX)
[email protected]e90ed8a2009-10-06 18:55:3518#include <Security/cssm.h>
[email protected]28ae8fe2009-06-05 18:25:0619#endif
20
21#include <vector>
22
23#include "base/basictypes.h"
[email protected]d613a9902011-08-05 20:59:1124#include "crypto/crypto_export.h"
[email protected]4b559b4d2011-04-14 17:37:1425#include "crypto/rsa_private_key.h"
[email protected]28ae8fe2009-06-05 18:25:0626
[email protected]692033a2010-04-09 18:40:5027#if defined(OS_WIN)
[email protected]4b559b4d2011-04-14 17:37:1428#include "crypto/scoped_capi_types.h"
[email protected]692033a2010-04-09 18:40:5029#endif
30
[email protected]4b559b4d2011-04-14 17:37:1431namespace crypto {
[email protected]28ae8fe2009-06-05 18:25:0632
33// Signs data using a bare private key (as opposed to a full certificate).
34// Currently can only sign data using SHA-1 with RSA encryption.
[email protected]d613a9902011-08-05 20:59:1135class CRYPTO_EXPORT SignatureCreator {
[email protected]28ae8fe2009-06-05 18:25:0636 public:
[email protected]a502bbe72011-01-07 18:06:4537 ~SignatureCreator();
38
[email protected]28ae8fe2009-06-05 18:25:0639 // Create an instance. The caller must ensure that the provided PrivateKey
40 // instance outlives the created SignatureCreator.
41 static SignatureCreator* Create(RSAPrivateKey* key);
42
[email protected]28ae8fe2009-06-05 18:25:0643 // Update the signature with more data.
44 bool Update(const uint8* data_part, int data_part_len);
45
46 // Finalize the signature.
47 bool Final(std::vector<uint8>* signature);
48
49 private:
50 // Private constructor. Use the Create() method instead.
[email protected]71a9f842009-09-24 01:21:1251 SignatureCreator();
[email protected]28ae8fe2009-06-05 18:25:0652
53 RSAPrivateKey* key_;
54
[email protected]be796bb2010-11-18 15:43:4355#if defined(USE_OPENSSL)
56 EVP_MD_CTX* sign_context_;
57#elif defined(USE_NSS)
[email protected]13555c122009-10-08 01:18:0258 SGNContextStr* sign_context_;
[email protected]71a9f842009-09-24 01:21:1259#elif defined(OS_MACOSX)
[email protected]e90ed8a2009-10-06 18:55:3560 CSSM_CC_HANDLE sig_handle_;
[email protected]71a9f842009-09-24 01:21:1261#elif defined(OS_WIN)
[email protected]692033a2010-04-09 18:40:5062 ScopedHCRYPTHASH hash_object_;
[email protected]28ae8fe2009-06-05 18:25:0663#endif
64
65 DISALLOW_COPY_AND_ASSIGN(SignatureCreator);
66};
67
[email protected]4b559b4d2011-04-14 17:37:1468} // namespace crypto
[email protected]28ae8fe2009-06-05 18:25:0669
[email protected]4b559b4d2011-04-14 17:37:1470#endif // CRYPTO_SIGNATURE_CREATOR_H_