Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file pk_internal.h
  3.  *
  4.  * \brief Public Key abstraction layer: wrapper functions
  5.  */
  6. /*
  7.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8.  *  SPDX-License-Identifier: GPL-2.0
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License along
  21.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  22.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23.  *
  24.  *  This file is part of mbed TLS (https://tls.mbed.org)
  25.  */
  26.  
  27. #ifndef MBEDTLS_PK_WRAP_H
  28. #define MBEDTLS_PK_WRAP_H
  29.  
  30. #if !defined(MBEDTLS_CONFIG_FILE)
  31. #include "config.h"
  32. #else
  33. #include MBEDTLS_CONFIG_FILE
  34. #endif
  35.  
  36. #include "pk.h"
  37.  
  38. struct mbedtls_pk_info_t
  39. {
  40.     /** Public key type */
  41.     mbedtls_pk_type_t type;
  42.  
  43.     /** Type name */
  44.     const char *name;
  45.  
  46.     /** Get key size in bits */
  47.     size_t (*get_bitlen)( const void * );
  48.  
  49.     /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
  50.     int (*can_do)( mbedtls_pk_type_t type );
  51.  
  52.     /** Verify signature */
  53.     int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
  54.                         const unsigned char *hash, size_t hash_len,
  55.                         const unsigned char *sig, size_t sig_len );
  56.  
  57.     /** Make signature */
  58.     int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
  59.                       const unsigned char *hash, size_t hash_len,
  60.                       unsigned char *sig, size_t *sig_len,
  61.                       int (*f_rng)(void *, unsigned char *, size_t),
  62.                       void *p_rng );
  63.  
  64. #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
  65.     /** Verify signature (restartable) */
  66.     int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
  67.                            const unsigned char *hash, size_t hash_len,
  68.                            const unsigned char *sig, size_t sig_len,
  69.                            void *rs_ctx );
  70.  
  71.     /** Make signature (restartable) */
  72.     int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg,
  73.                          const unsigned char *hash, size_t hash_len,
  74.                          unsigned char *sig, size_t *sig_len,
  75.                          int (*f_rng)(void *, unsigned char *, size_t),
  76.                          void *p_rng, void *rs_ctx );
  77. #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
  78.  
  79.     /** Decrypt message */
  80.     int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
  81.                          unsigned char *output, size_t *olen, size_t osize,
  82.                          int (*f_rng)(void *, unsigned char *, size_t),
  83.                          void *p_rng );
  84.  
  85.     /** Encrypt message */
  86.     int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
  87.                          unsigned char *output, size_t *olen, size_t osize,
  88.                          int (*f_rng)(void *, unsigned char *, size_t),
  89.                          void *p_rng );
  90.  
  91.     /** Check public-private key pair */
  92.     int (*check_pair_func)( const void *pub, const void *prv );
  93.  
  94.     /** Allocate a new context */
  95.     void * (*ctx_alloc_func)( void );
  96.  
  97.     /** Free the given context */
  98.     void (*ctx_free_func)( void *ctx );
  99.  
  100. #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
  101.     /** Allocate the restart context */
  102.     void * (*rs_alloc_func)( void );
  103.  
  104.     /** Free the restart context */
  105.     void (*rs_free_func)( void *rs_ctx );
  106. #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
  107.  
  108.     /** Interface with the debug module */
  109.     void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
  110.  
  111. };
  112. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  113. /* Container for RSA-alt */
  114. typedef struct
  115. {
  116.     void *key;
  117.     mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
  118.     mbedtls_pk_rsa_alt_sign_func sign_func;
  119.     mbedtls_pk_rsa_alt_key_len_func key_len_func;
  120. } mbedtls_rsa_alt_context;
  121. #endif
  122.  
  123. #if defined(MBEDTLS_RSA_C)
  124. extern const mbedtls_pk_info_t mbedtls_rsa_info;
  125. #endif
  126.  
  127. #if defined(MBEDTLS_ECP_C)
  128. extern const mbedtls_pk_info_t mbedtls_eckey_info;
  129. extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
  130. #endif
  131.  
  132. #if defined(MBEDTLS_ECDSA_C)
  133. extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
  134. #endif
  135.  
  136. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  137. extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
  138. #endif
  139.  
  140. #endif /* MBEDTLS_PK_WRAP_H */
  141.