2014-10-21 21:04:03 +02:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
2014-10-31 09:36:30 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-10-21 21:04:03 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_ECWRAPPER_H
|
|
|
|
#define BITCOIN_ECWRAPPER_H
|
2014-10-21 21:04:03 +02:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <openssl/ec.h>
|
|
|
|
|
|
|
|
class uint256;
|
|
|
|
|
2014-10-31 01:43:19 +01:00
|
|
|
/** RAII Wrapper around OpenSSL's EC_KEY */
|
2014-10-21 21:04:03 +02:00
|
|
|
class CECKey {
|
|
|
|
private:
|
|
|
|
EC_KEY *pkey;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CECKey();
|
|
|
|
~CECKey();
|
|
|
|
|
|
|
|
void GetPubKey(std::vector<unsigned char>& pubkey, bool fCompressed);
|
|
|
|
bool SetPubKey(const unsigned char* pubkey, size_t size);
|
|
|
|
bool Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig);
|
|
|
|
|
2014-10-31 01:43:19 +01:00
|
|
|
/**
|
|
|
|
* reconstruct public key from a compact signature
|
|
|
|
* This is only slightly more CPU intensive than just verifying it.
|
|
|
|
* If this function succeeds, the recovered public key is guaranteed to be valid
|
|
|
|
* (the signature is a valid signature of the given data for that key)
|
|
|
|
*/
|
2014-10-21 21:04:03 +02:00
|
|
|
bool Recover(const uint256 &hash, const unsigned char *p64, int rec);
|
|
|
|
|
|
|
|
bool TweakPublic(const unsigned char vchTweak[32]);
|
|
|
|
static bool SanityCheck();
|
|
|
|
};
|
|
|
|
|
2014-11-04 14:34:04 +01:00
|
|
|
#endif // BITCOIN_ECWRAPPER_H
|