takashi kadono / Mbed OS Nucleo446_SSD1331

Dependencies:   ssd1331

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 "config.h"
00031 #else
00032 #include MBEDTLS_CONFIG_FILE
00033 #endif
00034 
00035 #include "cipher.h"
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 /**
00042  * Base cipher information. The non-mode specific functions and values.
00043  */
00044 struct mbedtls_cipher_base_t
00045 {
00046     /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
00047     mbedtls_cipher_id_t cipher;
00048 
00049     /** Encrypt using ECB */
00050     int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
00051                      const unsigned char *input, unsigned char *output );
00052 
00053 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00054     /** Encrypt using CBC */
00055     int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
00056                      unsigned char *iv, const unsigned char *input,
00057                      unsigned char *output );
00058 #endif
00059 
00060 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00061     /** Encrypt using CFB (Full length) */
00062     int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
00063                      unsigned char *iv, const unsigned char *input,
00064                      unsigned char *output );
00065 #endif
00066 
00067 #if defined(MBEDTLS_CIPHER_MODE_OFB)
00068     /** Encrypt using OFB (Full length) */
00069     int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
00070                      unsigned char *iv,
00071                      const unsigned char *input,
00072                      unsigned char *output );
00073 #endif
00074 
00075 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00076     /** Encrypt using CTR */
00077     int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
00078                      unsigned char *nonce_counter, unsigned char *stream_block,
00079                      const unsigned char *input, unsigned char *output );
00080 #endif
00081 
00082 #if defined(MBEDTLS_CIPHER_MODE_XTS)
00083     /** Encrypt or decrypt using XTS. */
00084     int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
00085                      const unsigned char data_unit[16],
00086                      const unsigned char *input, unsigned char *output );
00087 #endif
00088 
00089 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
00090     /** Encrypt using STREAM */
00091     int (*stream_func)( void *ctx, size_t length,
00092                         const unsigned char *input, unsigned char *output );
00093 #endif
00094 
00095     /** Set key for encryption purposes */
00096     int (*setkey_enc_func)( void *ctx, const unsigned char *key,
00097                             unsigned int key_bitlen );
00098 
00099     /** Set key for decryption purposes */
00100     int (*setkey_dec_func)( void *ctx, const unsigned char *key,
00101                             unsigned int key_bitlen);
00102 
00103     /** Allocate a new context */
00104     void * (*ctx_alloc_func)( void );
00105 
00106     /** Free the given context */
00107     void (*ctx_free_func)( void *ctx );
00108 
00109 };
00110 
00111 typedef struct
00112 {
00113     mbedtls_cipher_type_t type;
00114     const mbedtls_cipher_info_t *info;
00115 } mbedtls_cipher_definition_t;
00116 
00117 extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
00118 
00119 extern int mbedtls_cipher_supported[];
00120 
00121 #ifdef __cplusplus
00122 }
00123 #endif
00124 
00125 #endif /* MBEDTLS_CIPHER_WRAP_H */