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
211a64c7
Commit
211a64c7
authored
Aug 09, 2013
by
Manuel Pégourié-Gonnard
Browse files
Add eckey to ecdsa conversion in the PK layer
parent
b4d69c41
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
include/polarssl/ecdsa.h
include/polarssl/ecdsa.h
+2
-0
include/polarssl/pk.h
include/polarssl/pk.h
+31
-0
library/pk.c
library/pk.c
+36
-0
No files found.
include/polarssl/ecdsa.h
View file @
211a64c7
...
...
@@ -31,6 +31,8 @@
/**
* \brief ECDSA context structure
*
* \note Purposefully begins with the same members as struct ecp_keypair.
*/
typedef
struct
{
...
...
include/polarssl/pk.h
View file @
211a64c7
...
...
@@ -33,6 +33,10 @@
#include "rsa.h"
#endif
#if defined(POLARSSL_ECDSA_C)
#include "ecdsa.h"
#endif
#define POLARSSL_ERR_PK_MALLOC_FAILED -0x2F80
/**< Memory alloation failed. */
#define POLARSSL_ERR_PK_TYPE_MISMATCH -0x2F00
/**< Type mismatch, eg attempt to use a RSA key as EC, or to modify key type */
...
...
@@ -107,6 +111,33 @@ void pk_free( pk_context *ctx );
*/
int
pk_set_type
(
pk_context
*
ctx
,
pk_type_t
type
);
#if defined(POLARSSL_ECDSA_C)
/**
* \brief Convert a generic EC key into an ECDSA context
*
* \param ctx Context to convert
*
* \return 0 on success, or
* POLARSSL_ERR_PK_MALLOC_FAILED or
* POLARSSL_ERR_PK_TYPE_MISMATCH.
*/
int
pk_ec_to_ecdsa
(
pk_context
*
ctx
);
/**
* \brief Tell if a PK context can be used for ECDSA
*
* \param ctx Context to check
*
* \return 0 if context cannot be used for ECDSA,
* 1 otherwise
*/
static
inline
int
pk_can_ecdsa
(
pk_context
ctx
)
{
return
(
ctx
.
type
==
POLARSSL_PK_ECKEY
||
ctx
.
type
==
POLARSSL_PK_ECDSA
);
}
#endif
/* POLARSSL_ECDSA_C */
#if defined(POLARSSL_RSA_C)
/**
* \brief Wrap a RSA context in a PK context
...
...
library/pk.c
View file @
211a64c7
...
...
@@ -132,6 +132,42 @@ int pk_set_type( pk_context *ctx, pk_type_t type )
return
(
0
);
}
#if defined(POLARSSL_ECDSA_C)
/*
* Convert generic EC context to ECDSA
*/
int
pk_ec_to_ecdsa
(
pk_context
*
ctx
)
{
ecp_keypair
*
eckey
;
ecdsa_context
*
ecdsa
;
if
(
ctx
->
type
==
POLARSSL_PK_ECDSA
)
return
(
0
);
if
(
ctx
->
type
!=
POLARSSL_PK_ECKEY
)
return
(
POLARSSL_ERR_PK_TYPE_MISMATCH
);
eckey
=
(
ecp_keypair
*
)
ctx
->
data
;
if
(
(
ecdsa
=
polarssl_malloc
(
sizeof
(
ecdsa_context
)
)
)
==
NULL
)
return
(
POLARSSL_ERR_PK_MALLOC_FAILED
);
ecdsa_init
(
ecdsa
);
/* struct ecdsa_context begins the same as struct ecp_keypair */
memcpy
(
ecdsa
,
eckey
,
sizeof
(
ecp_keypair
)
);
if
(
!
ctx
->
dont_free
)
polarssl_free
(
eckey
);
ctx
->
dont_free
=
0
;
ctx
->
type
=
POLARSSL_PK_ECDSA
;
ctx
->
data
=
ecdsa
;
return
(
0
);
}
#endif
/* POLARSSL_ECDSA_C */
#if defined(POLARSSL_RSA_C)
/*
* Wrap an RSA context in a PK context
...
...
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