Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: crypto/ec_private_key.h

Issue 1539353003: Switch to standard integer types in crypto/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « crypto/curve25519_unittest.cc ('k') | crypto/ec_private_key_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CRYPTO_EC_PRIVATE_KEY_H_ 5 #ifndef CRYPTO_EC_PRIVATE_KEY_H_
6 #define CRYPTO_EC_PRIVATE_KEY_H_ 6 #define CRYPTO_EC_PRIVATE_KEY_H_
7 7
8 #include <stddef.h>
9 #include <stdint.h>
10
8 #include <string> 11 #include <string>
9 #include <vector> 12 #include <vector>
10 13
11 #include "base/basictypes.h" 14 #include "base/macros.h"
12 #include "build/build_config.h" 15 #include "build/build_config.h"
13 #include "crypto/crypto_export.h" 16 #include "crypto/crypto_export.h"
14 17
15 #if defined(USE_OPENSSL) 18 #if defined(USE_OPENSSL)
16 // Forward declaration for openssl/*.h 19 // Forward declaration for openssl/*.h
17 typedef struct evp_pkey_st EVP_PKEY; 20 typedef struct evp_pkey_st EVP_PKEY;
18 #else 21 #else
19 // Forward declaration. 22 // Forward declaration.
20 typedef struct CERTSubjectPublicKeyInfoStr CERTSubjectPublicKeyInfo; 23 typedef struct CERTSubjectPublicKeyInfoStr CERTSubjectPublicKeyInfo;
21 typedef struct PK11SlotInfoStr PK11SlotInfo; 24 typedef struct PK11SlotInfoStr PK11SlotInfo;
(...skipping 16 matching lines...) Expand all
38 // The created key will use the NIST P-256 curve. 41 // The created key will use the NIST P-256 curve.
39 // TODO(mattm): Add a curve parameter. 42 // TODO(mattm): Add a curve parameter.
40 static ECPrivateKey* Create(); 43 static ECPrivateKey* Create();
41 44
42 // Creates a new instance by importing an existing key pair. 45 // Creates a new instance by importing an existing key pair.
43 // The key pair is given as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo 46 // The key pair is given as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo
44 // block and an X.509 SubjectPublicKeyInfo block. 47 // block and an X.509 SubjectPublicKeyInfo block.
45 // Returns NULL if initialization fails. 48 // Returns NULL if initialization fails.
46 static ECPrivateKey* CreateFromEncryptedPrivateKeyInfo( 49 static ECPrivateKey* CreateFromEncryptedPrivateKeyInfo(
47 const std::string& password, 50 const std::string& password,
48 const std::vector<uint8>& encrypted_private_key_info, 51 const std::vector<uint8_t>& encrypted_private_key_info,
49 const std::vector<uint8>& subject_public_key_info); 52 const std::vector<uint8_t>& subject_public_key_info);
50 53
51 #if !defined(USE_OPENSSL) 54 #if !defined(USE_OPENSSL)
52 // Imports the key pair into |slot| and returns in |public_key| and |key|. 55 // Imports the key pair into |slot| and returns in |public_key| and |key|.
53 // Shortcut for code that needs to keep a reference directly to NSS types 56 // Shortcut for code that needs to keep a reference directly to NSS types
54 // without having to create a ECPrivateKey object and make a copy of them. 57 // without having to create a ECPrivateKey object and make a copy of them.
55 // TODO(mattm): move this function to some NSS util file. 58 // TODO(mattm): move this function to some NSS util file.
56 static bool ImportFromEncryptedPrivateKeyInfo( 59 static bool ImportFromEncryptedPrivateKeyInfo(
57 PK11SlotInfo* slot, 60 PK11SlotInfo* slot,
58 const std::string& password, 61 const std::string& password,
59 const uint8* encrypted_private_key_info, 62 const uint8_t* encrypted_private_key_info,
60 size_t encrypted_private_key_info_len, 63 size_t encrypted_private_key_info_len,
61 CERTSubjectPublicKeyInfo* decoded_spki, 64 CERTSubjectPublicKeyInfo* decoded_spki,
62 bool permanent, 65 bool permanent,
63 bool sensitive, 66 bool sensitive,
64 SECKEYPrivateKey** key, 67 SECKEYPrivateKey** key,
65 SECKEYPublicKey** public_key); 68 SECKEYPublicKey** public_key);
66 #endif 69 #endif
67 70
68 // Returns a copy of the object. 71 // Returns a copy of the object.
69 ECPrivateKey* Copy() const; 72 ECPrivateKey* Copy() const;
70 73
71 #if defined(USE_OPENSSL) 74 #if defined(USE_OPENSSL)
72 EVP_PKEY* key() { return key_; } 75 EVP_PKEY* key() { return key_; }
73 #else 76 #else
74 SECKEYPrivateKey* key() { return key_; } 77 SECKEYPrivateKey* key() { return key_; }
75 SECKEYPublicKey* public_key() { return public_key_; } 78 SECKEYPublicKey* public_key() { return public_key_; }
76 #endif 79 #endif
77 80
78 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo 81 // Exports the private key as an ASN.1-encoded PKCS #8 EncryptedPrivateKeyInfo
79 // block and the public key as an X.509 SubjectPublicKeyInfo block. 82 // block and the public key as an X.509 SubjectPublicKeyInfo block.
80 // The |password| and |iterations| are used as inputs to the key derivation 83 // The |password| and |iterations| are used as inputs to the key derivation
81 // function for generating the encryption key. PKCS #5 recommends a minimum 84 // function for generating the encryption key. PKCS #5 recommends a minimum
82 // of 1000 iterations, on modern systems a larger value may be preferrable. 85 // of 1000 iterations, on modern systems a larger value may be preferrable.
83 bool ExportEncryptedPrivateKey(const std::string& password, 86 bool ExportEncryptedPrivateKey(const std::string& password,
84 int iterations, 87 int iterations,
85 std::vector<uint8>* output); 88 std::vector<uint8_t>* output);
86 89
87 // Exports the public key to an X.509 SubjectPublicKeyInfo block. 90 // Exports the public key to an X.509 SubjectPublicKeyInfo block.
88 bool ExportPublicKey(std::vector<uint8>* output); 91 bool ExportPublicKey(std::vector<uint8_t>* output);
89 92
90 // Exports the public key as an EC point in the uncompressed point format. 93 // Exports the public key as an EC point in the uncompressed point format.
91 bool ExportRawPublicKey(std::string* output); 94 bool ExportRawPublicKey(std::string* output);
92 95
93 // Exports private key data for testing. The format of data stored into output 96 // Exports private key data for testing. The format of data stored into output
94 // doesn't matter other than that it is consistent for the same key. 97 // doesn't matter other than that it is consistent for the same key.
95 bool ExportValue(std::vector<uint8>* output); 98 bool ExportValue(std::vector<uint8_t>* output);
96 bool ExportECParams(std::vector<uint8>* output); 99 bool ExportECParams(std::vector<uint8_t>* output);
97 100
98 private: 101 private:
99 // Constructor is private. Use one of the Create*() methods above instead. 102 // Constructor is private. Use one of the Create*() methods above instead.
100 ECPrivateKey(); 103 ECPrivateKey();
101 104
102 #if defined(USE_OPENSSL) 105 #if defined(USE_OPENSSL)
103 EVP_PKEY* key_; 106 EVP_PKEY* key_;
104 #else 107 #else
105 SECKEYPrivateKey* key_; 108 SECKEYPrivateKey* key_;
106 SECKEYPublicKey* public_key_; 109 SECKEYPublicKey* public_key_;
107 #endif 110 #endif
108 111
109 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey); 112 DISALLOW_COPY_AND_ASSIGN(ECPrivateKey);
110 }; 113 };
111 114
112 115
113 } // namespace crypto 116 } // namespace crypto
114 117
115 #endif // CRYPTO_EC_PRIVATE_KEY_H_ 118 #endif // CRYPTO_EC_PRIVATE_KEY_H_
OLDNEW
« no previous file with comments | « crypto/curve25519_unittest.cc ('k') | crypto/ec_private_key_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698