1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10 #include "tomcrypt_private.h"
11
12 /**
13 @file ed25519_import.c
14 Import a Ed25519 key from a binary packet, Steffen Jaeckel
15 */
16
17 #ifdef LTC_CURVE25519
18
19 /**
20 Import an Ed25519 public key
21 @param in The packet to read
22 @param inlen The length of the input packet
23 @param key [out] Where to import the key to
24 @return CRYPT_OK if successful, on error all allocated memory is freed automatically
25 */
ed25519_import(const unsigned char * in,unsigned long inlen,curve25519_key * key)26 int ed25519_import(const unsigned char *in, unsigned long inlen, curve25519_key *key)
27 {
28 int err;
29 unsigned long key_len;
30
31 LTC_ARGCHK(in != NULL);
32 LTC_ARGCHK(key != NULL);
33
34 key_len = sizeof(key->pub);
35 if ((err = x509_decode_subject_public_key_info(in, inlen, PKA_ED25519, key->pub, &key_len, LTC_ASN1_EOL, NULL, 0uL)) == CRYPT_OK) {
36 key->type = PK_PUBLIC;
37 key->algo = PKA_ED25519;
38 }
39 return err;
40 }
41
42 #endif
43
44 /* ref: $Format:%D$ */
45 /* git commit: $Format:%H$ */
46 /* commit time: $Format:%ai$ */
47