blob: 63512b83b5a048f50826e69a131a1ae3f3948842 [file] [log] [blame]
[email protected]5ee44d42012-02-08 00:14:541// Copyright (c) 2012 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]28ae8fe2009-06-05 18:25:0625
[email protected]692033a2010-04-09 18:40:5026#if defined(OS_WIN)
[email protected]4b559b4d2011-04-14 17:37:1427#include "crypto/scoped_capi_types.h"
[email protected]692033a2010-04-09 18:40:5028#endif
29
[email protected]4b559b4d2011-04-14 17:37:1430namespace crypto {
[email protected]28ae8fe2009-06-05 18:25:0631
[email protected]5ee44d42012-02-08 00:14:5432class RSAPrivateKey;
33
[email protected]28ae8fe2009-06-05 18:25:0634// Signs data using a bare private key (as opposed to a full certificate).
35// Currently can only sign data using SHA-1 with RSA encryption.
[email protected]d613a9902011-08-05 20:59:1136class CRYPTO_EXPORT SignatureCreator {
[email protected]28ae8fe2009-06-05 18:25:0637 public:
[email protected]a502bbe72011-01-07 18:06:4538 ~SignatureCreator();
39
[email protected]28ae8fe2009-06-05 18:25:0640 // Create an instance. The caller must ensure that the provided PrivateKey
41 // instance outlives the created SignatureCreator.
42 static SignatureCreator* Create(RSAPrivateKey* key);
43
[email protected]28ae8fe2009-06-05 18:25:0644 // Update the signature with more data.
45 bool Update(const uint8* data_part, int data_part_len);
46
47 // Finalize the signature.
48 bool Final(std::vector<uint8>* signature);
49
50 private:
51 // Private constructor. Use the Create() method instead.
[email protected]71a9f842009-09-24 01:21:1252 SignatureCreator();
[email protected]28ae8fe2009-06-05 18:25:0653
54 RSAPrivateKey* key_;
55
[email protected]be796bb2010-11-18 15:43:4356#if defined(USE_OPENSSL)
57 EVP_MD_CTX* sign_context_;
58#elif defined(USE_NSS)
[email protected]13555c122009-10-08 01:18:0259 SGNContextStr* sign_context_;
[email protected]71a9f842009-09-24 01:21:1260#elif defined(OS_MACOSX)
[email protected]e90ed8a2009-10-06 18:55:3561 CSSM_CC_HANDLE sig_handle_;
[email protected]71a9f842009-09-24 01:21:1262#elif defined(OS_WIN)
[email protected]692033a2010-04-09 18:40:5063 ScopedHCRYPTHASH hash_object_;
[email protected]28ae8fe2009-06-05 18:25:0664#endif
65
66 DISALLOW_COPY_AND_ASSIGN(SignatureCreator);
67};
68
[email protected]4b559b4d2011-04-14 17:37:1469} // namespace crypto
[email protected]28ae8fe2009-06-05 18:25:0670
[email protected]4b559b4d2011-04-14 17:37:1471#endif // CRYPTO_SIGNATURE_CREATOR_H_