~ubuntu-branches/ubuntu/utopic/bitcoin/utopic

« back to all changes in this revision

Viewing changes to src/key.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, Jonas Smedegaard, Jan Dittberner
  • Date: 2011-07-19 15:08:54 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110719150854-mhd8cclbbfrkhi1u
Tags: 0.3.24~dfsg-1
* New upstream release.

[ Jonas Smedegaard ]
* Improve various usage hints:
  + Explicitly mention in long description that bitcoind contains
    daemon and command-line interface.
  + Extend README.Debian with section on lack of GUI, and add primary
    headline.
  + Avoid installing upstream README: contains no parts relevant for
    Debian usage.
  Thanks to richard for suggestions (see bug#629443).
* Favor final releases over prereleases in rules and watch file.
  Thanks to Jan Dittberner.
* Track -src (not -linux) tarballs in rules and watch file.
  Thanks to Jan Dittberner.
* Drop patches 1004 and 1005 (integrated upstream) and simplify
  CXXFLAGS in rules file.
* Stop stripping no longer included source-less binaries from upstream
  tarballs.

[ Jan Dittberner ]
* refresh debian/patches/1000_use_system_crypto++.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
2
// Distributed under the MIT/X11 software license, see the accompanying
3
3
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
 
4
#ifndef BITCOIN_KEY_H
 
5
#define BITCOIN_KEY_H
4
6
 
 
7
#include <openssl/ec.h>
 
8
#include <openssl/ecdsa.h>
 
9
#include <openssl/obj_mac.h>
5
10
 
6
11
// secp160k1
7
12
// const unsigned int PRIVATE_KEY_SIZE = 192;
36
41
 
37
42
 
38
43
// secure_allocator is defined in serialize.h
39
 
typedef vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
 
44
typedef std::vector<unsigned char, secure_allocator<unsigned char> > CPrivKey;
40
45
 
41
46
 
42
47
 
109
114
        return vchPrivKey;
110
115
    }
111
116
 
112
 
    bool SetPubKey(const vector<unsigned char>& vchPubKey)
 
117
    bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
113
118
    {
114
119
        const unsigned char* pbegin = &vchPubKey[0];
115
120
        if (!o2i_ECPublicKey(&pkey, &pbegin, vchPubKey.size()))
118
123
        return true;
119
124
    }
120
125
 
121
 
    vector<unsigned char> GetPubKey() const
 
126
    std::vector<unsigned char> GetPubKey() const
122
127
    {
123
128
        unsigned int nSize = i2o_ECPublicKey(pkey, NULL);
124
129
        if (!nSize)
125
130
            throw key_error("CKey::GetPubKey() : i2o_ECPublicKey failed");
126
 
        vector<unsigned char> vchPubKey(nSize, 0);
 
131
        std::vector<unsigned char> vchPubKey(nSize, 0);
127
132
        unsigned char* pbegin = &vchPubKey[0];
128
133
        if (i2o_ECPublicKey(pkey, &pbegin) != nSize)
129
134
            throw key_error("CKey::GetPubKey() : i2o_ECPublicKey returned unexpected size");
130
135
        return vchPubKey;
131
136
    }
132
137
 
133
 
    bool Sign(uint256 hash, vector<unsigned char>& vchSig)
 
138
    bool Sign(uint256 hash, std::vector<unsigned char>& vchSig)
134
139
    {
135
140
        vchSig.clear();
136
141
        unsigned char pchSig[10000];
142
147
        return true;
143
148
    }
144
149
 
145
 
    bool Verify(uint256 hash, const vector<unsigned char>& vchSig)
 
150
    bool Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
146
151
    {
147
152
        // -1 = error, 0 = bad sig, 1 = good
148
153
        if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
150
155
        return true;
151
156
    }
152
157
 
153
 
    static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, vector<unsigned char>& vchSig)
 
158
    static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, std::vector<unsigned char>& vchSig)
154
159
    {
155
160
        CKey key;
156
161
        if (!key.SetPrivKey(vchPrivKey))
158
163
        return key.Sign(hash, vchSig);
159
164
    }
160
165
 
161
 
    static bool Verify(const vector<unsigned char>& vchPubKey, uint256 hash, const vector<unsigned char>& vchSig)
 
166
    static bool Verify(const std::vector<unsigned char>& vchPubKey, uint256 hash, const std::vector<unsigned char>& vchSig)
162
167
    {
163
168
        CKey key;
164
169
        if (!key.SetPubKey(vchPubKey))
166
171
        return key.Verify(hash, vchSig);
167
172
    }
168
173
};
 
174
 
 
175
#endif