Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
external
mbedtls
Commits
9439f93e
Commit
9439f93e
authored
Nov 21, 2014
by
Manuel Pégourié-Gonnard
Browse files
Use pk_load_file() in X509
Saves a bit of ROM. X509 depends on PK anyway.
parent
2457fa09
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
51 deletions
+14
-51
include/polarssl/pk.h
include/polarssl/pk.h
+8
-0
include/polarssl/x509.h
include/polarssl/x509.h
+0
-1
library/pkparse.c
library/pkparse.c
+3
-3
library/x509.c
library/x509.c
+0
-44
library/x509_crl.c
library/x509_crl.c
+1
-1
library/x509_crt.c
library/x509_crt.c
+1
-1
library/x509_csr.c
library/x509_csr.c
+1
-1
No files found.
include/polarssl/pk.h
View file @
9439f93e
...
...
@@ -638,6 +638,14 @@ int pk_write_pubkey( unsigned char **p, unsigned char *start,
const
pk_context
*
key
);
#endif
/* POLARSSL_PK_WRITE_C */
/*
* Internal module functions. You probably do not want to use these unless you
* know you do.
*/
#if defined(POLARSSL_FS_IO)
int
pk_load_file
(
const
char
*
path
,
unsigned
char
**
buf
,
size_t
*
n
);
#endif
#ifdef __cplusplus
}
#endif
...
...
include/polarssl/x509.h
View file @
9439f93e
...
...
@@ -307,7 +307,6 @@ int x509_get_serial( unsigned char **p, const unsigned char *end,
x509_buf
*
serial
);
int
x509_get_ext
(
unsigned
char
**
p
,
const
unsigned
char
*
end
,
x509_buf
*
ext
,
int
tag
);
int
x509_load_file
(
const
char
*
path
,
unsigned
char
**
buf
,
size_t
*
n
);
int
x509_sig_alg_gets
(
char
*
buf
,
size_t
size
,
const
x509_buf
*
sig_oid
,
pk_type_t
pk_alg
,
md_type_t
md_alg
,
const
void
*
sig_opts
);
...
...
library/pkparse.c
View file @
9439f93e
...
...
@@ -71,7 +71,7 @@ static void polarssl_zeroize( void *v, size_t n ) {
/*
* Load all data from a file into a given buffer.
*/
static
int
load_file
(
const
char
*
path
,
unsigned
char
**
buf
,
size_t
*
n
)
int
pk_
load_file
(
const
char
*
path
,
unsigned
char
**
buf
,
size_t
*
n
)
{
FILE
*
f
;
long
size
;
...
...
@@ -120,7 +120,7 @@ int pk_parse_keyfile( pk_context *ctx,
size_t
n
;
unsigned
char
*
buf
;
if
(
(
ret
=
load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
if
(
(
ret
=
pk_
load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
return
(
ret
);
if
(
pwd
==
NULL
)
...
...
@@ -144,7 +144,7 @@ int pk_parse_public_keyfile( pk_context *ctx, const char *path )
size_t
n
;
unsigned
char
*
buf
;
if
(
(
ret
=
load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
if
(
(
ret
=
pk_
load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
return
(
ret
);
ret
=
pk_parse_public_key
(
ctx
,
buf
,
n
);
...
...
library/x509.c
View file @
9439f93e
...
...
@@ -636,50 +636,6 @@ int x509_get_ext( unsigned char **p, const unsigned char *end,
return
(
0
);
}
#if defined(POLARSSL_FS_IO)
/*
* Load all data from a file into a given buffer.
*/
int
x509_load_file
(
const
char
*
path
,
unsigned
char
**
buf
,
size_t
*
n
)
{
FILE
*
f
;
long
size
;
if
(
(
f
=
fopen
(
path
,
"rb"
)
)
==
NULL
)
return
(
POLARSSL_ERR_X509_FILE_IO_ERROR
);
fseek
(
f
,
0
,
SEEK_END
);
if
(
(
size
=
ftell
(
f
)
)
==
-
1
)
{
fclose
(
f
);
return
(
POLARSSL_ERR_X509_FILE_IO_ERROR
);
}
fseek
(
f
,
0
,
SEEK_SET
);
*
n
=
(
size_t
)
size
;
if
(
*
n
+
1
==
0
||
(
*
buf
=
(
unsigned
char
*
)
polarssl_malloc
(
*
n
+
1
)
)
==
NULL
)
{
fclose
(
f
);
return
(
POLARSSL_ERR_X509_MALLOC_FAILED
);
}
if
(
fread
(
*
buf
,
1
,
*
n
,
f
)
!=
*
n
)
{
fclose
(
f
);
polarssl_free
(
*
buf
);
return
(
POLARSSL_ERR_X509_FILE_IO_ERROR
);
}
fclose
(
f
);
(
*
buf
)[
*
n
]
=
'\0'
;
return
(
0
);
}
#endif
/* POLARSSL_FS_IO */
#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
!defined(EFI32)
#include <stdarg.h>
...
...
library/x509_crl.c
View file @
9439f93e
...
...
@@ -549,7 +549,7 @@ int x509_crl_parse_file( x509_crl *chain, const char *path )
size_t
n
;
unsigned
char
*
buf
;
if
(
(
ret
=
x509
_load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
if
(
(
ret
=
pk
_load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
return
(
ret
);
ret
=
x509_crl_parse
(
chain
,
buf
,
n
);
...
...
library/x509_crt.c
View file @
9439f93e
...
...
@@ -953,7 +953,7 @@ int x509_crt_parse_file( x509_crt *chain, const char *path )
size_t
n
;
unsigned
char
*
buf
;
if
(
(
ret
=
x509
_load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
if
(
(
ret
=
pk
_load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
return
(
ret
);
ret
=
x509_crt_parse
(
chain
,
buf
,
n
);
...
...
library/x509_csr.c
View file @
9439f93e
...
...
@@ -310,7 +310,7 @@ int x509_csr_parse_file( x509_csr *csr, const char *path )
size_t
n
;
unsigned
char
*
buf
;
if
(
(
ret
=
x509
_load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
if
(
(
ret
=
pk
_load_file
(
path
,
&
buf
,
&
n
)
)
!=
0
)
return
(
ret
);
ret
=
x509_csr_parse
(
csr
,
buf
,
n
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment