Commit 1a7550ac authored by Paul Bakker's avatar Paul Bakker

Moved PK key parsing from X509 module to PK module

parent 24c0e848
......@@ -76,8 +76,8 @@
* Name ID Nr of Errors
* PEM 1 9
* PKCS#12 1 4 (Started from top)
* X509 2 25
* PK 2 3 (Started from top)
* X509 2 18
* PK 2 13 (Started from top)
* DHM 3 6
* PKCS5 3 4 (Started from top)
* RSA 4 9
......
......@@ -47,6 +47,17 @@
#define POLARSSL_ERR_PK_MALLOC_FAILED -0x2F80 /**< Memory alloation failed. */
#define POLARSSL_ERR_PK_TYPE_MISMATCH -0x2F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */
#define POLARSSL_ERR_PK_BAD_INPUT_DATA -0x2E80 /**< Bad input parameters to function. */
#define POLARSSL_ERR_PK_FILE_IO_ERROR -0x2E00 /**< Read/write of file failed. */
#define POLARSSL_ERR_PK_KEY_INVALID_VERSION -0x2D80 /**< Unsupported key version */
#define POLARSSL_ERR_PK_KEY_INVALID_FORMAT -0x2D00 /**< Invalid key tag or value. */
#define POLARSSL_ERR_PK_UNKNOWN_PK_ALG -0x2C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */
#define POLARSSL_ERR_PK_PASSWORD_REQUIRED -0x2C00 /**< Private key password can't be empty. */
#define POLARSSL_ERR_PK_PASSWORD_MISMATCH -0x2B80 /**< Given private key password does not allow for correct decryption. */
#define POLARSSL_ERR_PK_INVALID_PUBKEY -0x2B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
#define POLARSSL_ERR_PK_INVALID_ALG -0x2A80 /**< The algorithm tag or value is invalid. */
#define POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE -0x2A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */
#define POLARSSL_ERR_PK_FEATURE_UNAVAILABLE -0x2980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */
#if defined(POLARSSL_RSA_C)
/**
......@@ -378,6 +389,75 @@ const char * pk_get_name( const pk_context *ctx );
*/
pk_type_t pk_get_type( const pk_context *ctx );
/** \ingroup x509_module */
/**
* \brief Parse a private key
*
* \param ctx key to be initialized
* \param key input buffer
* \param keylen size of the buffer
* \param pwd password for decryption (optional)
* \param pwdlen size of the password
*
* \return 0 if successful, or a specific PK or PEM error code
*/
int pk_parse_key( pk_context *ctx,
const unsigned char *key, size_t keylen,
const unsigned char *pwd, size_t pwdlen );
#if defined(POLARSSL_FS_IO)
/** \ingroup x509_module */
/**
* \brief Load and parse a private key
*
* \param ctx key to be initialized
* \param path filename to read the private key from
* \param password password to decrypt the file (can be NULL)
*
* \return 0 if successful, or a specific PK or PEM error code
*/
int pk_parse_keyfile( pk_context *ctx,
const char *path, const char *password );
#endif /* POLARSSL_FS_IO */
/** \ingroup x509_module */
/**
* \brief Parse a public key
*
* \param ctx key to be initialized
* \param key input buffer
* \param keylen size of the buffer
*
* \return 0 if successful, or a specific PK or PEM error code
*/
int pk_parse_public_key( pk_context *ctx,
const unsigned char *key, size_t keylen );
#if defined(POLARSSL_FS_IO)
/** \ingroup x509_module */
/**
* \brief Load and parse a public key
*
* \param ctx key to be initialized
* \param path filename to read the private key from
*
* \return 0 if successful, or a specific PK or PEM error code
*/
int pk_parse_public_keyfile( pk_context *ctx, const char *path );
#endif /* POLARSSL_FS_IO */
/**
* \brief Parse a SubjectPublicKeyInfo DER structure
*
* \param p the position in the ASN.1 data
* \param end end of the buffer
* \param pk the key to fill
*
* \return 0 if successful, or a specific PK error code
*/
int pk_parse_get_pubkey( unsigned char **p, const unsigned char *end,
pk_context *pk );
#ifdef __cplusplus
}
#endif
......
......@@ -52,23 +52,16 @@
#define POLARSSL_ERR_X509_CERT_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
#define POLARSSL_ERR_X509_CERT_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
#define POLARSSL_ERR_X509_CERT_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
#define POLARSSL_ERR_X509_CERT_INVALID_PUBKEY -0x2480 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x2500 /**< The signature tag or value invalid. */
#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x2580 /**< The extension tag or value is invalid. */
#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x2600 /**< Certificate or CRL has an unsupported version number. */
#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x2680 /**< Signature algorithm (oid) is unsupported. */
#define POLARSSL_ERR_X509_UNKNOWN_PK_ALG -0x2700 /**< Key algorithm is unsupported (only RSA and EC are supported). */
#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x2780 /**< Certificate signature algorithms do not match. (see \c ::x509_cert sig_oid) */
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2800 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
#define POLARSSL_ERR_X509_KEY_INVALID_VERSION -0x2880 /**< Unsupported RSA key version */
#define POLARSSL_ERR_X509_KEY_INVALID_FORMAT -0x2900 /**< Invalid RSA key tag or value. */
#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2980 /**< Format not recognized as DER or PEM. */
#define POLARSSL_ERR_X509_INVALID_INPUT -0x2A00 /**< Input invalid. */
#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2A80 /**< Allocation of memory failed. */
#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2B00 /**< Read/write of file failed. */
#define POLARSSL_ERR_X509_PASSWORD_REQUIRED -0x2B80 /**< Private key password can't be empty. */
#define POLARSSL_ERR_X509_PASSWORD_MISMATCH -0x2C00 /**< Given private key password does not allow for correct decryption. */
#define POLARSSL_ERR_X509_UNKNOWN_NAMED_CURVE -0x2C80 /**< Elliptic curve is unsupported (only NIST curves are supported). */
#define POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE -0x2480 /**< The signature tag or value invalid. */
#define POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS -0x2500 /**< The extension tag or value is invalid. */
#define POLARSSL_ERR_X509_CERT_UNKNOWN_VERSION -0x2580 /**< Certificate or CRL has an unsupported version number. */
#define POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG -0x2600 /**< Signature algorithm (oid) is unsupported. */
#define POLARSSL_ERR_X509_CERT_SIG_MISMATCH -0x2680 /**< Certificate signature algorithms do not match. (see \c ::x509_cert sig_oid) */
#define POLARSSL_ERR_X509_CERT_VERIFY_FAILED -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
#define POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */
#define POLARSSL_ERR_X509_INVALID_INPUT -0x2800 /**< Input invalid. */
#define POLARSSL_ERR_X509_MALLOC_FAILED -0x2880 /**< Allocation of memory failed. */
#define POLARSSL_ERR_X509_FILE_IO_ERROR -0x2900 /**< Read/write of file failed. */
/* \} name */
/**
......@@ -480,63 +473,6 @@ int x509parse_public_keyfile_rsa( rsa_context *rsa, const char *path );
#endif /* POLARSSL_FS_IO */
#endif /* POLARSSL_RSA_C */
/** \ingroup x509_module */
/**
* \brief Parse a private key
*
* \param ctx key to be initialized
* \param key input buffer
* \param keylen size of the buffer
* \param pwd password for decryption (optional)
* \param pwdlen size of the password
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
int x509parse_key( pk_context *ctx,
const unsigned char *key, size_t keylen,
const unsigned char *pwd, size_t pwdlen );
#if defined(POLARSSL_FS_IO)
/** \ingroup x509_module */
/**
* \brief Load and parse a private key
*
* \param ctx key to be initialized
* \param path filename to read the private key from
* \param password password to decrypt the file (can be NULL)
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
int x509parse_keyfile( pk_context *ctx,
const char *path, const char *password );
#endif /* POLARSSL_FS_IO */
/** \ingroup x509_module */
/**
* \brief Parse a public key
*
* \param ctx key to be initialized
* \param key input buffer
* \param keylen size of the buffer
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
int x509parse_public_key( pk_context *ctx,
const unsigned char *key, size_t keylen );
#if defined(POLARSSL_FS_IO)
/** \ingroup x509_module */
/**
* \brief Load and parse a public key
*
* \param ctx key to be initialized
* \param path filename to read the private key from
*
* \return 0 if successful, or a specific X509 or PEM error code
*/
int x509parse_public_keyfile( pk_context *ctx, const char *path );
#endif /* POLARSSL_FS_IO */
/** \ingroup x509_module */
/**
* \brief Parse DHM parameters
......
......@@ -41,6 +41,7 @@ set(src
pkcs12.c
pk.c
pk_wrap.c
pkparse.c
rsa.c
sha1.c
sha256.c
......
......@@ -49,7 +49,7 @@ OBJS= aes.o arc4.o asn1parse.o \
oid.o \
padlock.o pbkdf2.o pem.o \
pkcs5.o pkcs11.o pkcs12.o \
pk.o pk_wrap.o \
pk.o pk_wrap.o pkparse.o \
rsa.o sha1.o sha256.o \
sha512.o ssl_cache.o ssl_cli.o \
ssl_srv.o ssl_ciphersuites.o \
......
......@@ -214,9 +214,11 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
if( use_ret == -(POLARSSL_ERR_ECP_BUFFER_TOO_SMALL) )
snprintf( buf, buflen, "ECP - The buffer is too small to write to" );
if( use_ret == -(POLARSSL_ERR_ECP_GENERIC) )
snprintf( buf, buflen, "ECP - Generic ECP error" );
snprintf( buf, buflen, "ECP - Generic ECP error" );
if( use_ret == -(POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE) )
snprintf( buf, buflen, "ECP - Requested curve not available" );
if( use_ret == -(POLARSSL_ERR_ECP_VERIFY_FAILED) )
snprintf( buf, buflen, "ECP - The signature is not valid" );
#endif /* POLARSSL_ECP_C */
#if defined(POLARSSL_MD_C)
......@@ -258,6 +260,26 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
snprintf( buf, buflen, "PK - Type mismatch, eg attempt to encrypt with an ECDSA key" );
if( use_ret == -(POLARSSL_ERR_PK_BAD_INPUT_DATA) )
snprintf( buf, buflen, "PK - Bad input parameters to function" );
if( use_ret == -(POLARSSL_ERR_PK_FILE_IO_ERROR) )
snprintf( buf, buflen, "PK - Read/write of file failed" );
if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_VERSION) )
snprintf( buf, buflen, "PK - Unsupported key version" );
if( use_ret == -(POLARSSL_ERR_PK_KEY_INVALID_FORMAT) )
snprintf( buf, buflen, "PK - Invalid key tag or value" );
if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_PK_ALG) )
snprintf( buf, buflen, "PK - Key algorithm is unsupported (only RSA and EC are supported)" );
if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_REQUIRED) )
snprintf( buf, buflen, "PK - Private key password can't be empty" );
if( use_ret == -(POLARSSL_ERR_PK_PASSWORD_MISMATCH) )
snprintf( buf, buflen, "PK - Given private key password does not allow for correct decryption" );
if( use_ret == -(POLARSSL_ERR_PK_INVALID_PUBKEY) )
snprintf( buf, buflen, "PK - The pubkey tag or value is invalid (only RSA and EC are supported)" );
if( use_ret == -(POLARSSL_ERR_PK_INVALID_ALG) )
snprintf( buf, buflen, "PK - The algorithm tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_PK_UNKNOWN_NAMED_CURVE) )
snprintf( buf, buflen, "PK - Elliptic curve is unsupported (only NIST curves are supported)" );
if( use_ret == -(POLARSSL_ERR_PK_FEATURE_UNAVAILABLE) )
snprintf( buf, buflen, "PK - Unavailable feature, e.g. RSA disabled for RSA key" );
#endif /* POLARSSL_PK_C */
#if defined(POLARSSL_PKCS12_C)
......@@ -400,8 +422,6 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
snprintf( buf, buflen, "X509 - The name tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_DATE) )
snprintf( buf, buflen, "X509 - The date tag or value is invalid" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_PUBKEY) )
snprintf( buf, buflen, "X509 - The pubkey tag or value is invalid (only RSA is supported)" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_SIGNATURE) )
snprintf( buf, buflen, "X509 - The signature tag or value invalid" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_INVALID_EXTENSIONS) )
......@@ -410,16 +430,10 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
snprintf( buf, buflen, "X509 - Certificate or CRL has an unsupported version number" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_SIG_ALG) )
snprintf( buf, buflen, "X509 - Signature algorithm (oid) is unsupported" );
if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_PK_ALG) )
snprintf( buf, buflen, "X509 - Key algorithm is unsupported (only RSA and EC are supported)" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_SIG_MISMATCH) )
snprintf( buf, buflen, "X509 - Certificate signature algorithms do not match. (see \\c ::x509_cert sig_oid)" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_VERIFY_FAILED) )
snprintf( buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed" );
if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_VERSION) )
snprintf( buf, buflen, "X509 - Unsupported RSA key version" );
if( use_ret == -(POLARSSL_ERR_X509_KEY_INVALID_FORMAT) )
snprintf( buf, buflen, "X509 - Invalid RSA key tag or value" );
if( use_ret == -(POLARSSL_ERR_X509_CERT_UNKNOWN_FORMAT) )
snprintf( buf, buflen, "X509 - Format not recognized as DER or PEM" );
if( use_ret == -(POLARSSL_ERR_X509_INVALID_INPUT) )
......@@ -428,12 +442,6 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
snprintf( buf, buflen, "X509 - Allocation of memory failed" );
if( use_ret == -(POLARSSL_ERR_X509_FILE_IO_ERROR) )
snprintf( buf, buflen, "X509 - Read/write of file failed" );
if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_REQUIRED) )
snprintf( buf, buflen, "X509 - Private key password can't be empty" );
if( use_ret == -(POLARSSL_ERR_X509_PASSWORD_MISMATCH) )
snprintf( buf, buflen, "X509 - Given private key password does not allow for correct decryption" );
if( use_ret == -(POLARSSL_ERR_X509_UNKNOWN_NAMED_CURVE) )
snprintf( buf, buflen, "X509 - Elliptic curve is unsupported (only NIST curves are supported)" );
#endif /* POLARSSL_X509_PARSE_C */
#if defined(POLARSSL_X509_WRITE_C)
......
This diff is collapsed.
This diff is collapsed.
......@@ -250,11 +250,11 @@ int main( int argc, char *argv[] )
printf( "\n . Loading the private key ..." );
fflush( stdout );
ret = x509parse_keyfile( &key, opt.filename, NULL );
ret = pk_parse_keyfile( &key, opt.filename, NULL );
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned %d", ret );
printf( " failed\n ! pk_parse_key returned %d", ret );
goto exit;
}
......@@ -291,11 +291,11 @@ int main( int argc, char *argv[] )
printf( "\n . Loading the public key ..." );
fflush( stdout );
ret = x509parse_public_keyfile( &key, opt.filename );
ret = pk_parse_public_keyfile( &key, opt.filename );
if( ret != 0 )
{
printf( " failed\n ! x509parse_public_key returned %d", ret );
printf( " failed\n ! pk_parse_public_key returned %d", ret );
goto exit;
}
......
......@@ -626,11 +626,11 @@ int main( int argc, char *argv[] )
#if defined(POLARSSL_FS_IO)
if( strlen( opt.key_file ) )
ret = x509parse_keyfile( &pkey, opt.key_file, "" );
ret = pk_parse_keyfile( &pkey, opt.key_file, "" );
else
#endif
#if defined(POLARSSL_CERTS_C)
ret = x509parse_key( &pkey, (const unsigned char *) test_cli_key,
ret = pk_parse_key( &pkey, (const unsigned char *) test_cli_key,
strlen( test_cli_key ), NULL, 0 );
#else
{
......@@ -640,7 +640,7 @@ int main( int argc, char *argv[] )
#endif
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned -0x%x\n\n", -ret );
printf( " failed\n ! pk_parse_key returned -0x%x\n\n", -ret );
goto exit;
}
......
......@@ -158,11 +158,11 @@ int main( int argc, char *argv[] )
}
pk_init( &pkey );
ret = x509parse_key( &pkey, (const unsigned char *) test_srv_key,
ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned %d\n\n", ret );
printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
......
......@@ -532,11 +532,11 @@ int main( int argc, char *argv[] )
#if defined(POLARSSL_FS_IO)
if( strlen( opt.key_file ) )
ret = x509parse_keyfile( &pkey, opt.key_file, "" );
ret = pk_parse_keyfile( &pkey, opt.key_file, "" );
else
#endif
#if defined(POLARSSL_CERTS_C)
ret = x509parse_key( &pkey, (const unsigned char *) test_cli_key,
ret = pk_parse_key( &pkey, (const unsigned char *) test_cli_key,
strlen( test_cli_key ), NULL, 0 );
#else
{
......@@ -546,7 +546,7 @@ int main( int argc, char *argv[] )
#endif
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned %d\n\n", ret );
printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
......
......@@ -136,11 +136,11 @@ int main( int argc, char *argv[] )
}
pk_init( &pkey );
ret = x509parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned %d\n\n", ret );
printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
......
......@@ -575,11 +575,11 @@ int main( int argc, char *argv[] )
#if defined(POLARSSL_FS_IO)
if( strlen( opt.key_file ) )
ret = x509parse_keyfile( &pkey, opt.key_file, "" );
ret = pk_parse_keyfile( &pkey, opt.key_file, "" );
else
#endif
#if defined(POLARSSL_CERTS_C)
ret = x509parse_key( &pkey, (const unsigned char *) test_srv_key,
ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
#else
{
......@@ -589,7 +589,7 @@ int main( int argc, char *argv[] )
#endif
if( ret != 0 )
{
printf( " failed\n ! x509parse_key returned -0x%x\n\n", -ret );
printf( " failed\n ! pk_parse_key returned -0x%x\n\n", -ret );
goto exit;
}
......
......@@ -229,11 +229,11 @@ static int ssl_test( struct options *opt )
goto exit;
}
ret = x509parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
printf( " ! x509parse_key returned %d\n\n", ret );
printf( " ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
#endif
......
......@@ -292,11 +292,11 @@ int main( int argc, char *argv[] )
printf( " . Loading the private key ..." );
fflush( stdout );
ret = x509parse_keyfile( &key, opt.filename, NULL );
ret = pk_parse_keyfile( &key, opt.filename, NULL );
if( ret != 0 )
{
printf( " failed\n ! x509parse_keyfile returned %d", ret );
printf( " failed\n ! pk_parse_keyfile returned %d", ret );
goto exit;
}
......
......@@ -458,12 +458,12 @@ int main( int argc, char *argv[] )
printf( " . Loading the subject key ..." );
fflush( stdout );
ret = x509parse_keyfile( &loaded_subject_key, opt.subject_key,
ret = pk_parse_keyfile( &loaded_subject_key, opt.subject_key,
opt.subject_pwd );
if( ret != 0 )
{
error_strerror( ret, buf, 1024 );
printf( " failed\n ! x509parse_keyfile returned -0x%02x - %s\n\n", -ret, buf );
printf( " failed\n ! pk_parse_keyfile returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
......@@ -473,12 +473,12 @@ int main( int argc, char *argv[] )
printf( " . Loading the issuer key ..." );
fflush( stdout );
ret = x509parse_keyfile( &loaded_issuer_key, opt.issuer_key,
opt.issuer_pwd );
ret = pk_parse_keyfile( &loaded_issuer_key, opt.issuer_key,
opt.issuer_pwd );
if( ret != 0 )
{
error_strerror( ret, buf, 1024 );
printf( " failed\n ! x509parse_keyfile returned -x%02x - %s\n\n", -ret, buf );
printf( " failed\n ! pk_parse_keyfile returned -x%02x - %s\n\n", -ret, buf );
goto exit;
}
......
......@@ -68,6 +68,7 @@ add_test_suite(mpi)
add_test_suite(pbkdf2)
add_test_suite(pkcs1_v21)
add_test_suite(pkcs5)
add_test_suite(pkparse)
add_test_suite(shax)
add_test_suite(rsa)
add_test_suite(version)
......
......@@ -47,6 +47,7 @@ APPS = test_suite_aes.ecb test_suite_aes.cbc \
test_suite_md test_suite_mdx \
test_suite_mpi test_suite_pbkdf2 \
test_suite_pkcs1_v21 test_suite_pkcs5 \
test_suite_pkparse \
test_suite_rsa test_suite_shax \
test_suite_x509parse test_suite_x509write \
test_suite_xtea test_suite_version
......@@ -275,6 +276,10 @@ test_suite_pkcs5: test_suite_pkcs5.c ../library/libpolarssl.a
echo " CC $@.c"
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
test_suite_pkparse: test_suite_pkparse.c ../library/libpolarssl.a
echo " CC $@.c"
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
test_suite_rsa: test_suite_rsa.c ../library/libpolarssl.a
echo " CC $@.c"
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
......
This diff is collapsed.
/* BEGIN_HEADER */
#include <polarssl/pk.h>
#include <polarssl/pem.h>
#include <polarssl/oid.h>
/* END_HEADER */
/* BEGIN_DEPENDENCIES
* depends_on:POLARSSL_PK_C:POLARSSL_BIGNUM_C
* END_DEPENDENCIES
*/
/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
void pk_parse_keyfile_rsa( char *key_file, char *password, int result )
{
pk_context ctx;
int res;
char *pwd = password;
pk_init( &ctx );
if( strcmp( pwd, "NULL" ) == 0 )
pwd = NULL;
res = pk_parse_keyfile( &ctx, key_file, pwd );
TEST_ASSERT( res == result );
if( res == 0 )
{
rsa_context *rsa;
TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_RSA ) );
rsa = pk_rsa( ctx );
TEST_ASSERT( rsa_check_privkey( rsa ) == 0 );
}
pk_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
void pk_parse_public_keyfile_rsa( char *key_file, int result )
{
pk_context ctx;
int res;
pk_init( &ctx );
res = pk_parse_public_keyfile( &ctx, key_file );
TEST_ASSERT( res == result );
if( res == 0 )
{
rsa_context *rsa;
TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_RSA ) );
rsa = pk_rsa( ctx );
TEST_ASSERT( rsa_check_pubkey( rsa ) == 0 );
}
pk_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE */
void pk_parse_public_keyfile_ec( char *key_file, int result )
{
pk_context ctx;
int res;
pk_init( &ctx );
res = pk_parse_public_keyfile( &ctx, key_file );
TEST_ASSERT( res == result );
if( res == 0 )
{
ecp_keypair *eckey;
TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
eckey = pk_ec( ctx );
TEST_ASSERT( ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
}
pk_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE */
void pk_parse_keyfile_ec( char *key_file, char *password, int result )
{
pk_context ctx;
int res;
pk_init( &ctx );
res = pk_parse_keyfile( &ctx, key_file, password );
TEST_ASSERT( res == result );
if( res == 0 )
{
ecp_keypair *eckey;
TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
eckey = pk_ec( ctx );
TEST_ASSERT( ecp_check_privkey( &eckey->grp, &eckey->d ) == 0 );
}
pk_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
void pk_parse_key_rsa( char *key_data, char *result_str, int result )
{
pk_context pk;
unsigned char buf[2000];
unsigned char output[2000];
int data_len;
((void) result_str);
pk_init( &pk );
memset( buf, 0, 2000 );
memset( output, 0, 2000 );
data_len = unhexify( buf, key_data );
TEST_ASSERT( pk_parse_key( &pk, buf, data_len, NULL, 0 ) == ( result ) );
if( ( result ) == 0 )
{
TEST_ASSERT( 1 );
}
pk_free( &pk );
}
/* END_CASE */
This diff is collapsed.
......@@ -165,100 +165,6 @@ void x509_time_expired( char *crt_file, char *entity, int result )
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
void x509parse_keyfile_rsa( char *key_file, char *password, int result )
{
rsa_context rsa;
int res;
char *pwd = password;
memset( &rsa, 0, sizeof( rsa_context ) );
if( strcmp( pwd, "NULL" ) == 0 )
pwd = NULL;
res = x509parse_keyfile_rsa( &rsa, key_file, pwd );
TEST_ASSERT( res == result );
if( res == 0 )
{
TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
}
rsa_free( &rsa );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RSA_C */
void x509parse_public_keyfile_rsa( char *key_file, int result )
{
rsa_context rsa;
int res;
memset( &rsa, 0, sizeof( rsa_context ) );
res = x509parse_public_keyfile_rsa( &rsa, key_file );
TEST_ASSERT( res == result );
if( res == 0 )
{
TEST_ASSERT( rsa_check_pubkey( &rsa ) == 0 );
}
rsa_free( &rsa );
}
/* END_CASE */
/* BEGIN_CASE */
void x509parse_public_keyfile_ec( char *key_file, int result )
{
pk_context ctx;
int res;
pk_init( &ctx );
res = x509parse_public_keyfile( &ctx, key_file );
TEST_ASSERT( res == result );
if( res == 0 )
{
ecp_keypair *eckey;
TEST_ASSERT( pk_can_do( &ctx, POLARSSL_PK_ECKEY ) );
eckey = pk_ec( ctx );
TEST_ASSERT( ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
}
pk_free( &ctx );
}
/* END_CASE */
/* BEGIN_CASE */
<