Skip to content

Commit ffd8edd

Browse files
committed
Update comments in key to be doxygen compatible
1 parent 068b7f8 commit ffd8edd

File tree

2 files changed

+82
-65
lines changed

2 files changed

+82
-65
lines changed

src/key.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2009-2014 The Bitcoin developers
2-
// Distributed under the MIT/X11 software license, see the accompanying
2+
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "key.h"
@@ -13,7 +13,7 @@
1313
#include "ecwrapper.h"
1414
#endif
1515

16-
// anonymous namespace
16+
//! anonymous namespace with local implementation code (OpenSSL interaction)
1717
namespace {
1818

1919
#ifdef USE_SECP256K1
@@ -56,15 +56,15 @@ int CompareBigEndian(const unsigned char *c1, size_t c1len, const unsigned char
5656
return 0;
5757
}
5858

59-
// Order of secp256k1's generator minus 1.
59+
/** Order of secp256k1's generator minus 1. */
6060
const unsigned char vchMaxModOrder[32] = {
6161
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
6262
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
6363
0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,
6464
0xBF,0xD2,0x5E,0x8C,0xD0,0x36,0x41,0x40
6565
};
6666

67-
// Half of the order of secp256k1's generator minus 1.
67+
/** Half of the order of secp256k1's generator minus 1. */
6868
const unsigned char vchMaxModHalfOrder[32] = {
6969
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
7070
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

src/key.h

Lines changed: 78 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2013 The Bitcoin developers
3-
// Distributed under the MIT/X11 software license, see the accompanying
2+
// Copyright (c) 2009-2014 The Bitcoin developers
3+
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#ifndef BITCOIN_KEY_H
@@ -14,13 +14,15 @@
1414
#include <stdexcept>
1515
#include <vector>
1616

17-
// secp256k1:
18-
// const unsigned int PRIVATE_KEY_SIZE = 279;
19-
// const unsigned int PUBLIC_KEY_SIZE = 65;
20-
// const unsigned int SIGNATURE_SIZE = 72;
21-
//
22-
// see www.keylength.com
23-
// script supports up to 75 for single byte push
17+
/**
18+
* secp256k1:
19+
* const unsigned int PRIVATE_KEY_SIZE = 279;
20+
* const unsigned int PUBLIC_KEY_SIZE = 65;
21+
* const unsigned int SIGNATURE_SIZE = 72;
22+
*
23+
* see www.keylength.com
24+
* script supports up to 75 for single byte push
25+
*/
2426

2527
/** A reference to a CKey: the Hash160 of its serialized public key */
2628
class CKeyID : public uint160
@@ -34,11 +36,14 @@ class CKeyID : public uint160
3436
class CPubKey
3537
{
3638
private:
37-
// Just store the serialized data.
38-
// Its length can very cheaply be computed from the first byte.
39+
40+
/**
41+
* Just store the serialized data.
42+
* Its length can very cheaply be computed from the first byte.
43+
*/
3944
unsigned char vch[65];
4045

41-
// Compute the length of a pubkey with a given first byte.
46+
//! Compute the length of a pubkey with a given first byte.
4247
unsigned int static GetLen(unsigned char chHeader)
4348
{
4449
if (chHeader == 2 || chHeader == 3)
@@ -48,20 +53,20 @@ class CPubKey
4853
return 0;
4954
}
5055

51-
// Set this key data to be invalid
56+
//! Set this key data to be invalid
5257
void Invalidate()
5358
{
5459
vch[0] = 0xFF;
5560
}
5661

5762
public:
58-
// Construct an invalid public key.
63+
//! Construct an invalid public key.
5964
CPubKey()
6065
{
6166
Invalidate();
6267
}
6368

64-
// Initialize a public key using begin/end iterators to byte data.
69+
//! Initialize a public key using begin/end iterators to byte data.
6570
template <typename T>
6671
void Set(const T pbegin, const T pend)
6772
{
@@ -72,26 +77,26 @@ class CPubKey
7277
Invalidate();
7378
}
7479

75-
// Construct a public key using begin/end iterators to byte data.
80+
//! Construct a public key using begin/end iterators to byte data.
7681
template <typename T>
7782
CPubKey(const T pbegin, const T pend)
7883
{
7984
Set(pbegin, pend);
8085
}
8186

82-
// Construct a public key from a byte vector.
87+
//! Construct a public key from a byte vector.
8388
CPubKey(const std::vector<unsigned char>& vch)
8489
{
8590
Set(vch.begin(), vch.end());
8691
}
8792

88-
// Simple read-only vector-like interface to the pubkey data.
93+
//! Simple read-only vector-like interface to the pubkey data.
8994
unsigned int size() const { return GetLen(vch[0]); }
9095
const unsigned char* begin() const { return vch; }
9196
const unsigned char* end() const { return vch + size(); }
9297
const unsigned char& operator[](unsigned int pos) const { return vch[pos]; }
9398

94-
// Comparator implementation.
99+
//! Comparator implementation.
95100
friend bool operator==(const CPubKey& a, const CPubKey& b)
96101
{
97102
return a.vch[0] == b.vch[0] &&
@@ -107,7 +112,7 @@ class CPubKey
107112
(a.vch[0] == b.vch[0] && memcmp(a.vch, b.vch, a.size()) < 0);
108113
}
109114

110-
// Implement serialization, as if this was a byte vector.
115+
//! Implement serialization, as if this was a byte vector.
111116
unsigned int GetSerializeSize(int nType, int nVersion) const
112117
{
113118
return size() + 1;
@@ -134,86 +139,92 @@ class CPubKey
134139
}
135140
}
136141

137-
// Get the KeyID of this public key (hash of its serialization)
142+
//! Get the KeyID of this public key (hash of its serialization)
138143
CKeyID GetID() const
139144
{
140145
return CKeyID(Hash160(vch, vch + size()));
141146
}
142147

143-
// Get the 256-bit hash of this public key.
148+
//! Get the 256-bit hash of this public key.
144149
uint256 GetHash() const
145150
{
146151
return Hash(vch, vch + size());
147152
}
148153

149-
// Check syntactic correctness.
150-
//
151-
// Note that this is consensus critical as CheckSig() calls it!
154+
/*
155+
* Check syntactic correctness.
156+
*
157+
* Note that this is consensus critical as CheckSig() calls it!
158+
*/
152159
bool IsValid() const
153160
{
154161
return size() > 0;
155162
}
156163

157-
// fully validate whether this is a valid public key (more expensive than IsValid())
164+
//! fully validate whether this is a valid public key (more expensive than IsValid())
158165
bool IsFullyValid() const;
159166

160-
// Check whether this is a compressed public key.
167+
//! Check whether this is a compressed public key.
161168
bool IsCompressed() const
162169
{
163170
return size() == 33;
164171
}
165172

166-
// Verify a DER signature (~72 bytes).
167-
// If this public key is not fully valid, the return value will be false.
173+
/**
174+
* Verify a DER signature (~72 bytes).
175+
* If this public key is not fully valid, the return value will be false.
176+
*/
168177
bool Verify(const uint256& hash, const std::vector<unsigned char>& vchSig) const;
169178

170-
// Recover a public key from a compact signature.
179+
//! Recover a public key from a compact signature.
171180
bool RecoverCompact(const uint256& hash, const std::vector<unsigned char>& vchSig);
172181

173-
// Turn this public key into an uncompressed public key.
182+
//! Turn this public key into an uncompressed public key.
174183
bool Decompress();
175184

176-
// Derive BIP32 child pubkey.
185+
//! Derive BIP32 child pubkey.
177186
bool Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const;
178187
};
179188

180189

181-
// secure_allocator is defined in allocators.h
182-
// CPrivKey is a serialized private key, with all parameters included (279 bytes)
190+
/**
191+
* secure_allocator is defined in allocators.h
192+
* CPrivKey is a serialized private key, with all parameters included (279 bytes)
193+
*/
183194
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
184195

185196
/** An encapsulated private key. */
186197
class CKey
187198
{
188199
private:
189-
// Whether this private key is valid. We check for correctness when modifying the key
190-
// data, so fValid should always correspond to the actual state.
200+
//! Whether this private key is valid. We check for correctness when modifying the key
201+
//! data, so fValid should always correspond to the actual state.
191202
bool fValid;
192203

193-
// Whether the public key corresponding to this private key is (to be) compressed.
204+
//! Whether the public key corresponding to this private key is (to be) compressed.
194205
bool fCompressed;
195206

196-
// The actual byte data
207+
//! The actual byte data
197208
unsigned char vch[32];
198209

199-
// Check whether the 32-byte array pointed to be vch is valid keydata.
210+
//! Check whether the 32-byte array pointed to be vch is valid keydata.
200211
bool static Check(const unsigned char* vch);
201212

202213
public:
203-
// Construct an invalid private key.
214+
//! Construct an invalid private key.
204215
CKey() : fValid(false), fCompressed(false)
205216
{
206217
LockObject(vch);
207218
}
208219

209-
// Copy constructor. This is necessary because of memlocking.
220+
//! Copy constructor. This is necessary because of memlocking.
210221
CKey(const CKey& secret) : fValid(secret.fValid), fCompressed(secret.fCompressed)
211222
{
212223
LockObject(vch);
213224
memcpy(vch, secret.vch, sizeof(vch));
214225
}
215226

216-
// Destructor (again necessary because of memlocking).
227+
//! Destructor (again necessary because of memlocking).
217228
~CKey()
218229
{
219230
UnlockObject(vch);
@@ -225,7 +236,7 @@ class CKey
225236
memcmp(&a.vch[0], &b.vch[0], a.size()) == 0;
226237
}
227238

228-
// Initialize using begin and end iterators to byte data.
239+
//! Initialize using begin and end iterators to byte data.
229240
template <typename T>
230241
void Set(const T pbegin, const T pend, bool fCompressedIn)
231242
{
@@ -242,48 +253,54 @@ class CKey
242253
}
243254
}
244255

245-
// Simple read-only vector-like interface.
256+
//! Simple read-only vector-like interface.
246257
unsigned int size() const { return (fValid ? 32 : 0); }
247258
const unsigned char* begin() const { return vch; }
248259
const unsigned char* end() const { return vch + size(); }
249260

250-
// Check whether this private key is valid.
261+
//! Check whether this private key is valid.
251262
bool IsValid() const { return fValid; }
252263

253-
// Check whether the public key corresponding to this private key is (to be) compressed.
264+
//! Check whether the public key corresponding to this private key is (to be) compressed.
254265
bool IsCompressed() const { return fCompressed; }
255266

256-
// Initialize from a CPrivKey (serialized OpenSSL private key data).
267+
//! Initialize from a CPrivKey (serialized OpenSSL private key data).
257268
bool SetPrivKey(const CPrivKey& vchPrivKey, bool fCompressed);
258269

259-
// Generate a new private key using a cryptographic PRNG.
270+
//! Generate a new private key using a cryptographic PRNG.
260271
void MakeNewKey(bool fCompressed);
261272

262-
// Convert the private key to a CPrivKey (serialized OpenSSL private key data).
263-
// This is expensive.
273+
/**
274+
* Convert the private key to a CPrivKey (serialized OpenSSL private key data).
275+
* This is expensive.
276+
*/
264277
CPrivKey GetPrivKey() const;
265278

266-
// Compute the public key from a private key.
267-
// This is expensive.
279+
/**
280+
* Compute the public key from a private key.
281+
* This is expensive.
282+
*/
268283
CPubKey GetPubKey() const;
269284

270-
// Create a DER-serialized signature.
285+
//! Create a DER-serialized signature.
271286
bool Sign(const uint256& hash, std::vector<unsigned char>& vchSig, bool lowS = true) const;
272287

273-
// Create a compact signature (65 bytes), which allows reconstructing the used public key.
274-
// The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
275-
// The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
276-
// 0x1D = second key with even y, 0x1E = second key with odd y,
277-
// add 0x04 for compressed keys.
288+
/**
289+
* Create a compact signature (65 bytes), which allows reconstructing the used public key.
290+
* The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
291+
* The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
292+
* 0x1D = second key with even y, 0x1E = second key with odd y,
293+
* add 0x04 for compressed keys.
294+
*/
278295
bool SignCompact(const uint256& hash, std::vector<unsigned char>& vchSig) const;
279296

280-
// Derive BIP32 child key.
297+
//! Derive BIP32 child key.
281298
bool Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const;
282299

283-
// Load private key and check that public key matches.
300+
//! Load private key and check that public key matches.
284301
bool Load(CPrivKey& privkey, CPubKey& vchPubKey, bool fSkipCheck);
285302

286-
// Check whether an element of a signature (r or s) is valid.
303+
//! Check whether an element of a signature (r or s) is valid.
287304
static bool CheckSignatureElement(const unsigned char* vch, int len, bool half);
288305
};
289306

0 commit comments

Comments
 (0)