Chaos.NaCl icon indicating copy to clipboard operation
Chaos.NaCl copied to clipboard

Using of _basePoint

Open wasimjee opened this issue 9 years ago • 4 comments

i need to get public key using the _basePoint, but i see nowhere, u using it,

Please prove solution.

  1. Generating Random Privatekey.
  2. Generating Public Key using Privatekey and _basePoint

wasimjee avatar Jan 11 '16 10:01 wasimjee

For montgomery form Curve25519 you can use MontgomeryCurve25519.GetPublicKey. Use a random 32 byte value as private key. Note that this twiddles some bits to match NaCl, so it doesn't work with computed scalars.

For Ed25519 you can use Ed25519.KeyPairFromSeed or (PublicKeyFromSeed and ExpandedPrivateKeyFromSeed) to generate a key-pair. Use a random 32 byte value as privateKeySeed.

Internally I'm using a specialized method for multiplying with the base point, which is about twice as fast as using a general purpose scalar multiplication routine and passing it the base point.

To generate those random 32 byte values you can use a function like:

public static byte[] GetRandomBytes(int length)
{
    using(var rng = new RNGCryptoServiceProvider())
    {
        var bytes = new byte[length];
        rng.GetBytes(bytes);
        return bytes;
    }
}

I didn't include this in my library because it's only available in some flavours of the .net framework.

CodesInChaos avatar Jan 11 '16 11:01 CodesInChaos

@CodesInChaos , Thanks for your Help,

I got the required Result.

wasimjee avatar Jan 12 '16 09:01 wasimjee

Have 2 more queries

  1. Regarding Creating Signature
  2. Regarding Verifying the Created Signature.

i am not able to get.

Please provide a solution

wasimjee avatar Jan 12 '16 09:01 wasimjee

byte[] publicKey, privateKey;
Ed25519.KeyPairFromSeed(out publicKey, out privateKey, GetRandomBytes(32));
byte[] signature = Ed25519.Sign(message, privateKey);
bool isValid = Ed25519.Verify(signature, message, publicKey);

CodesInChaos avatar Jan 13 '16 08:01 CodesInChaos