1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
12 @file der_encode_subject_public_key_info.c
13 ASN.1 DER, encode a Subject Public Key structure --nmav
18 /* AlgorithmIdentifier := SEQUENCE {
19 * algorithm OBJECT IDENTIFIER,
20 * parameters ANY DEFINED BY algorithm
23 * SubjectPublicKeyInfo := SEQUENCE {
24 * algorithm AlgorithmIdentifier,
25 * subjectPublicKey BIT STRING
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
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)
45 ltc_asn1_list alg_id[2];
48 LTC_ARGCHK(out != NULL);
49 LTC_ARGCHK(outlen != NULL);
51 err = pk_get_oid(algorithm, &oid);
52 if (err != CRYPT_OK) {
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);
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);
68 /* ref: $Format:%D$ */
69 /* git commit: $Format:%H$ */
70 /* commit time: $Format:%ai$ */