-
vtnerd
knaccc: clearing the lowest 3-bits has nothing to do with constant-time, and technically makes the algo 3-bits weaker than the current ed25519 scalarmult
-
vtnerd
the other clamping was to help prevent leaks with crummy implementations (technically clearing them shouldn't matter if the implementation is done properly)
-
UkoeHB
-
UkoeHB
btw tevador, randomx's blake2b implementation is not exposed so I had to copy your files over to `src/crypto`
-
UkoeHB
I also implemented `clear_internal_memory()` as a wrapper on `memwipe`.
-
knaccc
luigi1111w maybe it's possible that
-
knaccc
there could be an issue on a multi-user system
-
knaccc
or an EM leak
-
knaccc
not really sure
-
knaccc
vtnerd interesting re: crummy implementations. did you figure that out yourself, or is there somewhere i can read up about that issue?
-
vtnerd
I recall that being the explanation in the paper (or perhaps on DJBs website) -
-
vtnerd
if the implementation does bit-by-bit with shifting, it always does a computation on the first bit, partially mitigating issues with constant-time
-
vtnerd
i.e. it doesn't leak the first "real-bit" - which always seemed like an odd explanation but I recall seeing that somewhere
-
vtnerd
especially since other implementations could just botch it - but I don't see how setting those bits _makes it constant-time_
-
vtnerd
*first bit->same bit
-
knaccc
there was a stackoverflow question that claimed that about constant-time
-
knaccc
i think people were questioning it though
-
vtnerd
theres been vague discussions about it on modern-crypto? mailing list, and it came up yet again on another list let me see if I can find some links to the archives
-
knaccc
vtnerd this stackexchange answer
crypto.stackexchange.com/a/11818/43864 says "In practice, the first step of the ladder will be to find the most significant bit of the exponent. This is not hard, of course, but doing so may leak, through timing, information about the most significant bits of the exponent"
-
knaccc
which i think is why it was thought important to always set the MSB to a fixed position
-
vtnerd
hmm maybe have to go back and look at the ladder implementation. I dont see how this could matter with the window-method of ed25519 (both scalarmult and scalarmultbase)
-
vtnerd
which, perhaps thats why ed25519 doesnt even bother
-
knaccc
vtnerd is the ed25519 scalarmult supposed to be constant-time?
-
knaccc
i'd have thought that wouldn't have been a design consideration
-
vtnerd
it doesn't matter for verification, but it matters for signatures
-
vtnerd
*producing signature, the prover
-
knaccc
i guess yeah it would be bad to leak k
-
vtnerd
the x86-64 scalarmultbase in supercop is definitely designed to be constant-time, it touches every value in the pre-generated table and does cmov instead of branching
-
vtnerd
in asm. like, its just a really shitty implementation if it wasnt' trying to be constant-time
-
knaccc
it's weird that people don't say "use ed25519 for performance when verifying signatures, but use curve25519 for performance when creating signatures"
-
knaccc
there must be certain situations where it's more of a performance consideration to optimize for signing rather than verifying
-
vtnerd
perhaps our adapation for arbitrary ed25519 botched something (really hope not), but the prover code from supercop would be modified if someone found it to be variable timed
-
knaccc
interesting, thanks for the info
-
dangerousfreedom
What is the easiest way to test the cryptographic functions used by monero? Is there a help guide showing the commands and how to use it?
-
dangerousfreedom
Specifically, I want to test the 'cn_fast_hash' with some inputs and check the outputs.
-
UkoeHB
Are you writing C++ code?
-
dangerousfreedom
<UkoeHB> "Are you writing C++ code?" <- I'm trying not to. I just want to do the minimum in C++ to create my tools in Python
-
dangerousfreedom
(But to create my tools I will need to understand a lot about the monero code (in c++))
-
UkoeHB
Well `cn_fast_hash` is pretty easy to use: `#include "ringct/rctOps.h"` and `cn_fast_hash(some_rct_key_output, data, data_length)`.
-
UkoeHB
There are a bunch of different `cn_fast_hash` overloads, but they all do the same thing.
-
UkoeHB
There is also `hash_to_scalar()` which calls `cn_fast_hash()` then reduces the result modulo the ed25519 group order.
-
dangerousfreedom
Ok. Thanks UkoeHB . What I am trying to do is to understand the meaning of the 'prefix_hash' in the v1 transactions. From my understanding, I need to pass the tx string (version,unlock time, vin, vout, extra) and hash it with the cn_fast_hash algorithm. I will see if I can create a new file then in C++ and only play with this function alone.
-
dangerousfreedom
I am not quite there to use ringct. I basically want to do the same as here:
monero.stackexchange.com/questions/…lating-a-transaction-id/12236#12236
-
dangerousfreedom
But for the v1
-
knaccc
-
knaccc
it's a little odd that you're referring to (version,unlock time, vin, vout, extra) as a "string"
-
knaccc
if you want to calculate the txid yourself, you'll need to serialize the data exactly as the C code does
-
knaccc
which means thinking about bytes and data types
-
dangerousfreedom
Thanks knaccc . I am already using some libraries in python (pysha3 is one of those). My problem is to understand what I need to hash so my code in python matches with what is happening inc c++
-
dangerousfreedom
knaccc: Yeah, I guess so. Which I dont understand properly yet :p
-
knaccc
yeah you're probably going to have to get a lot more familiar with the C code
-
knaccc
why are you trying to recalcualte tx ids?
-
dangerousfreedom
I hope I won't need to understand the C code for now. I just want to understand what is being hashed.
-
knaccc
i assume you're not trying to build your own txs, and the place you get the tx from will already report the txid to you
-
dangerousfreedom
It is not the tx id. It is the prefix_hash
-
knaccc
why is that useful for you to calculate?
-
dangerousfreedom
That it part of the signature in a transaction.
-
knaccc
right, but what is the overall objective? are you just looking to learn about monero by re-implementing some stuff?
-
dangerousfreedom
And I want to understand what the signature means so I can check if they are valid (at least the amounts are matching)
-
knaccc
oh then you're going to need to learn a lot about crypto
-
knaccc
like how to do elliptic curve stuff
-
knaccc
and what pedersen commitments are
-
dangerousfreedom
My objective is to prove that there is no inflation in monero using only a python code
-
knaccc
that's already implemented as a feature in the node
-
dangerousfreedom
In python?
-
knaccc
no C. i'm just letting you know that it'll be a huge amount of work to learn enough about how the signatures are verified
-
dangerousfreedom
knaccc: I'm trying :p
-
knaccc
it'll be a fun project
-
knaccc
but i'd start with understanding the crypto, rather than starting with coding
-
knaccc
it's probably several weeks of work
-
dangerousfreedom
I believe I have basic understanding about everything (coding and math). I want to do stuff now. So, I will start with the v1 and move forward chronologically
-
dangerousfreedom
knaccc: Yeah, maybe months :p
-
knaccc
-
dangerousfreedom
knaccc: Exactely! Thats why I believe that there is only the version,unlock time, vin, vout and extra. I dont know how to play with it though.
-
knaccc
what do you mean by "play with it"
-
dangerousfreedom
Im trying to use the cn_fast_hash but Im confused about the data I need to pass
-
dangerousfreedom
And how to easily do it
-
knaccc
i assume you're starting with the bytes of a raw transaction, and just want to isolate the bytes of the prefix hash?
-
knaccc
i mean isolate the bytes of the data you need to hash to get the prefix hash
-
dangerousfreedom
I have my json of my tx (or just the data corresponding to these fields) but I dont know how to call this function alone or if there is any binding to easily do it
-
dangerousfreedom
knaccc: Yeah, basically that
-
dangerousfreedom
And call the function
-
knaccc
which one do you want to do: get the data from the json, or get the data from the raw transaction bytes
-
dangerousfreedom
First I want to know how it is hashed. I assume than that I need to pass the bytes? But in which order and how?
-
knaccc
there is a reason i'm asking. monero uses varints. if you are starting with the raw tx bytes, you already have the varints
-
knaccc
if you start with the json, you have stuff that you need to convert to varints to get the right byte representation
-
dangerousfreedom
Ah okay. I have the json. So how I start from the json information?
-
knaccc
you have to cross-reference the json with that github link i just sent you
-
dangerousfreedom
(I could have the raw tx bytes I guess but then it would be horrible to read and make sense of what I am doing)
-
knaccc
and then represent each field in the json in the byte format that is required for the hash
-
knaccc
so you can't just write an int
-
knaccc
you need to convert the int to a varint, which is a particular way of writing the int
-
knaccc
if i were you, i'd write code to parse the raw tx bytes and check your results against what the json is reporting
-
knaccc
and that'll get you familiar with data types like varints and uint64_t
-
knaccc
and once you are familiar, you'll know how to then either extract the right parts of the raw tx, or how to use the json values to produce the correct bytes that need hashing
-
dangerousfreedom
I see... I accept your suggestion. For now I will believe that what the code gives me as a json readable version is the same as it is passed by raw bytes and continue with my project. If I get the same thing in Python, I will assume it is correct and wont try to understand what these C files are doing.
-
knaccc
what i'm saying is you can't just see a number being reported by the json and use it directly
-
knaccc
that'll get you the wrong result
-
knaccc
you need to know what a varint is or you'll get nowhere
-
dangerousfreedom
Ahhh... I hope not. Let me rephrase what I'm trying to do.
-
knaccc
here is a simple example:
-
knaccc
you look at the json, and it gives you the unlock time 796803
-
knaccc
how do you convert that into bytes?
-
knaccc
if you don't convert it to bytes in exactly the right way, the hash will fail
-
dangerousfreedom
I have an implementation of cn_fast_hash in Python and I want to check that I get the same thing as I get in monero from a known transaction that I have the json file.
-
knaccc
yeah i understand that, but the hash is expecting a series of bytes
-
knaccc
and so how do you convert the number 796803 into the correct series of bytes?
-
dangerousfreedom
knaccc: Thats a good question :p
-
dangerousfreedom
I'm hoping that there are simple functions to do it.
-
knaccc
right, and to learn what functions you need to implement or look up, you need to understand exactly what data formats are required
-
knaccc
because it turns out that unlocktime needs to be written as a uint64_t
-
knaccc
and other things need to be written as varints
-
knaccc
and the extra field is just a series of bytes
-
knaccc
and vin and vout are varints
-
dangerousfreedom
For example: cn_fast_hash(bytes(version)+bytes(unlock_time)+...). In python I think it would be easy (if there is no implementation problems with these functions...)
-
dangerousfreedom
But I dont even know how to use the monero cn_fast_hash to hash for example the string '1' in bytes
-
knaccc
what is 1? is it a hex character?
-
dangerousfreedom
a string for example
-
knaccc
1 as a string is the byte 31
-
knaccc
monero doesn't use strings
-
knaccc
because 1 is an ascii code if it's treated as a string
-
knaccc
so you need to stop thinking about strings, and start thinging about either hex strings or byte sequences
-
dangerousfreedom
Yes. Thanks for answering these questions, my c++ skills and data structure knowledge are pretty rusty.
-
dangerousfreedom
knaccc: I remember that :p
-
knaccc
the bottom line is: there is no way that if you give python an integer, that it will magically know how to convert that into the correct byte sequence
-
dangerousfreedom
Ok, so how is the easiest way to call the cn_fast_hash in monero? Should I create a file with the implementation of this function to play with it or is there an easy way to call this function?
-
knaccc
the objective is just to check that your python version of cn_fast_hash is working properly right?
-
dangerousfreedom
knaccc: You will have to specify, of course.
-
dangerousfreedom
knaccc: Yes!
-
knaccc
not only will you need to specify, but you might even need to write your own varint code
-
knaccc
because it's not a common data format
-
dangerousfreedom
(But with the future goal to check that I get the same prefix_hash as I get in monero.)
-
knaccc
if i just tell you a test vector, like what cn_fast_hash should output for a certain test input, will that be enough?
-
knaccc
you don't need to actually call the C version if you know an example of what input and output should happen in python
-
dangerousfreedom
If you tell me, then I would need to trust you and that is much harder to verify :p
-
knaccc
hehe well then i guess you're going to have to learn how to set up a C environment :)
-
dangerousfreedom
knaccc: Would be great to have a small list of inputs and outputs though
-
dangerousfreedom
knaccc: I hope I wont have to go to assembly later haha
-
knaccc
here is something to get you started: if you hash a 32 byte sequence consisting of zeroes, you'll get 290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563
-
knaccc
this tool will help you
-
knaccc
-
knaccc
make sure you set the input type to hex if you give it a hex string
-
dangerousfreedom
Ok. I see that the cn_fast_hash calls the keccak1600. Is it the same as this keccak256 ?
-
knaccc
yes
-
dangerousfreedom
Is there a reason to have different names?
-
UkoeHB
`cn_fast_hash` forces the result to 32 bytes
-
knaccc
256 is the output length in bits, 1600 = 1088+512 which is an internal thing
-
dangerousfreedom
Ok thanks :)