Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash x #1097

Closed
wants to merge 12 commits into from
8 changes: 3 additions & 5 deletions src/crypto/SecretKey.cpp
Expand Up @@ -14,6 +14,7 @@
#include "util/HashOfHash.h"
#include <mutex>
#include "main/Config.h"
#include "transactions/SignatureUtils.h"
#include "util/lrucache.hpp"

namespace stellar
Expand Down Expand Up @@ -327,16 +328,13 @@ PubKeyUtils::verifySig(PublicKey const& key, Signature const& signature,
SignatureHint
PubKeyUtils::getHint(PublicKey const& pk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have people call SignatureUtils::getHint directly if you want to move this function there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{
SignatureHint res;
memcpy(res.data(), &pk.ed25519().back() - res.size() + 1, res.size());
return res;
return SignatureUtils::getHint(pk.ed25519());
}

bool
PubKeyUtils::hasHint(PublicKey const& pk, SignatureHint const& hint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems misnamed. Seems like it should be called doesHintMatch or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

{
return memcmp(&pk.ed25519().back() - hint.size() + 1, hint.data(),
hint.size()) == 0;
return SignatureUtils::hasHint(pk.ed25519(), hint);
}

PublicKey
Expand Down
19 changes: 19 additions & 0 deletions src/transactions/SignatureUtils.cpp
Expand Up @@ -51,6 +51,25 @@ verifyHashX(DecoratedSignature const& sig, SignerKey const& signerKey)
return signerKey.hashX() == hash;
}

SignatureHint getHint(ByteSlice const& bs)
{
SignatureHint res;
memcpy(res.data(), bs.end() - res.size(), res.size());
return res;
}

bool
hasHint(ByteSlice const& bs, SignatureHint const& hint)
{
if (bs.size() < hint.size())
{
return false;
}

return memcmp(bs.end() - hint.size(), hint.data(),
hint.size()) == 0;
}

}

}
3 changes: 3 additions & 0 deletions src/transactions/SignatureUtils.h
Expand Up @@ -23,6 +23,9 @@ bool verify(DecoratedSignature const& sig, SignerKey const& signerKey, Hash cons
DecoratedSignature signHashX(const ByteSlice &x);
bool verifyHashX(DecoratedSignature const& sig, SignerKey const& signerKey);

SignatureHint getHint(ByteSlice const& bs);
bool hasHint(ByteSlice const& bs, SignatureHint const& hint);

}

}