1 /* 2 * Copyright 2018 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #include "fsl_common.h" 10 #include "fsl_component_scrambler.h" 11 12 /******************************************************************************* 13 * Code 14 ******************************************************************************/ 15 SCRAMBLER_Whiten(whitener_config_t * whitenerConfig,uint8_t * pBuff,uint32_t buffLength)16void SCRAMBLER_Whiten(whitener_config_t *whitenerConfig, uint8_t *pBuff, uint32_t buffLength) 17 { 18 uint32_t initialState = ((uint32_t)whitenerConfig->whitenInitValue << (32U - whitenerConfig->whitenSize)); 19 uint32_t polyValue = ((uint32_t)whitenerConfig->whitenPolyValue << (32U - whitenerConfig->whitenSize)); 20 uint32_t currentValue = 0U; 21 22 for (uint32_t i = 0U; i < buffLength; i++) 23 { 24 currentValue = pBuff[i]; 25 26 if (whitenerConfig->type == kSCRAMBLER_GaloisPolyType) 27 { 28 for (uint8_t j = 0; j < 8U; j++) 29 { 30 if (0U != (initialState & 0x80000000U)) 31 { 32 initialState = (initialState << 1U); 33 initialState ^= polyValue; 34 35 if (whitenerConfig->whitenRefIn == kSCRAMBLER_WhitenRefInput) 36 { 37 currentValue = currentValue ^ (0x80UL >> j); 38 } 39 else 40 { 41 currentValue = currentValue ^ (0x1UL << j); 42 } 43 } 44 else 45 { 46 initialState = initialState << 1U; 47 } 48 } 49 } 50 51 pBuff[i] = (uint8_t)currentValue; 52 } 53 } 54