0

Is there any obvious gain to using epee in the crypto module?

I don't know why this code is inside crypto instead of cryptonote:

  inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) {
    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
  }
  inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) {
    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
  }
  inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) {
    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
  }
  inline std::ostream &operator <<(std::ostream &o, const crypto::key_image &v) {
    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
  }
  inline std::ostream &operator <<(std::ostream &o, const crypto::signature &v) {
    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
  }

It is a way to convert data to hex, so why is this part of the crypto module?

And maybe a template function can do the job:

template <typename T> std::ostream &operator <<(std::ostream &o, T &v) {
  epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
}

As we know public_key and private_key are parts of cryptonote not crypto. So why should this code be put into the crypto module?

To my understanding, the crypto module only cares about hashing. Am I wrong?

1

It may help to first understand that CryptoNote is a protocol and that the crypto module contains cryptographic primitives.

public_key, secret_key, key_derivation, key_image, signature... these are all cryptographic primitives, hence they are all correctly in the crypto module, as are the hashing functions.

The reason for the output stream functions being in the crypto module and not CryptoNote is that they are not CryptoNote specific. They provide a way to output the primitives to a stream (encoded as hex).

  • But as far as I know public/private keys are used for wallet address , transaction encryption, blockchain recording and validation not for generating hash. Only the hash is what related to crypto module the most where pow algorithm is the core for this module. I think keys would better be hold inside cryptonote core where transactions are generated. It seems the consistency is broken when putting keys into crypto module. – Bai Lee Nov 19 '18 at 18:25
  • No, the crypto module holds much more than just hashing functions - it holds all the cryptographic primitives. For example, all the ECC math is in this file. Again, CryptoNote is a protocol, crypto holds cryptographic primitives (which are used in many places). – jtgrassie Nov 19 '18 at 18:54
  • As what you've addressed, I think account.cpp should be moved to crypto module, where it use public keys and encryption to generate new keys. Both keys and encryption are used. – Bai Lee Nov 19 '18 at 19:17
  • "Account" is not a cryptographic primitive. Just because something "uses" a cryptographic primitive, does not make it one. – jtgrassie Nov 19 '18 at 19:32
  • so is it a must to introduce epee just for formatting strings? – Bai Lee Nov 19 '18 at 19:59

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.