1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 @file ed25519_import.c
7 Import a Ed25519 key from a SubjectPublicKeyInfo, Steffen Jaeckel
8 */
9
10 #ifdef LTC_CURVE25519
11
12 /**
13 Import an Ed25519 public key
14 @param in The packet to read
15 @param inlen The length of the input packet
16 @param key [out] Where to import the key to
17 @return CRYPT_OK if successful, on error all allocated memory is freed automatically
18 */
ed25519_import(const unsigned char * in,unsigned long inlen,curve25519_key * key)19 int ed25519_import(const unsigned char *in, unsigned long inlen, curve25519_key *key)
20 {
21 int err;
22 unsigned long key_len;
23
24 LTC_ARGCHK(in != NULL);
25 LTC_ARGCHK(key != NULL);
26
27 key_len = sizeof(key->pub);
28 if ((err = x509_decode_subject_public_key_info(in, inlen, LTC_OID_ED25519, key->pub, &key_len, LTC_ASN1_EOL, NULL, 0uL)) == CRYPT_OK) {
29 key->type = PK_PUBLIC;
30 key->algo = LTC_OID_ED25519;
31 }
32 return err;
33 }
34
35 #endif
36