OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009-2010 The Chromium OS 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. |
| 4 |
| 5 // Crypto - class for handling some OpenSSL crypto functions |
| 6 |
| 7 #ifndef TPM_INIT_CRYPTO_H_ |
| 8 #define TPM_INIT_CRYPTO_H_ |
| 9 |
| 10 #include <base/basictypes.h> |
| 11 #include <base/file_path.h> |
| 12 |
| 13 #include "secure_blob.h" |
| 14 |
| 15 namespace tpm_init { |
| 16 |
| 17 // Default entropy source is used to seed openssl's random number generator |
| 18 extern const std::string kDefaultEntropySource; |
| 19 |
| 20 class Crypto { |
| 21 public: |
| 22 |
| 23 // Default constructor, using the default entropy source |
| 24 Crypto(); |
| 25 |
| 26 virtual ~Crypto(); |
| 27 |
| 28 // Initializes Crypto |
| 29 bool Init(); |
| 30 |
| 31 // Seeds the random number generator |
| 32 void SeedRng() const; |
| 33 |
| 34 // Returns random bytes of the given length |
| 35 // |
| 36 // Parameters |
| 37 // rand (OUT) - Where to store the random bytes |
| 38 // length - The number of random bytes to store in rand |
| 39 void GetSecureRandom(unsigned char *rand, int length) const; |
| 40 |
| 41 // Creates a new RSA key |
| 42 // |
| 43 // Parameters |
| 44 // key_bits - The key size to generate |
| 45 // n (OUT) - the modulus |
| 46 // p (OUT) - the private key |
| 47 bool CreateRsaKey(int key_bits, SecureBlob* n, SecureBlob *p) const; |
| 48 |
| 49 // Gets the SHA1 hash of the data provided |
| 50 void GetSha1(const chromeos::Blob& data, int start, int count, |
| 51 SecureBlob* hash) const; |
| 52 |
| 53 void AsciiEncodeToBuffer(const chromeos::Blob& blob, char* buffer, |
| 54 int buffer_length); |
| 55 |
| 56 private: |
| 57 std::string entropy_source_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(Crypto); |
| 60 }; |
| 61 |
| 62 } // namespace tpm_init |
| 63 |
| 64 #endif // TPM_INIT_CRYPTO_H_ |
OLD | NEW |