1212extern const struct pem_header_id pem_std_headers [];
1313extern const unsigned long pem_std_headers_num ;
1414
15- static int s_decrypt_pem (unsigned char * pem , unsigned long * l , const struct pem_headers * hdr )
15+ static int s_decrypt_pem (unsigned char * asn1_cert , unsigned long * asn1_len , const struct pem_headers * hdr )
1616{
1717 unsigned char iv [MAXBLOCKSIZE ], key [MAXBLOCKSIZE ];
1818 unsigned long ivlen , klen ;
@@ -34,7 +34,7 @@ static int s_decrypt_pem(unsigned char *pem, unsigned long *l, const struct pem_
3434 return err ;
3535 }
3636
37- err = pem_decrypt (pem , l , key , klen , iv , ivlen , NULL , 0 , & hdr -> info , LTC_PAD_PKCS7 );
37+ err = pem_decrypt (asn1_cert , asn1_len , key , klen , iv , ivlen , NULL , 0 , & hdr -> info , LTC_PAD_PKCS7 );
3838
3939 zeromem (key , sizeof (key ));
4040 zeromem (iv , sizeof (iv ));
@@ -82,12 +82,12 @@ static const import_fn s_import_x509_fns[LTC_PKA_NUM] = {
8282#endif
8383};
8484
85- static int s_import_x509 (unsigned char * pem , unsigned long l , ltc_pka_key * k )
85+ static int s_import_x509 (unsigned char * asn1_cert , unsigned long asn1_len , ltc_pka_key * k )
8686{
8787 enum ltc_pka_id pka = LTC_PKA_UNDEF ;
8888 ltc_asn1_list * d , * spki ;
8989 int err ;
90- if ((err = x509_decode_spki (pem , l , & d , & spki )) != CRYPT_OK ) {
90+ if ((err = x509_decode_spki (asn1_cert , asn1_len , & d , & spki )) != CRYPT_OK ) {
9191 return err ;
9292 }
9393 err = s_get_pka (spki , & pka );
@@ -100,19 +100,19 @@ static int s_import_x509(unsigned char *pem, unsigned long l, ltc_pka_key *k)
100100 || s_import_x509_fns [pka ] == NULL ) {
101101 return CRYPT_PK_INVALID_TYPE ;
102102 }
103- if ((err = s_import_x509_fns [pka ](pem , l , & k -> u )) == CRYPT_OK ) {
103+ if ((err = s_import_x509_fns [pka ](asn1_cert , asn1_len , & k -> u )) == CRYPT_OK ) {
104104 k -> id = pka ;
105105 }
106106 return err ;
107107}
108108
109- static int s_import_pkcs8 (unsigned char * pem , unsigned long l , ltc_pka_key * k , const password_ctx * pw_ctx )
109+ static int s_import_pkcs8 (unsigned char * asn1_cert , unsigned long asn1_len , ltc_pka_key * k , const password_ctx * pw_ctx )
110110{
111111 int err ;
112112 enum ltc_oid_id pka ;
113113 ltc_asn1_list * alg_id , * priv_key ;
114114 ltc_asn1_list * p8_asn1 = NULL ;
115- if ((err = pkcs8_decode_flexi (pem , l , pw_ctx , & p8_asn1 )) != CRYPT_OK ) {
115+ if ((err = pkcs8_decode_flexi (asn1_cert , asn1_len , pw_ctx , & p8_asn1 )) != CRYPT_OK ) {
116116 goto cleanup ;
117117 }
118118 if ((err = pkcs8_get_children (p8_asn1 , & pka , & alg_id , & priv_key )) != CRYPT_OK ) {
@@ -164,11 +164,11 @@ static int s_import_pkcs8(unsigned char *pem, unsigned long l, ltc_pka_key *k, c
164164 return err ;
165165}
166166
167- static int s_extract_pka (unsigned char * pem , unsigned long w , enum ltc_pka_id * pka )
167+ static int s_extract_pka (unsigned char * asn1_cert , unsigned long asn1_len , enum ltc_pka_id * pka )
168168{
169169 ltc_asn1_list * pub ;
170170 int err = CRYPT_ERROR ;
171- if ((err = der_decode_sequence_flexi (pem , & w , & pub )) != CRYPT_OK ) {
171+ if ((err = der_decode_sequence_flexi (asn1_cert , & asn1_len , & pub )) != CRYPT_OK ) {
172172 return err ;
173173 }
174174 err = s_get_pka (pub , pka );
@@ -194,19 +194,19 @@ static const import_fn s_import_openssl_fns[LTC_PKA_NUM] = {
194194
195195static int s_decode (struct get_char * g , ltc_pka_key * k , const password_ctx * pw_ctx )
196196{
197- unsigned char * pem = NULL ;
198- unsigned long w , l , n ;
197+ unsigned char * asn1_cert = NULL ;
198+ unsigned long w , asn1_len , n ;
199199 int err = CRYPT_ERROR ;
200200 struct pem_headers hdr = { 0 };
201201 struct password pw = { 0 };
202202 enum ltc_pka_id pka ;
203203 XMEMSET (k , 0 , sizeof (* k ));
204204 w = LTC_PEM_READ_BUFSIZE * 2 ;
205205retry :
206- pem = XREALLOC (pem , w );
206+ asn1_cert = XREALLOC (asn1_cert , w );
207207 for (n = 0 ; n < pem_std_headers_num ; ++ n ) {
208208 hdr .id = & pem_std_headers [n ];
209- err = pem_read (pem , & w , & hdr , g );
209+ err = pem_read (asn1_cert , & w , & hdr , g );
210210 if (err == CRYPT_BUFFER_OVERFLOW ) {
211211 goto retry ;
212212 } else if (err == CRYPT_OK ) {
@@ -219,15 +219,15 @@ static int s_decode(struct get_char *g, ltc_pka_key *k, const password_ctx *pw_c
219219 /* id not found */
220220 if (hdr .id == NULL )
221221 goto cleanup ;
222- l = w ;
222+ asn1_len = w ;
223223 if (hdr .id -> flags & pf_pkcs8 ) {
224- err = s_import_pkcs8 (pem , l , k , pw_ctx );
224+ err = s_import_pkcs8 (asn1_cert , asn1_len , k , pw_ctx );
225225 goto cleanup ;
226226 } else if (hdr .id -> flags == pf_x509 ) {
227- err = s_import_x509 (pem , l , k );
227+ err = s_import_x509 (asn1_cert , asn1_len , k );
228228 goto cleanup ;
229229 } else if ((hdr .id -> flags & pf_public ) && hdr .id -> pka == LTC_PKA_UNDEF ) {
230- if ((err = s_extract_pka (pem , w , & pka )) != CRYPT_OK ) {
230+ if ((err = s_extract_pka (asn1_cert , asn1_len , & pka )) != CRYPT_OK ) {
231231 goto cleanup ;
232232 }
233233 } else if (hdr .encrypted ) {
@@ -242,7 +242,7 @@ static int s_decode(struct get_char *g, ltc_pka_key *k, const password_ctx *pw_c
242242 goto cleanup ;
243243 }
244244
245- if ((err = s_decrypt_pem (pem , & l , & hdr )) != CRYPT_OK ) {
245+ if ((err = s_decrypt_pem (asn1_cert , & asn1_len , & hdr )) != CRYPT_OK ) {
246246 goto cleanup ;
247247 }
248248 pka = hdr .id -> pka ;
@@ -256,13 +256,13 @@ static int s_decode(struct get_char *g, ltc_pka_key *k, const password_ctx *pw_c
256256 err = CRYPT_PK_INVALID_TYPE ;
257257 goto cleanup ;
258258 }
259- if ((err = s_import_openssl_fns [pka ](pem , l , & k -> u )) == CRYPT_OK ) {
259+ if ((err = s_import_openssl_fns [pka ](asn1_cert , asn1_len , & k -> u )) == CRYPT_OK ) {
260260 k -> id = pka ;
261261 }
262262
263263cleanup :
264264 password_free (hdr .pw , pw_ctx );
265- XFREE (pem );
265+ XFREE (asn1_cert );
266266 return err ;
267267}
268268
0 commit comments