summaryrefslogtreecommitdiff
path: root/src/ltc/pk/x25519/x25519_make_key.c
blob: 610eb96fb031d22be2526a7d5041c47c8883c893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tomcrypt_private.h"

/**
  @file x25519_make_key.c
  Create a X25519 key, Steffen Jaeckel
*/

#ifdef LTC_CURVE25519

/**
   Create a X25519 key
   @param prng     An active PRNG state
   @param wprng    The index of the PRNG desired
   @param key      [out] Destination of a newly created private key pair
   @return CRYPT_OK if successful
*/
int x25519_make_key(prng_state *prng, int wprng, curve25519_key *key)
{
   int err;

   LTC_ARGCHK(prng != NULL);
   LTC_ARGCHK(key  != NULL);

   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
      return err;
   }

   if (prng_descriptor[wprng].read(key->priv, sizeof(key->priv), prng) != sizeof(key->priv)) {
      return CRYPT_ERROR_READPRNG;
   }

   tweetnacl_crypto_scalarmult_base(key->pub, key->priv);

   key->type = PK_PRIVATE;
   key->algo = PKA_X25519;

   return err;
}

#endif