0

I am trying to use Crypto.PubKey.ECIES library that call curveGenerateKeyPair function from Crypto.ECC library and Crypto.ECC uses Crypto.PubKey.ECC.P256 for scalarGenerate function, how can i modify this scalarGenerate function without modifying all those libraries?, is there any other way to do this?

Basically, I want to modify scalarGenerate function of Crypto.PubKey.ECC.P256 library (to use randomByteString generation of Raaz library), so that will affect the output of deriveEncrypt function from Crypto.PubKey.ECIES library

I'm using curve type as curve = Proxy :: Proxy Curve_X25519

Community
  • 1
  • 1
Mahesh Uligade
  • 597
  • 8
  • 17

1 Answers1

1

deriveEncrypt uses curveGenerateKeyPair for the relevant curve. I don't see anything about scalarGenerate there. The EllipticCurve instance for Curve_X25519 defines

curveGenerateKeyPair _ = do
    s <- X25519.generateSecretKey
    return $ KeyPair (X25519.toPublic s) s

If you want to generate X25519 keypairs some other way, you'll have to define your own version of the Curve_X25519 type, copy the EllipticCurve and EllipticCurveDH instances for Curve_X25519 type to make instances for your type, but replace the definition of curveGenerateKeyPair with your own.

dfeuer
  • 48,079
  • 5
  • 63
  • 167
  • Yeh we can do this if 'A' is just calling 'B' library then we can make instance of 'B' and override it, but if 'A' is calling 'B' , 'B' is calling 'C', can we override instance of 'C' from 'A'? – Mahesh Uligade Mar 13 '18 at 07:16
  • @MaheshUligade, it's really hard to come up with a concrete answer when the question is vague. Can you edit your question to explain more concretely and in more detail what you're trying to do? – dfeuer Mar 13 '18 at 07:26
  • Sorry to be vague. Basically, I want to modify the random seed generation in `scalarGenerate` function of `Crypto.PubKey.ECC.P256` , so that will effect in `curveGenerateKeyPair` in `Crypto.PubKey.ECIES` – Mahesh Uligade Mar 13 '18 at 07:30
  • @MaheshUligade, that's still vague. Please improve your question instead of creating a long thread in the comments. – dfeuer Mar 13 '18 at 08:11
  • Thanks I have done it some other way, I am upvoting your answer – Mahesh Uligade Mar 13 '18 at 18:07
  • @MaheshUligade, you should post your own answer to explain how you did it. – dfeuer Mar 13 '18 at 18:40