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.
This commit is contained in:
Gilles Peskine 2017-11-03 11:58:25 +01:00 committed by Andrzej Kurek
parent cd062d84d6
commit 5cc7bc596d
5 changed files with 98 additions and 60 deletions

89
include/mbedtls/pk_info.h Normal file
View file

@ -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 */

View file

@ -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 */

View file

@ -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"

View file

@ -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 */

View file

@ -191,6 +191,7 @@
<ClInclude Include="..\..\include\mbedtls\padlock.h" />
<ClInclude Include="..\..\include\mbedtls\pem.h" />
<ClInclude Include="..\..\include\mbedtls\pk.h" />
<ClInclude Include="..\..\include\mbedtls\pk_info.h" />
<ClInclude Include="..\..\include\mbedtls\pk_internal.h" />
<ClInclude Include="..\..\include\mbedtls\pkcs11.h" />
<ClInclude Include="..\..\include\mbedtls\pkcs12.h" />