Changeset View
Changeset View
Standalone View
Standalone View
src/script/sigencoding.cpp
Show First 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | switch (vchPubKey.size()) { | ||||
return vchPubKey[0] == 0x04; | return vchPubKey[0] == 0x04; | ||||
default: | default: | ||||
// Non-canonical public key: invalid size. | // Non-canonical public key: invalid size. | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
static bool IsCompressedPubKey(const valtype &vchPubKey) { | |||||
if (vchPubKey.size() != CPubKey::COMPRESSED_PUBLIC_KEY_SIZE) { | |||||
// Non-canonical public key: invalid length for compressed key | |||||
return false; | |||||
} | |||||
if (vchPubKey[0] != 0x02 && vchPubKey[0] != 0x03) { | |||||
// Non-canonical public key: invalid prefix for compressed key | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
bool CheckPubKeyEncoding(const valtype &vchPubKey, uint32_t flags, | bool CheckPubKeyEncoding(const valtype &vchPubKey, uint32_t flags, | ||||
ScriptError *serror) { | ScriptError *serror) { | ||||
if ((flags & SCRIPT_VERIFY_STRICTENC) && | if ((flags & SCRIPT_VERIFY_STRICTENC) && | ||||
!IsCompressedOrUncompressedPubKey(vchPubKey)) { | !IsCompressedOrUncompressedPubKey(vchPubKey)) { | ||||
return set_error(serror, ScriptError::PUBKEYTYPE); | return set_error(serror, ScriptError::PUBKEYTYPE); | ||||
} | } | ||||
// Only compressed keys are accepted when | |||||
// SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE is enabled. | |||||
if ((flags & SCRIPT_VERIFY_COMPRESSED_PUBKEYTYPE) && | |||||
!IsCompressedPubKey(vchPubKey)) { | |||||
return set_error(serror, ScriptError::NONCOMPRESSED_PUBKEY); | |||||
} | |||||
return true; | return true; | ||||
} | } |