1*cfb92d14SAndroid Build Coastguard Worker /* 2*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 2018, The OpenThread Authors. 3*cfb92d14SAndroid Build Coastguard Worker * All rights reserved. 4*cfb92d14SAndroid Build Coastguard Worker * 5*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 7*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 8*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 9*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 10*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 11*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 12*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the 13*cfb92d14SAndroid Build Coastguard Worker * names of its contributors may be used to endorse or promote products 14*cfb92d14SAndroid Build Coastguard Worker * derived from this software without specific prior written permission. 15*cfb92d14SAndroid Build Coastguard Worker * 16*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17*cfb92d14SAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18*cfb92d14SAndroid Build Coastguard Worker * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19*cfb92d14SAndroid Build Coastguard Worker * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20*cfb92d14SAndroid Build Coastguard Worker * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21*cfb92d14SAndroid Build Coastguard Worker * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22*cfb92d14SAndroid Build Coastguard Worker * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23*cfb92d14SAndroid Build Coastguard Worker * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*cfb92d14SAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25*cfb92d14SAndroid Build Coastguard Worker * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*cfb92d14SAndroid Build Coastguard Worker */ 27*cfb92d14SAndroid Build Coastguard Worker 28*cfb92d14SAndroid Build Coastguard Worker /** 29*cfb92d14SAndroid Build Coastguard Worker * Allows to encrypt spinel frames sent between Application Processor (AP) and Network Co-Processor (NCP). 30*cfb92d14SAndroid Build Coastguard Worker */ 31*cfb92d14SAndroid Build Coastguard Worker 32*cfb92d14SAndroid Build Coastguard Worker namespace SpinelEncrypter { 33*cfb92d14SAndroid Build Coastguard Worker 34*cfb92d14SAndroid Build Coastguard Worker /** 35*cfb92d14SAndroid Build Coastguard Worker * Encrypts spinel frames before sending to AP/NCP. 36*cfb92d14SAndroid Build Coastguard Worker * 37*cfb92d14SAndroid Build Coastguard Worker * Encrypts outbound frames in both directions, i.e. from AP to NCP and from NCP to AP. 38*cfb92d14SAndroid Build Coastguard Worker * 39*cfb92d14SAndroid Build Coastguard Worker * @param[in,out] aFrameBuf Pointer to buffer containing the frame, also where the encrypted frame will be placed. 40*cfb92d14SAndroid Build Coastguard Worker * @param[in] aFrameSize Max number of bytes in frame buffer (max length of spinel frame + additional data for 41*cfb92d14SAndroid Build Coastguard Worker * encryption). 42*cfb92d14SAndroid Build Coastguard Worker * @param[in,out] aFrameLength Pointer to store frame length, on input value is set to frame length, 43*cfb92d14SAndroid Build Coastguard Worker * on output changed to show the frame length after encryption. 44*cfb92d14SAndroid Build Coastguard Worker * @return \c true on success, \c false otherwise. 45*cfb92d14SAndroid Build Coastguard Worker */ 46*cfb92d14SAndroid Build Coastguard Worker bool EncryptOutbound(unsigned char *aFrameBuf, size_t aFrameSize, size_t *aFrameLength); 47*cfb92d14SAndroid Build Coastguard Worker 48*cfb92d14SAndroid Build Coastguard Worker /** 49*cfb92d14SAndroid Build Coastguard Worker * Decrypts spinel frames received from AP/NCP. 50*cfb92d14SAndroid Build Coastguard Worker * 51*cfb92d14SAndroid Build Coastguard Worker * Decrypts inbound frames in both directions, i.e. from AP to NCP and from NCP to AP. 52*cfb92d14SAndroid Build Coastguard Worker * 53*cfb92d14SAndroid Build Coastguard Worker * @param[in,out] aFrameBuf Pointer to buffer containing encrypted frame, also where the decrypted frame will be placed. 54*cfb92d14SAndroid Build Coastguard Worker * @param[in] aFrameSize Max number of bytes in frame buffer (max length of spinel frame + additional data for 55*cfb92d14SAndroid Build Coastguard Worker * encryption). 56*cfb92d14SAndroid Build Coastguard Worker * @param[in,out] aFrameLength Pointer to store frame length, on input value is set to encrypted frame length, 57*cfb92d14SAndroid Build Coastguard Worker * on output changed to show the frame length after decryption. 58*cfb92d14SAndroid Build Coastguard Worker * @return \c true on success, \c false otherwise. 59*cfb92d14SAndroid Build Coastguard Worker */ 60*cfb92d14SAndroid Build Coastguard Worker bool DecryptInbound(unsigned char *aFrameBuf, size_t aFrameSize, size_t *aFrameLength); 61*cfb92d14SAndroid Build Coastguard Worker 62*cfb92d14SAndroid Build Coastguard Worker } // namespace SpinelEncrypter 63