comparison libtomcrypt/src/pk/asn1/der/sequence/der_encode_subject_public_key_info.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9 #include "tomcrypt.h"
10
11 /**
12 @file der_encode_subject_public_key_info.c
13 ASN.1 DER, encode a Subject Public Key structure --nmav
14 */
15
16 #ifdef LTC_DER
17
18 /* AlgorithmIdentifier := SEQUENCE {
19 * algorithm OBJECT IDENTIFIER,
20 * parameters ANY DEFINED BY algorithm
21 * }
22 *
23 * SubjectPublicKeyInfo := SEQUENCE {
24 * algorithm AlgorithmIdentifier,
25 * subjectPublicKey BIT STRING
26 * }
27 */
28 /**
29 Encode a subject public key info
30 @param out The output buffer
31 @param outlen [in/out] Length of buffer and resulting length of output
32 @param algorithm One out of the enum #public_key_algorithms
33 @param public_key The buffer for the public key
34 @param public_key_len The length of the public key buffer
35 @param parameters_type The parameters' type out of the enum ltc_asn1_type
36 @param parameters The parameters to include
37 @param parameters_len The number of parameters to include
38 @return CRYPT_OK on success
39 */
40 int der_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen,
41 unsigned int algorithm, void* public_key, unsigned long public_key_len,
42 unsigned long parameters_type, void* parameters, unsigned long parameters_len)
43 {
44 int err;
45 ltc_asn1_list alg_id[2];
46 oid_st oid;
47
48 LTC_ARGCHK(out != NULL);
49 LTC_ARGCHK(outlen != NULL);
50
51 err = pk_get_oid(algorithm, &oid);
52 if (err != CRYPT_OK) {
53 return err;
54 }
55
56 LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, oid.OID, oid.OIDlen);
57 LTC_SET_ASN1(alg_id, 1, (ltc_asn1_type)parameters_type, parameters, parameters_len);
58
59 return der_encode_sequence_multi(out, outlen,
60 LTC_ASN1_SEQUENCE, (unsigned long)sizeof(alg_id)/sizeof(alg_id[0]), alg_id,
61 LTC_ASN1_RAW_BIT_STRING, public_key_len*8U, public_key,
62 LTC_ASN1_EOL, 0UL, NULL);
63
64 }
65
66 #endif
67
68 /* ref: $Format:%D$ */
69 /* git commit: $Format:%H$ */
70 /* commit time: $Format:%ai$ */
71