1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6   @file ed25519_import_raw.c
7   Set the parameters of an Ed25519 key, Steffen Jaeckel
8 */
9 
10 #ifdef LTC_CURVE25519
11 
12 /**
13    Set the parameters of an Ed25519 key
14 
15    @param in       The key
16    @param inlen    The length of the key
17    @param which    Which type of key (PK_PRIVATE or PK_PUBLIC)
18    @param key      [out] Destination of the key
19    @return CRYPT_OK if successful
20 */
ed25519_import_raw(const unsigned char * in,unsigned long inlen,int which,curve25519_key * key)21 int ed25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key)
22 {
23    LTC_ARGCHK(in   != NULL);
24    LTC_ARGCHK(inlen == 32uL);
25    LTC_ARGCHK(key  != NULL);
26 
27    if (which == PK_PRIVATE) {
28       XMEMCPY(key->priv, in, sizeof(key->priv));
29       tweetnacl_crypto_sk_to_pk(key->pub, key->priv);
30    } else if (which == PK_PUBLIC) {
31       XMEMCPY(key->pub, in, sizeof(key->pub));
32    } else {
33       return CRYPT_INVALID_ARG;
34    }
35    key->algo = LTC_OID_ED25519;
36    key->type = which;
37 
38    return CRYPT_OK;
39 }
40 
41 #endif
42