Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pk_internal.h Source File

pk_internal.h

Go to the documentation of this file.
00001 /**
00002  * \file pk_internal.h
00003  *
00004  * \brief Public Key abstraction layer: wrapper functions
00005  */
00006 /*
00007  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00008  *  SPDX-License-Identifier: Apache-2.0
00009  *
00010  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00011  *  not use this file except in compliance with the License.
00012  *  You may obtain a copy of the License at
00013  *
00014  *  http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  *  Unless required by applicable law or agreed to in writing, software
00017  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00018  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  *  See the License for the specific language governing permissions and
00020  *  limitations under the License.
00021  *
00022  *  This file is part of mbed TLS (https://tls.mbed.org)
00023  */
00024 
00025 #ifndef MBEDTLS_PK_WRAP_H
00026 #define MBEDTLS_PK_WRAP_H
00027 
00028 #if !defined(MBEDTLS_CONFIG_FILE)
00029 #include "config.h"
00030 #else
00031 #include MBEDTLS_CONFIG_FILE
00032 #endif
00033 
00034 #include "pk.h"
00035 
00036 struct mbedtls_pk_info_t
00037 {
00038     /** Public key type */
00039     mbedtls_pk_type_t type;
00040 
00041     /** Type name */
00042     const char *name;
00043 
00044     /** Get key size in bits */
00045     size_t (*get_bitlen)( const void * );
00046 
00047     /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
00048     int (*can_do)( mbedtls_pk_type_t type );
00049 
00050     /** Verify signature */
00051     int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
00052                         const unsigned char *hash, size_t hash_len,
00053                         const unsigned char *sig, size_t sig_len );
00054 
00055     /** Make signature */
00056     int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
00057                       const unsigned char *hash, size_t hash_len,
00058                       unsigned char *sig, size_t *sig_len,
00059                       int (*f_rng)(void *, unsigned char *, size_t),
00060                       void *p_rng );
00061 
00062     /** Decrypt message */
00063     int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
00064                          unsigned char *output, size_t *olen, size_t osize,
00065                          int (*f_rng)(void *, unsigned char *, size_t),
00066                          void *p_rng );
00067 
00068     /** Encrypt message */
00069     int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
00070                          unsigned char *output, size_t *olen, size_t osize,
00071                          int (*f_rng)(void *, unsigned char *, size_t),
00072                          void *p_rng );
00073 
00074     /** Check public-private key pair */
00075     int (*check_pair_func)( const void *pub, const void *prv );
00076 
00077     /** Allocate a new context */
00078     void * (*ctx_alloc_func)( void );
00079 
00080     /** Free the given context */
00081     void (*ctx_free_func)( void *ctx );
00082 
00083     /** Interface with the debug module */
00084     void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
00085 
00086 };
00087 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
00088 /* Container for RSA-alt */
00089 typedef struct
00090 {
00091     void *key;
00092     mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
00093     mbedtls_pk_rsa_alt_sign_func sign_func;
00094     mbedtls_pk_rsa_alt_key_len_func key_len_func;
00095 } mbedtls_rsa_alt_context;
00096 #endif
00097 
00098 #if defined(MBEDTLS_RSA_C)
00099 extern const mbedtls_pk_info_t mbedtls_rsa_info;
00100 #endif
00101 
00102 #if defined(MBEDTLS_ECP_C)
00103 extern const mbedtls_pk_info_t mbedtls_eckey_info;
00104 extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
00105 #endif
00106 
00107 #if defined(MBEDTLS_ECDSA_C)
00108 extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
00109 #endif
00110 
00111 #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
00112 extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
00113 #endif
00114 
00115 #endif /* MBEDTLS_PK_WRAP_H */