11182cb7eSMatthias Ringwald /*
21182cb7eSMatthias Ringwald * Copyright (C) 2015 BlueKitchen GmbH
31182cb7eSMatthias Ringwald *
41182cb7eSMatthias Ringwald * Redistribution and use in source and binary forms, with or without
51182cb7eSMatthias Ringwald * modification, are permitted provided that the following conditions
61182cb7eSMatthias Ringwald * are met:
71182cb7eSMatthias Ringwald *
81182cb7eSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright
91182cb7eSMatthias Ringwald * notice, this list of conditions and the following disclaimer.
101182cb7eSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright
111182cb7eSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the
121182cb7eSMatthias Ringwald * documentation and/or other materials provided with the distribution.
131182cb7eSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of
141182cb7eSMatthias Ringwald * contributors may be used to endorse or promote products derived
151182cb7eSMatthias Ringwald * from this software without specific prior written permission.
161182cb7eSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for
171182cb7eSMatthias Ringwald * personal benefit and not for any commercial purpose or for
181182cb7eSMatthias Ringwald * monetary gain.
191182cb7eSMatthias Ringwald *
201182cb7eSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
211182cb7eSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221182cb7eSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
251182cb7eSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
261182cb7eSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
271182cb7eSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
281182cb7eSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
291182cb7eSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
301182cb7eSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311182cb7eSMatthias Ringwald * SUCH DAMAGE.
321182cb7eSMatthias Ringwald *
331182cb7eSMatthias Ringwald * Please inquire about commercial licensing options at
341182cb7eSMatthias Ringwald * [email protected]
351182cb7eSMatthias Ringwald *
361182cb7eSMatthias Ringwald */
371182cb7eSMatthias Ringwald
38*bc6a318fSMatthias Ringwald #define BTSTACK_FILE__ "main.c"
391182cb7eSMatthias Ringwald
401182cb7eSMatthias Ringwald #ifndef WICED_HAVE_MBEDTLS
411182cb7eSMatthias Ringwald
421182cb7eSMatthias Ringwald // pre 5.2
431182cb7eSMatthias Ringwald #include "wiced_security.h"
441182cb7eSMatthias Ringwald
451182cb7eSMatthias Ringwald static aes_context_t wiced_aes128_context;
461182cb7eSMatthias Ringwald
471182cb7eSMatthias Ringwald void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result);
btstack_aes128_calc(uint8_t * key,uint8_t * plaintext,uint8_t * result)481182cb7eSMatthias Ringwald void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result){
491182cb7eSMatthias Ringwald aes_setkey_enc(&wiced_aes128_context, key, 128);
501182cb7eSMatthias Ringwald aes_crypt_ecb(&wiced_aes128_context, AES_ENCRYPT , plaintext, result);
511182cb7eSMatthias Ringwald }
521182cb7eSMatthias Ringwald
531182cb7eSMatthias Ringwald #else
541182cb7eSMatthias Ringwald
551182cb7eSMatthias Ringwald // 5.2+
561182cb7eSMatthias Ringwald #include <string.h>
571182cb7eSMatthias Ringwald #include "mbedtls/aes.h"
581182cb7eSMatthias Ringwald
591182cb7eSMatthias Ringwald static aes_context_t wiced_aes128_context;
601182cb7eSMatthias Ringwald
611182cb7eSMatthias Ringwald void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result);
btstack_aes128_calc(uint8_t * key,uint8_t * plaintext,uint8_t * result)621182cb7eSMatthias Ringwald void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result){
631182cb7eSMatthias Ringwald memset(&wiced_aes128_context, 0, sizeof(aes_context_t));
641182cb7eSMatthias Ringwald mbedtls_aes_setkey_enc(&wiced_aes128_context, key, 128);
651182cb7eSMatthias Ringwald mbedtls_aes_crypt_ecb(&wiced_aes128_context, AES_ENCRYPT, plaintext, result);
661182cb7eSMatthias Ringwald }
671182cb7eSMatthias Ringwald
681182cb7eSMatthias Ringwald #endif
691182cb7eSMatthias Ringwald
701182cb7eSMatthias Ringwald
71