From 5cc7bc596da2bd97e1e7ad121e40d499d17ddbfb Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 3 Nov 2017 11:58:25 +0100 Subject: [PATCH] Move pk_info structure to its own file This is in preparation to adding support for opaque keys in the pk layer. The header files are for use as follows: * pk.h for users of the pk interface. * pk_info.h for implementers of opaque key engines. * pk_internal.h only inside libmbedcrypto to implement built-in pk types. --- include/mbedtls/pk_info.h | 89 ++++++++++++++++++++++++++++++++++ include/mbedtls/pk_internal.h | 66 +++---------------------- library/pk.c | 1 + library/pk_wrap.c | 1 + visualc/VS2010/mbedTLS.vcxproj | 1 + 5 files changed, 98 insertions(+), 60 deletions(-) create mode 100644 include/mbedtls/pk_info.h diff --git a/include/mbedtls/pk_info.h b/include/mbedtls/pk_info.h new file mode 100644 index 000000000..fe2dbdfc1 --- /dev/null +++ b/include/mbedtls/pk_info.h @@ -0,0 +1,89 @@ +/** + * \file pk_info.h + * + * \brief Public Key cryptography abstraction layer: object interface + * + * Copyright (C) 2006-2017, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_PK_INFO_H +#define MBEDTLS_PK_INFO_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include "pk.h" + +struct mbedtls_pk_info_t +{ + /** Key pair type with indication of supported algorithms */ + mbedtls_pk_type_t type; + + /** Type name */ + const char *name; + + /** Get key size in bits */ + size_t (*get_bitlen)( const void *ctx ); + + /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */ + int (*can_do)( const void * ctx, mbedtls_pk_type_t type ); + + /** Verify signature */ + int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ); + + /** Make signature */ + int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + + /** Decrypt message */ + int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + + /** Encrypt message */ + int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + + /** Check public-private key pair */ + int (*check_pair_func)( const void *pub, const void *prv ); + + /** Allocate a new context */ + void * (*ctx_alloc_func)( void ); + + /** Free the given context */ + void (*ctx_free_func)( void *ctx ); + + /** Interface with the debug module */ + void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); + + /** Signature size */ + size_t (*signature_size_func)( const void *ctx ); +}; + +#endif /* MBEDTLS_PK_INFO_H */ diff --git a/include/mbedtls/pk_internal.h b/include/mbedtls/pk_internal.h index 4823294e8..06475e948 100644 --- a/include/mbedtls/pk_internal.h +++ b/include/mbedtls/pk_internal.h @@ -1,9 +1,9 @@ /** - * \file pk.h + * \file pk_internal.h * - * \brief Public Key cryptography abstraction layer: wrapper functions + * \brief Public Key cryptography abstraction layer: built-in key types * - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * Copyright (C) 2006-2017, ARM Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -21,8 +21,8 @@ * This file is part of mbed TLS (https://tls.mbed.org) */ -#ifndef MBEDTLS_PK_WRAP_H -#define MBEDTLS_PK_WRAP_H +#ifndef MBEDTLS_PK_INTERNAL_H +#define MBEDTLS_PK_INTERNAL_H #if !defined(MBEDTLS_CONFIG_FILE) #include "config.h" @@ -32,60 +32,6 @@ #include "pk.h" -struct mbedtls_pk_info_t -{ - /** Key pair type with indication of supported algorithms */ - mbedtls_pk_type_t type; - - /** Type name */ - const char *name; - - /** Get key size in bits */ - size_t (*get_bitlen)( const void *ctx ); - - /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */ - int (*can_do)( const void * ctx, mbedtls_pk_type_t type ); - - /** Verify signature */ - int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len ); - - /** Make signature */ - int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); - - /** Decrypt message */ - int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); - - /** Encrypt message */ - int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); - - /** Check public-private key pair */ - int (*check_pair_func)( const void *pub, const void *prv ); - - /** Allocate a new context */ - void * (*ctx_alloc_func)( void ); - - /** Free the given context */ - void (*ctx_free_func)( void *ctx ); - - /** Interface with the debug module */ - void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); - - /** Signature size */ - size_t (*signature_size_func)( const void *ctx ); -}; - #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) /* Container for RSA-alt */ typedef struct @@ -114,4 +60,4 @@ extern const mbedtls_pk_info_t mbedtls_ecdsa_info; extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; #endif -#endif /* MBEDTLS_PK_WRAP_H */ +#endif /* MBEDTLS_PK_INTERNAL_H */ diff --git a/library/pk.c b/library/pk.c index b48f4d90c..d080c7599 100644 --- a/library/pk.c +++ b/library/pk.c @@ -28,6 +28,7 @@ #if defined(MBEDTLS_PK_C) #include "mbedtls/pk.h" #include "mbedtls/pk_internal.h" +#include "mbedtls/pk_info.h" #if defined(MBEDTLS_RSA_C) #include "mbedtls/rsa.h" diff --git a/library/pk_wrap.c b/library/pk_wrap.c index 0d8aee1fc..dafd7a469 100644 --- a/library/pk_wrap.c +++ b/library/pk_wrap.c @@ -26,6 +26,7 @@ #endif #if defined(MBEDTLS_PK_C) +#include "mbedtls/pk_info.h" #include "mbedtls/pk_internal.h" /* Even if RSA not activated, for the sake of RSA-alt */ diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index f13f83cc1..1a55eaaa3 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -191,6 +191,7 @@ +