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
3053f5bc
Commit
3053f5bc
authored
Aug 14, 2013
by
Manuel Pégourié-Gonnard
Browse files
Get rid of pk_wrap_rsa()
parent
f8c948a6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
44 deletions
+94
-44
include/polarssl/pk.h
include/polarssl/pk.h
+0
-16
include/polarssl/rsa.h
include/polarssl/rsa.h
+11
-0
library/pk.c
library/pk.c
+1
-20
library/rsa.c
library/rsa.c
+34
-0
library/x509parse.c
library/x509parse.c
+48
-8
No files found.
include/polarssl/pk.h
View file @
3053f5bc
...
...
@@ -112,7 +112,6 @@ typedef struct
const
pk_info_t
*
info
;
/**< Public key informations */
pk_type_t
type
;
/**< Public key type (temporary) */
void
*
data
;
/**< Public key data */
int
dont_free
;
/**< True if data must not be freed */
}
pk_context
;
/**
...
...
@@ -140,21 +139,6 @@ void pk_free( pk_context *ctx );
*/
int
pk_set_type
(
pk_context
*
ctx
,
pk_type_t
type
);
#if defined(POLARSSL_RSA_C)
/**
* \brief Wrap a RSA context in a PK context
*
* \param ctx PK context to initiliaze
* \param rsa RSA context to use
*
* \note The PK context must be freshly initialized.
*
* \return O on success,
* POLARSSL_ERR_PK_TYPE_MISMATCH if ctx was not empty.
*/
int
pk_wrap_rsa
(
pk_context
*
ctx
,
const
rsa_context
*
rsa
);
#endif
/* POLARSSL_RSA_C */
#ifdef __cplusplus
}
#endif
...
...
include/polarssl/rsa.h
View file @
3053f5bc
...
...
@@ -506,6 +506,17 @@ int rsa_rsassa_pss_verify( rsa_context *ctx,
const
unsigned
char
*
hash
,
const
unsigned
char
*
sig
);
/**
* \brief Copy the components of an RSA context
*
* \param dst Destination context
* \param src Source context
*
* \return O on success,
* POLARSSL_ERR_MPI_MALLOC_FAILED on memory allocation failure
*/
int
rsa_copy
(
rsa_context
*
dst
,
const
rsa_context
*
src
);
/**
* \brief Free the components of an RSA key
*
...
...
library/pk.c
View file @
3053f5bc
...
...
@@ -58,7 +58,6 @@ void pk_init( pk_context *ctx )
ctx
->
info
=
NULL
;
ctx
->
type
=
POLARSSL_PK_NONE
;
ctx
->
data
=
NULL
;
ctx
->
dont_free
=
0
;
}
/*
...
...
@@ -88,8 +87,7 @@ void pk_free( pk_context *ctx )
;
/* guard for the else's above */
}
if
(
!
ctx
->
dont_free
)
polarssl_free
(
ctx
->
data
);
polarssl_free
(
ctx
->
data
);
ctx
->
info
=
NULL
;
ctx
->
type
=
POLARSSL_PK_NONE
;
...
...
@@ -150,20 +148,3 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
return
(
0
);
}
#if defined(POLARSSL_RSA_C)
/*
* Wrap an RSA context in a PK context
*/
int
pk_wrap_rsa
(
pk_context
*
ctx
,
const
rsa_context
*
rsa
)
{
if
(
ctx
->
type
!=
POLARSSL_PK_NONE
)
return
(
POLARSSL_ERR_PK_TYPE_MISMATCH
);
ctx
->
type
=
POLARSSL_PK_RSA
;
ctx
->
data
=
(
rsa_context
*
)
rsa
;
ctx
->
dont_free
=
1
;
return
(
0
);
}
#endif
library/rsa.c
View file @
3053f5bc
...
...
@@ -1196,6 +1196,40 @@ int rsa_pkcs1_verify( rsa_context *ctx,
}
}
/*
* Copy the components of an RSA key
*/
int
rsa_copy
(
rsa_context
*
dst
,
const
rsa_context
*
src
)
{
int
ret
;
dst
->
ver
=
src
->
ver
;
dst
->
len
=
src
->
len
;
MPI_CHK
(
mpi_copy
(
&
dst
->
N
,
&
src
->
N
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
E
,
&
src
->
E
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
D
,
&
src
->
D
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
P
,
&
src
->
P
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
Q
,
&
src
->
Q
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
DP
,
&
src
->
DP
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
DQ
,
&
src
->
DQ
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
QP
,
&
src
->
QP
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
RN
,
&
src
->
RN
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
RP
,
&
src
->
RP
)
);
MPI_CHK
(
mpi_copy
(
&
dst
->
RQ
,
&
src
->
RQ
)
);
dst
->
padding
=
src
->
padding
;
dst
->
hash_id
=
src
->
padding
;
cleanup:
if
(
ret
!=
0
)
rsa_free
(
dst
);
return
(
ret
);
}
/*
* Free the components of an RSA key
*/
...
...
library/x509parse.c
View file @
3053f5bc
...
...
@@ -2138,12 +2138,22 @@ int x509parse_public_keyfile( pk_context *ctx, const char *path )
*/
int
x509parse_keyfile_rsa
(
rsa_context
*
rsa
,
const
char
*
path
,
const
char
*
pwd
)
{
int
ret
;
pk_context
pk
;
pk_init
(
&
pk
);
pk_wrap_rsa
(
&
pk
,
rsa
);
pk_set_type
(
&
pk
,
POLARSSL_PK_RSA
);
ret
=
x509parse_keyfile
(
&
pk
,
path
,
pwd
);
if
(
ret
==
0
)
rsa_copy
(
rsa
,
pk
.
data
);
else
rsa_free
(
rsa
);
return
(
x509parse_keyfile
(
&
pk
,
path
,
pwd
)
);
pk_free
(
&
pk
);
return
(
ret
);
}
/*
...
...
@@ -2151,12 +2161,22 @@ int x509parse_keyfile_rsa( rsa_context *rsa, const char *path, const char *pwd )
*/
int
x509parse_public_keyfile_rsa
(
rsa_context
*
rsa
,
const
char
*
path
)
{
int
ret
;
pk_context
pk
;
pk_init
(
&
pk
);
pk_wrap_rsa
(
&
pk
,
rsa
);
pk_set_type
(
&
pk
,
POLARSSL_PK_RSA
);
ret
=
x509parse_public_keyfile
(
&
pk
,
path
);
if
(
ret
==
0
)
rsa_copy
(
rsa
,
pk
.
data
);
else
rsa_free
(
rsa
);
return
(
x509parse_public_keyfile
(
&
pk
,
path
)
);
pk_free
(
&
pk
);
return
(
ret
);
}
#endif
/* POLARSSL_RSA_C */
#endif
/* POLARSSL_FS_IO */
...
...
@@ -2745,12 +2765,22 @@ int x509parse_key_rsa( rsa_context *rsa,
const
unsigned
char
*
key
,
size_t
keylen
,
const
unsigned
char
*
pwd
,
size_t
pwdlen
)
{
int
ret
;
pk_context
pk
;
pk_init
(
&
pk
);
pk_wrap_rsa
(
&
pk
,
rsa
);
pk_set_type
(
&
pk
,
POLARSSL_PK_RSA
);
ret
=
x509parse_key
(
&
pk
,
key
,
keylen
,
pwd
,
pwdlen
);
if
(
ret
==
0
)
rsa_copy
(
rsa
,
pk
.
data
);
else
rsa_free
(
rsa
);
return
(
x509parse_key
(
&
pk
,
key
,
keylen
,
pwd
,
pwdlen
)
);
pk_free
(
&
pk
);
return
(
ret
);
}
/*
...
...
@@ -2759,12 +2789,22 @@ int x509parse_key_rsa( rsa_context *rsa,
int
x509parse_public_key_rsa
(
rsa_context
*
rsa
,
const
unsigned
char
*
key
,
size_t
keylen
)
{
int
ret
;
pk_context
pk
;
pk_init
(
&
pk
);
pk_wrap_rsa
(
&
pk
,
rsa
);
pk_set_type
(
&
pk
,
POLARSSL_PK_RSA
);
ret
=
x509parse_public_key
(
&
pk
,
key
,
keylen
);
if
(
ret
==
0
)
rsa_copy
(
rsa
,
pk
.
data
);
else
rsa_free
(
rsa
);
return
(
x509parse_public_key
(
&
pk
,
key
,
keylen
)
);
pk_free
(
&
pk
);
return
(
ret
);
}
#endif
/* POLARSSL_RSA_C */
...
...
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