mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Remove the use of ec_key parameters and return values from ECDSA crypto
prototypes. Don't store key data into an ec_key variable only to fetch
it back into the original type again. Use uint256 and Blob explicitly.
Pass private keys as uint256, and pass public keys as either pointer and
length or Blob in calls to ECDSA{Sign,Verify}() and {en,de}cryptECIES().
Replace GenerateRootDeterministicKey() with separate functions returning
either the public or private key, since no caller needs both at once.
Simplify the use of GenerateDeterministicKey within RippleAddress. Call
a single routine rather than pass the result of one as input to another.
Add openssl unit with RAII classes for bignum, bn_ctx, and ec_point plus
free utility functions.
Rewrite the functions in GenerateDeterministicKey.cpp to use RAII rather
than explicit cleanup code:
* factor out secp256k1_group and secp256k1_order for reuse rather than
computing them each time
* replace getPublicKey() with serialize_ec_point(), which makes, sets,
and destroys an ec_key internally (sparing the caller those details)
and calls i2o_ECPublicKey() directly
* return bignum rather than ec_key from GenerateRootDeterministicKey()
* return ec_point rather than EC_KEY* from GenerateRootPubKey()
Move ECDSA{Private,Public}Key() to a new ECDSAKey unit.
Move ec_key.h into impl/ since it's no longer used outside crypto/.
Remove now-unused member functions from ec_key.
Change tabs to spaces; trim trailing whitespace (including blank lines).
164 lines
4.3 KiB
C++
164 lines
4.3 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#ifndef RIPPLE_PROTOCOL_STTX_H_INCLUDED
|
|
#define RIPPLE_PROTOCOL_STTX_H_INCLUDED
|
|
|
|
#include <ripple/protocol/STObject.h>
|
|
#include <ripple/protocol/TxFormats.h>
|
|
#include <boost/logic/tribool.hpp>
|
|
|
|
namespace ripple {
|
|
|
|
// VFALCO TODO replace these macros with language constants
|
|
#define TXN_SQL_NEW 'N'
|
|
#define TXN_SQL_CONFLICT 'C'
|
|
#define TXN_SQL_HELD 'H'
|
|
#define TXN_SQL_VALIDATED 'V'
|
|
#define TXN_SQL_INCLUDED 'I'
|
|
#define TXN_SQL_UNKNOWN 'U'
|
|
|
|
class STTx final
|
|
: public STObject
|
|
, public CountedObject <STTx>
|
|
{
|
|
public:
|
|
static char const* getCountedObjectName () { return "STTx"; }
|
|
|
|
typedef std::shared_ptr<STTx> pointer;
|
|
typedef const std::shared_ptr<STTx>& ref;
|
|
|
|
public:
|
|
STTx () = delete;
|
|
STTx& operator= (STTx const& other) = delete;
|
|
|
|
STTx (STTx const& other) = default;
|
|
|
|
explicit STTx (SerialIter& sit);
|
|
explicit STTx (TxType type);
|
|
|
|
// Only called from ripple::RPC::transactionSign - can we eliminate this?
|
|
explicit STTx (STObject const& object);
|
|
|
|
// STObject functions
|
|
SerializedTypeID getSType () const override
|
|
{
|
|
return STI_TRANSACTION;
|
|
}
|
|
std::string getFullText () const override;
|
|
|
|
// outer transaction functions / signature functions
|
|
Blob getSignature () const;
|
|
|
|
uint256 getSigningHash () const;
|
|
|
|
TxType getTxnType () const
|
|
{
|
|
return tx_type_;
|
|
}
|
|
STAmount getTransactionFee () const
|
|
{
|
|
return getFieldAmount (sfFee);
|
|
}
|
|
void setTransactionFee (const STAmount & fee)
|
|
{
|
|
setFieldAmount (sfFee, fee);
|
|
}
|
|
|
|
RippleAddress getSourceAccount () const
|
|
{
|
|
return getFieldAccount (sfAccount);
|
|
}
|
|
Blob getSigningPubKey () const
|
|
{
|
|
return getFieldVL (sfSigningPubKey);
|
|
}
|
|
void setSigningPubKey (const RippleAddress & naSignPubKey);
|
|
void setSourceAccount (const RippleAddress & naSource);
|
|
|
|
std::uint32_t getSequence () const
|
|
{
|
|
return getFieldU32 (sfSequence);
|
|
}
|
|
void setSequence (std::uint32_t seq)
|
|
{
|
|
return setFieldU32 (sfSequence, seq);
|
|
}
|
|
|
|
std::vector<RippleAddress> getMentionedAccounts () const;
|
|
|
|
uint256 getTransactionID () const;
|
|
|
|
virtual Json::Value getJson (int options) const override;
|
|
virtual Json::Value getJson (int options, bool binary) const;
|
|
|
|
void sign (RippleAddress const& private_key);
|
|
|
|
bool checkSign () const;
|
|
|
|
bool isKnownGood () const
|
|
{
|
|
return (sig_state_ == true);
|
|
}
|
|
bool isKnownBad () const
|
|
{
|
|
return (sig_state_ == false);
|
|
}
|
|
void setGood () const
|
|
{
|
|
sig_state_ = true;
|
|
}
|
|
void setBad () const
|
|
{
|
|
sig_state_ = false;
|
|
}
|
|
|
|
// SQL Functions with metadata
|
|
static
|
|
std::string const&
|
|
getMetaSQLInsertReplaceHeader ();
|
|
|
|
std::string getMetaSQL (
|
|
std::uint32_t inLedger, std::string const& escapedMetaData) const;
|
|
|
|
std::string getMetaSQL (
|
|
Serializer rawTxn,
|
|
std::uint32_t inLedger,
|
|
char status,
|
|
std::string const& escapedMetaData) const;
|
|
|
|
std::unique_ptr<STBase>
|
|
duplicate () const override
|
|
{
|
|
return std::make_unique<STTx>(*this);
|
|
}
|
|
|
|
private:
|
|
TxType tx_type_;
|
|
|
|
mutable boost::tribool sig_state_;
|
|
};
|
|
|
|
bool passesLocalChecks (STObject const& st, std::string&);
|
|
bool passesLocalChecks (STObject const& st);
|
|
|
|
} // ripple
|
|
|
|
#endif
|