mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file ccm.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief Counter with CBC-MAC (CCM) for 128-bit block ciphers
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_CCM_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_CCM_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #include "cipher.h"
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to function. */
mbedAustin 11:cada08fc8a70 29 #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */
mbedAustin 11:cada08fc8a70 30
mbedAustin 11:cada08fc8a70 31 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 32 extern "C" {
mbedAustin 11:cada08fc8a70 33 #endif
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 /**
mbedAustin 11:cada08fc8a70 36 * \brief CCM context structure
mbedAustin 11:cada08fc8a70 37 */
mbedAustin 11:cada08fc8a70 38 typedef struct {
mbedAustin 11:cada08fc8a70 39 mbedtls_cipher_context_t cipher_ctx; /*!< cipher context used */
mbedAustin 11:cada08fc8a70 40 }
mbedAustin 11:cada08fc8a70 41 mbedtls_ccm_context;
mbedAustin 11:cada08fc8a70 42
mbedAustin 11:cada08fc8a70 43 /**
mbedAustin 11:cada08fc8a70 44 * \brief Initialize CCM context (just makes references valid)
mbedAustin 11:cada08fc8a70 45 * Makes the context ready for mbedtls_ccm_setkey() or
mbedAustin 11:cada08fc8a70 46 * mbedtls_ccm_free().
mbedAustin 11:cada08fc8a70 47 *
mbedAustin 11:cada08fc8a70 48 * \param ctx CCM context to initialize
mbedAustin 11:cada08fc8a70 49 */
mbedAustin 11:cada08fc8a70 50 void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
mbedAustin 11:cada08fc8a70 51
mbedAustin 11:cada08fc8a70 52 /**
mbedAustin 11:cada08fc8a70 53 * \brief CCM initialization (encryption and decryption)
mbedAustin 11:cada08fc8a70 54 *
mbedAustin 11:cada08fc8a70 55 * \param ctx CCM context to be initialized
mbedAustin 11:cada08fc8a70 56 * \param cipher cipher to use (a 128-bit block cipher)
mbedAustin 11:cada08fc8a70 57 * \param key encryption key
mbedAustin 11:cada08fc8a70 58 * \param keybits key size in bits (must be acceptable by the cipher)
mbedAustin 11:cada08fc8a70 59 *
mbedAustin 11:cada08fc8a70 60 * \return 0 if successful, or a cipher specific error code
mbedAustin 11:cada08fc8a70 61 */
mbedAustin 11:cada08fc8a70 62 int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
mbedAustin 11:cada08fc8a70 63 mbedtls_cipher_id_t cipher,
mbedAustin 11:cada08fc8a70 64 const unsigned char *key,
mbedAustin 11:cada08fc8a70 65 unsigned int keybits );
mbedAustin 11:cada08fc8a70 66
mbedAustin 11:cada08fc8a70 67 /**
mbedAustin 11:cada08fc8a70 68 * \brief Free a CCM context and underlying cipher sub-context
mbedAustin 11:cada08fc8a70 69 *
mbedAustin 11:cada08fc8a70 70 * \param ctx CCM context to free
mbedAustin 11:cada08fc8a70 71 */
mbedAustin 11:cada08fc8a70 72 void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
mbedAustin 11:cada08fc8a70 73
mbedAustin 11:cada08fc8a70 74 /**
mbedAustin 11:cada08fc8a70 75 * \brief CCM buffer encryption
mbedAustin 11:cada08fc8a70 76 *
mbedAustin 11:cada08fc8a70 77 * \param ctx CCM context
mbedAustin 11:cada08fc8a70 78 * \param length length of the input data in bytes
mbedAustin 11:cada08fc8a70 79 * \param iv nonce (initialization vector)
mbedAustin 11:cada08fc8a70 80 * \param iv_len length of IV in bytes
mbedAustin 11:cada08fc8a70 81 * must be 2, 3, 4, 5, 6, 7 or 8
mbedAustin 11:cada08fc8a70 82 * \param add additional data
mbedAustin 11:cada08fc8a70 83 * \param add_len length of additional data in bytes
mbedAustin 11:cada08fc8a70 84 * must be less than 2^16 - 2^8
mbedAustin 11:cada08fc8a70 85 * \param input buffer holding the input data
mbedAustin 11:cada08fc8a70 86 * \param output buffer for holding the output data
mbedAustin 11:cada08fc8a70 87 * must be at least 'length' bytes wide
mbedAustin 11:cada08fc8a70 88 * \param tag buffer for holding the tag
mbedAustin 11:cada08fc8a70 89 * \param tag_len length of the tag to generate in bytes
mbedAustin 11:cada08fc8a70 90 * must be 4, 6, 8, 10, 14 or 16
mbedAustin 11:cada08fc8a70 91 *
mbedAustin 11:cada08fc8a70 92 * \note The tag is written to a separate buffer. To get the tag
mbedAustin 11:cada08fc8a70 93 * concatenated with the output as in the CCM spec, use
mbedAustin 11:cada08fc8a70 94 * tag = output + length and make sure the output buffer is
mbedAustin 11:cada08fc8a70 95 * at least length + tag_len wide.
mbedAustin 11:cada08fc8a70 96 *
mbedAustin 11:cada08fc8a70 97 * \return 0 if successful
mbedAustin 11:cada08fc8a70 98 */
mbedAustin 11:cada08fc8a70 99 int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
mbedAustin 11:cada08fc8a70 100 const unsigned char *iv, size_t iv_len,
mbedAustin 11:cada08fc8a70 101 const unsigned char *add, size_t add_len,
mbedAustin 11:cada08fc8a70 102 const unsigned char *input, unsigned char *output,
mbedAustin 11:cada08fc8a70 103 unsigned char *tag, size_t tag_len );
mbedAustin 11:cada08fc8a70 104
mbedAustin 11:cada08fc8a70 105 /**
mbedAustin 11:cada08fc8a70 106 * \brief CCM buffer authenticated decryption
mbedAustin 11:cada08fc8a70 107 *
mbedAustin 11:cada08fc8a70 108 * \param ctx CCM context
mbedAustin 11:cada08fc8a70 109 * \param length length of the input data
mbedAustin 11:cada08fc8a70 110 * \param iv initialization vector
mbedAustin 11:cada08fc8a70 111 * \param iv_len length of IV
mbedAustin 11:cada08fc8a70 112 * \param add additional data
mbedAustin 11:cada08fc8a70 113 * \param add_len length of additional data
mbedAustin 11:cada08fc8a70 114 * \param input buffer holding the input data
mbedAustin 11:cada08fc8a70 115 * \param output buffer for holding the output data
mbedAustin 11:cada08fc8a70 116 * \param tag buffer holding the tag
mbedAustin 11:cada08fc8a70 117 * \param tag_len length of the tag
mbedAustin 11:cada08fc8a70 118 *
mbedAustin 11:cada08fc8a70 119 * \return 0 if successful and authenticated,
mbedAustin 11:cada08fc8a70 120 * MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match
mbedAustin 11:cada08fc8a70 121 */
mbedAustin 11:cada08fc8a70 122 int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
mbedAustin 11:cada08fc8a70 123 const unsigned char *iv, size_t iv_len,
mbedAustin 11:cada08fc8a70 124 const unsigned char *add, size_t add_len,
mbedAustin 11:cada08fc8a70 125 const unsigned char *input, unsigned char *output,
mbedAustin 11:cada08fc8a70 126 const unsigned char *tag, size_t tag_len );
mbedAustin 11:cada08fc8a70 127
mbedAustin 11:cada08fc8a70 128 #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
mbedAustin 11:cada08fc8a70 129 /**
mbedAustin 11:cada08fc8a70 130 * \brief Checkup routine
mbedAustin 11:cada08fc8a70 131 *
mbedAustin 11:cada08fc8a70 132 * \return 0 if successful, or 1 if the test failed
mbedAustin 11:cada08fc8a70 133 */
mbedAustin 11:cada08fc8a70 134 int mbedtls_ccm_self_test( int verbose );
mbedAustin 11:cada08fc8a70 135 #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
mbedAustin 11:cada08fc8a70 136
mbedAustin 11:cada08fc8a70 137 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 138 }
mbedAustin 11:cada08fc8a70 139 #endif
mbedAustin 11:cada08fc8a70 140
mbedAustin 11:cada08fc8a70 141 #endif /* MBEDTLS_CCM_H */