Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cipher_internal.h Source File

cipher_internal.h

Go to the documentation of this file.
00001 /**
00002  * \file cipher_internal.h
00003  *
00004  * \brief Cipher wrappers.
00005  *
00006  * \author Adriaan de Jong <dejong@fox-it.com>
00007  */
00008 /*
00009  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00010  *  SPDX-License-Identifier: Apache-2.0
00011  *
00012  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00013  *  not use this file except in compliance with the License.
00014  *  You may obtain a copy of the License at
00015  *
00016  *  http://www.apache.org/licenses/LICENSE-2.0
00017  *
00018  *  Unless required by applicable law or agreed to in writing, software
00019  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00020  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  *  See the License for the specific language governing permissions and
00022  *  limitations under the License.
00023  *
00024  *  This file is part of mbed TLS (https://tls.mbed.org)
00025  */
00026 #ifndef MBEDTLS_CIPHER_WRAP_H
00027 #define MBEDTLS_CIPHER_WRAP_H
00028 
00029 #if !defined(MBEDTLS_CONFIG_FILE)
00030 #include "mbedtls/config.h"
00031 #else
00032 #include MBEDTLS_CONFIG_FILE
00033 #endif
00034 
00035 #include "mbedtls/cipher.h"
00036 
00037 #if defined(MBEDTLS_USE_PSA_CRYPTO)
00038 #include "psa/crypto.h"
00039 #endif /* MBEDTLS_USE_PSA_CRYPTO */
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 /**
00046  * Base cipher information. The non-mode specific functions and values.
00047  */
00048 struct mbedtls_cipher_base_t
00049 {
00050     /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
00051     mbedtls_cipher_id_t cipher;
00052 
00053     /** Encrypt using ECB */
00054     int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
00055                      const unsigned char *input, unsigned char *output );
00056 
00057 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00058     /** Encrypt using CBC */
00059     int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
00060                      unsigned char *iv, const unsigned char *input,
00061                      unsigned char *output );
00062 #endif
00063 
00064 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00065     /** Encrypt using CFB (Full length) */
00066     int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
00067                      unsigned char *iv, const unsigned char *input,
00068                      unsigned char *output );
00069 #endif
00070 
00071 #if defined(MBEDTLS_CIPHER_MODE_OFB)
00072     /** Encrypt using OFB (Full length) */
00073     int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
00074                      unsigned char *iv,
00075                      const unsigned char *input,
00076                      unsigned char *output );
00077 #endif
00078 
00079 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00080     /** Encrypt using CTR */
00081     int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
00082                      unsigned char *nonce_counter, unsigned char *stream_block,
00083                      const unsigned char *input, unsigned char *output );
00084 #endif
00085 
00086 #if defined(MBEDTLS_CIPHER_MODE_XTS)
00087     /** Encrypt or decrypt using XTS. */
00088     int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
00089                      const unsigned char data_unit[16],
00090                      const unsigned char *input, unsigned char *output );
00091 #endif
00092 
00093 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
00094     /** Encrypt using STREAM */
00095     int (*stream_func)( void *ctx, size_t length,
00096                         const unsigned char *input, unsigned char *output );
00097 #endif
00098 
00099     /** Set key for encryption purposes */
00100     int (*setkey_enc_func)( void *ctx, const unsigned char *key,
00101                             unsigned int key_bitlen );
00102 
00103     /** Set key for decryption purposes */
00104     int (*setkey_dec_func)( void *ctx, const unsigned char *key,
00105                             unsigned int key_bitlen);
00106 
00107     /** Allocate a new context */
00108     void * (*ctx_alloc_func)( void );
00109 
00110     /** Free the given context */
00111     void (*ctx_free_func)( void *ctx );
00112 
00113 };
00114 
00115 typedef struct
00116 {
00117     mbedtls_cipher_type_t type;
00118     const mbedtls_cipher_info_t *info;
00119 } mbedtls_cipher_definition_t;
00120 
00121 #if defined(MBEDTLS_USE_PSA_CRYPTO)
00122 typedef enum
00123 {
00124     MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
00125     MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
00126                                   /* use raw key material internally imported */
00127                                   /* as a volatile key, and which hence need  */
00128                                   /* to destroy that key when the context is  */
00129                                   /* freed.                                   */
00130     MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts   */
00131                                       /* which use a key provided by the      */
00132                                       /* user, and which hence will not be    */
00133                                       /* destroyed when the context is freed. */
00134 } mbedtls_cipher_psa_key_ownership;
00135 
00136 typedef struct
00137 {
00138     psa_algorithm_t alg;
00139     psa_key_handle_t slot;
00140     mbedtls_cipher_psa_key_ownership slot_state;
00141 } mbedtls_cipher_context_psa;
00142 #endif /* MBEDTLS_USE_PSA_CRYPTO */
00143 
00144 extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
00145 
00146 extern int mbedtls_cipher_supported[];
00147 
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151 
00152 #endif /* MBEDTLS_CIPHER_WRAP_H */