1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6   @file x25519_make_key.c
7   Create a X25519 key, Steffen Jaeckel
8 */
9 
10 #ifdef LTC_CURVE25519
11 
12 /**
13    Create a X25519 key
14    @param prng     An active PRNG state
15    @param wprng    The index of the PRNG desired
16    @param key      [out] Destination of a newly created private key pair
17    @return CRYPT_OK if successful
18 */
x25519_make_key(prng_state * prng,int wprng,curve25519_key * key)19 int x25519_make_key(prng_state *prng, int wprng, curve25519_key *key)
20 {
21    int err;
22 
23    LTC_ARGCHK(key  != NULL);
24 
25    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
26       return err;
27    }
28 
29    if (prng_descriptor[wprng]->read(key->priv, sizeof(key->priv), prng) != sizeof(key->priv)) {
30       return CRYPT_ERROR_READPRNG;
31    }
32 
33    tweetnacl_crypto_scalarmult_base(key->pub, key->priv);
34 
35    key->type = PK_PRIVATE;
36    key->algo = LTC_OID_X25519;
37 
38    return err;
39 }
40 
41 #endif
42