@@ -344,13 +344,14 @@ static const struct pem_header_id pem_openssh =
344344 .has_more_headers = 0
345345 };
346346
347- static int s_decode_openssh (struct get_char * g , ltc_pka_key * k , password_ctx * pw_ctx )
347+ static int s_decode_openssh (struct get_char * g , ltc_pka_key * k , const password_ctx * pw_ctx )
348348{
349349 unsigned char * pem = NULL , * p , * privkey = NULL ;
350350 unsigned long w , l , privkey_len ;
351351 int err ;
352352 struct pem_headers hdr = { .id = & pem_openssh };
353353 struct kdf_options opts = { 0 };
354+ XMEMSET (k , 0 , sizeof (* k ));
354355 w = LTC_PEM_READ_BUFSIZE * 2 ;
355356retry :
356357 pem = XREALLOC (pem , w );
@@ -378,9 +379,8 @@ static int s_decode_openssh(struct get_char *g, ltc_pka_key *k, password_ctx *pw
378379 }
379380
380381 if (XSTRCMP (opts .name , "none" ) != 0 ) {
381- /* hard-coded pass for demo keys */
382- if (!pw_ctx || !pw_ctx -> callback ) {
383- err = CRYPT_INVALID_ARG ;
382+ if ((pw_ctx == NULL ) || (pw_ctx -> callback == NULL )) {
383+ err = CRYPT_PW_CTX_MISSING ;
384384 goto cleanup ;
385385 }
386386 if (pw_ctx -> callback (& opts .pw .pw , & opts .pw .l , pw_ctx -> userdata )) {
@@ -411,16 +411,27 @@ static int s_decode_openssh(struct get_char *g, ltc_pka_key *k, password_ctx *pw
411411 return err ;
412412}
413413
414- int pem_decode_openssh_filehandle (FILE * f , ltc_pka_key * k , password_ctx * pw_ctx )
414+ #ifndef LTC_NO_FILE
415+ int pem_decode_openssh_filehandle (FILE * f , ltc_pka_key * k , const password_ctx * pw_ctx )
415416{
416- struct get_char g = { .get = pem_get_char_from_file , .f = f };
417- return s_decode_openssh (& g , k , pw_ctx );
417+ LTC_ARGCHK (f != NULL );
418+ LTC_ARGCHK (k != NULL );
419+ {
420+ struct get_char g = { .get = pem_get_char_from_file , .f = f };
421+ return s_decode_openssh (& g , k , pw_ctx );
422+ }
418423}
424+ #endif /* LTC_NO_FILE */
419425
420- int pem_decode_openssh (const void * buf , unsigned long len , ltc_pka_key * k , password_ctx * pw_ctx )
426+ int pem_decode_openssh (const void * buf , unsigned long len , ltc_pka_key * k , const password_ctx * pw_ctx )
421427{
422- struct get_char g = { .get = pem_get_char_from_buf , SET_BUFP (.buf , buf , len ) };
423- return s_decode_openssh (& g , k , pw_ctx );
428+ LTC_ARGCHK (buf != NULL );
429+ LTC_ARGCHK (len != 0 );
430+ LTC_ARGCHK (k != NULL );
431+ {
432+ struct get_char g = { .get = pem_get_char_from_buf , SET_BUFP (.buf , buf , len ) };
433+ return s_decode_openssh (& g , k , pw_ctx );
434+ }
424435}
425436
426437#endif /* defined(LTC_PEM) && defined(LTC_SSH) */
0 commit comments