A library implementing IEEE 802.15.4 PHY functionality for the MCR20A transceiver. The PHY sublayer provides two services: the PHY data service and the PHY management service interfacing to the PHY sublayer management entity (PLME) service access point (SAP) (known as PLME-SAP). The PHY data service enables the transmission and reception of PHY protocol data units (PSDUs) over the media (radio).

Fork of fsl_phy_mcr20a by Freescale

The Freescale PHY Layer deals with the physical burst which is to be sent and/or received. It performs modulation and demodulation, transmitter and receiver switching, fragmentation, scrambling, interleaving, and error correction coding. The communication to the upper protocol layers is carried out through the Layer 1 Interface.

The PHY Layer is capable of executing the following sequences:

  • I (Idle)
  • R (Receive Sequence conditionally followed by a TxAck)
  • T (Transmit Sequence)
  • C (Standalone CCA)
  • CCCA (Continuous CCA)
  • TR (Transmit/Receive Sequence - transmit unconditionally followed by either an R or RxAck)

In addition to these sequences the PHY Layer also integrates a packet processor which determines whether the packet is MAC-compliant, and if it is, whether it is addressed to the end device. Another feature of the packet processor is Source Address Matching which can be viewed as an extension of packet filtering; however its function is very specific to its intended application (data-polling and indirect queue management by a PAN Coordinator).

Documentation

MCR20A PHY Reference Manual

Committer:
andreikovacs
Date:
Tue Aug 18 12:41:42 2015 +0000
Revision:
0:764779eedf2d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andreikovacs 0:764779eedf2d 1 /*!
andreikovacs 0:764779eedf2d 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
andreikovacs 0:764779eedf2d 3 * All rights reserved.
andreikovacs 0:764779eedf2d 4 *
andreikovacs 0:764779eedf2d 5 * \file RNG.c
andreikovacs 0:764779eedf2d 6 * RNG implementation file for the ARM CORTEX-M4 processor
andreikovacs 0:764779eedf2d 7 *
andreikovacs 0:764779eedf2d 8 * Redistribution and use in source and binary forms, with or without modification,
andreikovacs 0:764779eedf2d 9 * are permitted provided that the following conditions are met:
andreikovacs 0:764779eedf2d 10 *
andreikovacs 0:764779eedf2d 11 * o Redistributions of source code must retain the above copyright notice, this list
andreikovacs 0:764779eedf2d 12 * of conditions and the following disclaimer.
andreikovacs 0:764779eedf2d 13 *
andreikovacs 0:764779eedf2d 14 * o Redistributions in binary form must reproduce the above copyright notice, this
andreikovacs 0:764779eedf2d 15 * list of conditions and the following disclaimer in the documentation and/or
andreikovacs 0:764779eedf2d 16 * other materials provided with the distribution.
andreikovacs 0:764779eedf2d 17 *
andreikovacs 0:764779eedf2d 18 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
andreikovacs 0:764779eedf2d 19 * contributors may be used to endorse or promote products derived from this
andreikovacs 0:764779eedf2d 20 * software without specific prior written permission.
andreikovacs 0:764779eedf2d 21 *
andreikovacs 0:764779eedf2d 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
andreikovacs 0:764779eedf2d 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
andreikovacs 0:764779eedf2d 24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
andreikovacs 0:764779eedf2d 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
andreikovacs 0:764779eedf2d 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
andreikovacs 0:764779eedf2d 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
andreikovacs 0:764779eedf2d 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
andreikovacs 0:764779eedf2d 29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
andreikovacs 0:764779eedf2d 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
andreikovacs 0:764779eedf2d 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
andreikovacs 0:764779eedf2d 32 */
andreikovacs 0:764779eedf2d 33
andreikovacs 0:764779eedf2d 34
andreikovacs 0:764779eedf2d 35 #include "RNG_Interface.h"
andreikovacs 0:764779eedf2d 36 #include "fsl_device_registers.h"
andreikovacs 0:764779eedf2d 37 #include "fsl_clock_manager.h"
andreikovacs 0:764779eedf2d 38 //#include "SecLib.h"
andreikovacs 0:764779eedf2d 39 #include "FunctionLib.h"
andreikovacs 0:764779eedf2d 40
andreikovacs 0:764779eedf2d 41 #if (gSecLib_HWSupport_d == gSecLib_MMCAUSupport_d)
andreikovacs 0:764779eedf2d 42 //#include "mmcau_interface.h"
andreikovacs 0:764779eedf2d 43 #endif
andreikovacs 0:764779eedf2d 44
andreikovacs 0:764779eedf2d 45 #ifndef gRNG_UsePhyRngForInitialSeed_d
andreikovacs 0:764779eedf2d 46 #define gRNG_UsePhyRngForInitialSeed_d 0
andreikovacs 0:764779eedf2d 47 #endif
andreikovacs 0:764779eedf2d 48
andreikovacs 0:764779eedf2d 49 #if (gRNG_HWSupport_d == gRNG_NoHWSupport_d)
andreikovacs 0:764779eedf2d 50 uint32_t mRandomNumber;
andreikovacs 0:764779eedf2d 51
andreikovacs 0:764779eedf2d 52 #if gRNG_UsePhyRngForInitialSeed_d
andreikovacs 0:764779eedf2d 53 extern void PhyGetRandomNo(uint32_t *pRandomNo);
andreikovacs 0:764779eedf2d 54 #endif
andreikovacs 0:764779eedf2d 55 #endif
andreikovacs 0:764779eedf2d 56
andreikovacs 0:764779eedf2d 57 /************************************************************************************
andreikovacs 0:764779eedf2d 58 *************************************************************************************
andreikovacs 0:764779eedf2d 59 * Private macros
andreikovacs 0:764779eedf2d 60 *************************************************************************************
andreikovacs 0:764779eedf2d 61 ************************************************************************************/
andreikovacs 0:764779eedf2d 62 #define mPRNG_NoOfBits_c (160)
andreikovacs 0:764779eedf2d 63 #define mPRNG_NoOfBytes_c (mPRNG_NoOfBits_c/8)
andreikovacs 0:764779eedf2d 64 #define mPRNG_NoOfLongWords_c (mPRNG_NoOfBits_c/32)
andreikovacs 0:764779eedf2d 65
andreikovacs 0:764779eedf2d 66 /************************************************************************************
andreikovacs 0:764779eedf2d 67 *************************************************************************************
andreikovacs 0:764779eedf2d 68 * Private memory declarations
andreikovacs 0:764779eedf2d 69 *************************************************************************************
andreikovacs 0:764779eedf2d 70 ************************************************************************************/
andreikovacs 0:764779eedf2d 71 static uint32_t XKEY[mPRNG_NoOfLongWords_c];
andreikovacs 0:764779eedf2d 72 static uint32_t mPRNG_Requests = gRngMaxRequests_d;
andreikovacs 0:764779eedf2d 73
andreikovacs 0:764779eedf2d 74 /************************************************************************************
andreikovacs 0:764779eedf2d 75 *************************************************************************************
andreikovacs 0:764779eedf2d 76 * Public functions
andreikovacs 0:764779eedf2d 77 *************************************************************************************
andreikovacs 0:764779eedf2d 78 ************************************************************************************/
andreikovacs 0:764779eedf2d 79
andreikovacs 0:764779eedf2d 80 /******************************************************************************
andreikovacs 0:764779eedf2d 81 * Name: RNG_Init()
andreikovacs 0:764779eedf2d 82 * Description: Initialize the RNG HW module
andreikovacs 0:764779eedf2d 83 * Parameter(s): -
andreikovacs 0:764779eedf2d 84 * Return: Status of the RNG module
andreikovacs 0:764779eedf2d 85 ******************************************************************************/
andreikovacs 0:764779eedf2d 86 uint8_t RNG_Init(void)
andreikovacs 0:764779eedf2d 87 {
andreikovacs 0:764779eedf2d 88 #if gRNG_HWSupport_d == gRNG_RNGAHWSupport_d
andreikovacs 0:764779eedf2d 89 CLOCK_SYS_EnableRngaClock(0);
andreikovacs 0:764779eedf2d 90 /* Mask Interrupts and start RNG */
andreikovacs 0:764779eedf2d 91 RNG_CR = RNG_CR_INTM_MASK | RNG_CR_HA_MASK | RNG_CR_GO_MASK;
andreikovacs 0:764779eedf2d 92
andreikovacs 0:764779eedf2d 93 #elif gRNG_HWSupport_d == gRNG_RNGBHWSupport_d
andreikovacs 0:764779eedf2d 94 CLOCK_SYS_EnableRngbClock(0);
andreikovacs 0:764779eedf2d 95 /* Execute a SW Reset */
andreikovacs 0:764779eedf2d 96 RNG_CMD |= RNG_CMD_SR_MASK;
andreikovacs 0:764779eedf2d 97
andreikovacs 0:764779eedf2d 98 /* Mask Interrupts */
andreikovacs 0:764779eedf2d 99 RNG_CR = RNG_CR_MASKDONE_MASK | RNG_CR_MASKERR_MASK;
andreikovacs 0:764779eedf2d 100
andreikovacs 0:764779eedf2d 101 /* Start Self Test and Seed Generation */
andreikovacs 0:764779eedf2d 102 RNG_CMD = RNG_CMD_ST_MASK | RNG_CMD_GS_MASK;
andreikovacs 0:764779eedf2d 103
andreikovacs 0:764779eedf2d 104 /* Wait for Self Test and Seed Generation to be done*/
andreikovacs 0:764779eedf2d 105 while (RNG_CMD & (RNG_CMD_ST_MASK | RNG_CMD_GS_MASK));
andreikovacs 0:764779eedf2d 106
andreikovacs 0:764779eedf2d 107 /* Enable RNG Auto-Reseed */
andreikovacs 0:764779eedf2d 108 RNG_CR |= RNG_CR_AR_MASK;
andreikovacs 0:764779eedf2d 109
andreikovacs 0:764779eedf2d 110 /* Check for Errors */
andreikovacs 0:764779eedf2d 111 if ( RNG_SR & RNG_SR_ERR_MASK )
andreikovacs 0:764779eedf2d 112 {
andreikovacs 0:764779eedf2d 113 return (uint8_t)(RNG_ESR);
andreikovacs 0:764779eedf2d 114 }
andreikovacs 0:764779eedf2d 115 #elif gRNG_HWSupport_d == gRNG_TRNGHWSupport_d
andreikovacs 0:764779eedf2d 116 // uint32_t temp;
andreikovacs 0:764779eedf2d 117 //
andreikovacs 0:764779eedf2d 118 // SIM_SCGC6 |= SIM_SCGC6_TRNG_MASK;
andreikovacs 0:764779eedf2d 119 //
andreikovacs 0:764779eedf2d 120 // /* Reset TRNG registers to default values */
andreikovacs 0:764779eedf2d 121 // HW_TRNG_RTMCTL_WR(gTRNG_BaseAddr_c, BM_TRNG_RTMCTL_RST_DEF | BM_TRNG_RTMCTL_PRGM);
andreikovacs 0:764779eedf2d 122 //
andreikovacs 0:764779eedf2d 123 // /* Enable Entropy Valid IRQ */
andreikovacs 0:764779eedf2d 124 // //disallow device to sleep, allow device to sleep in ISR
andreikovacs 0:764779eedf2d 125 // //HW_TRNG_SA_TRNG_INT_MASK_SET(gTRNG_BaseAddr_c, BM_TRNG_SA_TRNG_INT_MASK_SA_TRNG_SBS_ENTROPY_VALID);
andreikovacs 0:764779eedf2d 126 //
andreikovacs 0:764779eedf2d 127 // /* Set TRNG in Run mode, and enable entropy read access */
andreikovacs 0:764779eedf2d 128 // temp = HW_TRNG_RTMCTL_RD(gTRNG_BaseAddr_c);
andreikovacs 0:764779eedf2d 129 // temp &= ~(BM_TRNG_RTMCTL_PRGM | BM_TRNG_RTMCTL_ERR);
andreikovacs 0:764779eedf2d 130 // temp |= BM_TRNG_RTMCTL_TRNG_ACC;
andreikovacs 0:764779eedf2d 131 // HW_TRNG_RTMCTL_WR(gTRNG_BaseAddr_c, temp);
andreikovacs 0:764779eedf2d 132 #else
andreikovacs 0:764779eedf2d 133 #if gRNG_UsePhyRngForInitialSeed_d
andreikovacs 0:764779eedf2d 134 PhyGetRandomNo(&mRandomNumber);
andreikovacs 0:764779eedf2d 135 #else
andreikovacs 0:764779eedf2d 136 mRandomNumber = HW_SIM_UIDL_RD(SIM_BASE);
andreikovacs 0:764779eedf2d 137 #endif
andreikovacs 0:764779eedf2d 138 #endif /* gRNG_HwSupport_d == 1 */
andreikovacs 0:764779eedf2d 139
andreikovacs 0:764779eedf2d 140 /* Init Successfull */
andreikovacs 0:764779eedf2d 141 return gRngSuccess_d;
andreikovacs 0:764779eedf2d 142 }
andreikovacs 0:764779eedf2d 143
andreikovacs 0:764779eedf2d 144 /******************************************************************************
andreikovacs 0:764779eedf2d 145 * Name: RNG_HwGetRandomNo()
andreikovacs 0:764779eedf2d 146 * Description: Read a random number from the HW RNG module
andreikovacs 0:764779eedf2d 147 * Parameter(s): [OUT] pRandomNo - pointer to location where the RN will be stored
andreikovacs 0:764779eedf2d 148 * Return: status of the RNG module
andreikovacs 0:764779eedf2d 149 ******************************************************************************/
andreikovacs 0:764779eedf2d 150 #if (gRNG_HWSupport_d != gRNG_NoHWSupport_d)
andreikovacs 0:764779eedf2d 151 static uint8_t RNG_HwGetRandomNo(uint32_t* pRandomNo)
andreikovacs 0:764779eedf2d 152 {
andreikovacs 0:764779eedf2d 153 #if gRNG_HWSupport_d == gRNG_RNGAHWSupport_d
andreikovacs 0:764779eedf2d 154 /* If output register is empty, wait for a new random number */
andreikovacs 0:764779eedf2d 155 while ( ((RNG_SR & RNG_SR_OREG_LVL_MASK) >> RNG_SR_OREG_LVL_SHIFT) == 0 );
andreikovacs 0:764779eedf2d 156
andreikovacs 0:764779eedf2d 157 /* Copy the output of RNG module */
andreikovacs 0:764779eedf2d 158 *pRandomNo = RNG_OR;
andreikovacs 0:764779eedf2d 159
andreikovacs 0:764779eedf2d 160 #elif gRNG_HWSupport_d == gRNG_RNGBHWSupport_d
andreikovacs 0:764779eedf2d 161 /* Check for Errors */
andreikovacs 0:764779eedf2d 162 if ( RNG_SR & RNG_SR_ERR_MASK )
andreikovacs 0:764779eedf2d 163 return (uint8_t)(RNG_ESR);
andreikovacs 0:764779eedf2d 164
andreikovacs 0:764779eedf2d 165 /* If output FIFO is empty, wait for a new random number */
andreikovacs 0:764779eedf2d 166 while (((RNG_SR & RNG_SR_FIFO_LVL_MASK) >> RNG_SR_FIFO_LVL_SHIFT) == 0 );
andreikovacs 0:764779eedf2d 167
andreikovacs 0:764779eedf2d 168 /* Copy the output of RNG module */
andreikovacs 0:764779eedf2d 169 *pRandomNo = RNG_OUT;
andreikovacs 0:764779eedf2d 170
andreikovacs 0:764779eedf2d 171 #elif gRNG_HWSupport_d == gRNG_TRNGHWSupport_d
andreikovacs 0:764779eedf2d 172 static uint8_t entropyIdx = 0;
andreikovacs 0:764779eedf2d 173
andreikovacs 0:764779eedf2d 174 /* wait for entropy to be generated or for an error */
andreikovacs 0:764779eedf2d 175 while( !(HW_TRNG_RTMCTL_RD(gTRNG_BaseAddr_c) & (BM_TRNG_RTMCTL_ENT_VAL | BM_TRNG_RTMCTL_ERR)) );
andreikovacs 0:764779eedf2d 176
andreikovacs 0:764779eedf2d 177 if( HW_TRNG_RTMCTL_RD(gTRNG_BaseAddr_c) & BM_TRNG_RTMCTL_ERR )
andreikovacs 0:764779eedf2d 178 return gRngInternalError_d;
andreikovacs 0:764779eedf2d 179
andreikovacs 0:764779eedf2d 180 *pRandomNo = HW_TRNG_RTENTan_RD(gTRNG_BaseAddr_c, entropyIdx);
andreikovacs 0:764779eedf2d 181 if( ++entropyIdx == 16 )
andreikovacs 0:764779eedf2d 182 {
andreikovacs 0:764779eedf2d 183 entropyIdx = 0;
andreikovacs 0:764779eedf2d 184 //disallow device to sleep
andreikovacs 0:764779eedf2d 185 }
andreikovacs 0:764779eedf2d 186 #endif
andreikovacs 0:764779eedf2d 187
andreikovacs 0:764779eedf2d 188 return gRngSuccess_d;
andreikovacs 0:764779eedf2d 189 }
andreikovacs 0:764779eedf2d 190 #endif /* gRNG_HwSupport_d */
andreikovacs 0:764779eedf2d 191
andreikovacs 0:764779eedf2d 192
andreikovacs 0:764779eedf2d 193 /******************************************************************************
andreikovacs 0:764779eedf2d 194 * Name: RNG_GetRandomNo()
andreikovacs 0:764779eedf2d 195 * Description: Read a random number from RNG module or from 802.15.4 PHY
andreikovacs 0:764779eedf2d 196 * Parameter(s): [OUT] pRandomNo - pointer to location where the RN will be stored
andreikovacs 0:764779eedf2d 197 * Return: none
andreikovacs 0:764779eedf2d 198 ******************************************************************************/
andreikovacs 0:764779eedf2d 199 void RNG_GetRandomNo(uint32_t* pRandomNo)
andreikovacs 0:764779eedf2d 200 {
andreikovacs 0:764779eedf2d 201 /* Check for NULL pointers */
andreikovacs 0:764779eedf2d 202 if (NULL == pRandomNo)
andreikovacs 0:764779eedf2d 203 return;
andreikovacs 0:764779eedf2d 204
andreikovacs 0:764779eedf2d 205 #if (gRNG_HWSupport_d == gRNG_NoHWSupport_d)
andreikovacs 0:764779eedf2d 206 mRandomNumber = (mRandomNumber * 6075) + 1283;
andreikovacs 0:764779eedf2d 207 FLib_MemCpy(pRandomNo, &mRandomNumber, sizeof(uint32_t));
andreikovacs 0:764779eedf2d 208 #else
andreikovacs 0:764779eedf2d 209 (void)RNG_HwGetRandomNo(pRandomNo);
andreikovacs 0:764779eedf2d 210 #endif
andreikovacs 0:764779eedf2d 211 }
andreikovacs 0:764779eedf2d 212
andreikovacs 0:764779eedf2d 213 /******************************************************************************
andreikovacs 0:764779eedf2d 214 * Name: RNG_SetPseudoRandomNoSeed()
andreikovacs 0:764779eedf2d 215 * Description: Initialize seed for the PRNG algorithm.
andreikovacs 0:764779eedf2d 216 * Parameter(s):
andreikovacs 0:764779eedf2d 217 * pSeed - pointer to a buffer containing 20 bytes (160 bits).
andreikovacs 0:764779eedf2d 218 * Can be set using the RNG_GetRandomNo() function.
andreikovacs 0:764779eedf2d 219 * Return: None
andreikovacs 0:764779eedf2d 220 ******************************************************************************/
andreikovacs 0:764779eedf2d 221 void RNG_SetPseudoRandomNoSeed(uint8_t* pSeed)
andreikovacs 0:764779eedf2d 222 {
andreikovacs 0:764779eedf2d 223 mPRNG_Requests = 1;
andreikovacs 0:764779eedf2d 224 FLib_MemCpy( XKEY, pSeed, mPRNG_NoOfBytes_c );
andreikovacs 0:764779eedf2d 225 }
andreikovacs 0:764779eedf2d 226
andreikovacs 0:764779eedf2d 227 #if 0
andreikovacs 0:764779eedf2d 228 /******************************************************************************
andreikovacs 0:764779eedf2d 229 * Name: RNG_GetRandomNo()
andreikovacs 0:764779eedf2d 230 *
andreikovacs 0:764779eedf2d 231 * Description: Pseudo Random Number Generator (PRNG) implementation
andreikovacs 0:764779eedf2d 232 * according to NIST FIPS Publication 186-2, APPENDIX 3
andreikovacs 0:764779eedf2d 233 *
andreikovacs 0:764779eedf2d 234 * Let x be the signer's private key. The following may be used to generate m values of x:
andreikovacs 0:764779eedf2d 235 * Step 1. Choose a new, secret value for the seed-key, XKEY.
andreikovacs 0:764779eedf2d 236 * Step 2. In hexadecimal notation let
andreikovacs 0:764779eedf2d 237 * t = 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0.
andreikovacs 0:764779eedf2d 238 * This is the initial value for H0 || H1 || H2 || H3 || H4 in the SHS.
andreikovacs 0:764779eedf2d 239 * Step 3. For j = 0 to m - 1 do
andreikovacs 0:764779eedf2d 240 * a. XSEEDj = optional user input.
andreikovacs 0:764779eedf2d 241 * b. XVAL = (XKEY + XSEEDj) mod 2^b
andreikovacs 0:764779eedf2d 242 * c. xj = G(t,XVAL) mod q
andreikovacs 0:764779eedf2d 243 * d. XKEY = (1 + XKEY + xj) mod 2^b
andreikovacs 0:764779eedf2d 244 *
andreikovacs 0:764779eedf2d 245 * Parameter(s):
andreikovacs 0:764779eedf2d 246 * pOut - pointer to the output buffer
andreikovacs 0:764779eedf2d 247 * outBytes - the number of bytes to be copyed (1-20)
andreikovacs 0:764779eedf2d 248 * pXSEED - optional user SEED. Should be NULL if not used.
andreikovacs 0:764779eedf2d 249 *
andreikovacs 0:764779eedf2d 250 * Return: The number of bytes copied or -1 if reseed is needed
andreikovacs 0:764779eedf2d 251 ******************************************************************************/
andreikovacs 0:764779eedf2d 252 int16_t RNG_GetPseudoRandomNo(uint8_t* pOut, uint8_t outBytes, uint8_t* pXSEED)
andreikovacs 0:764779eedf2d 253 {
andreikovacs 0:764779eedf2d 254 uint32_t i;
andreikovacs 0:764779eedf2d 255 sha1Context_t ctx;
andreikovacs 0:764779eedf2d 256
andreikovacs 0:764779eedf2d 257 if (mPRNG_Requests == gRngMaxRequests_d)
andreikovacs 0:764779eedf2d 258 return -1;
andreikovacs 0:764779eedf2d 259
andreikovacs 0:764779eedf2d 260 mPRNG_Requests++;
andreikovacs 0:764779eedf2d 261
andreikovacs 0:764779eedf2d 262 /* a. XSEEDj = optional user input. */
andreikovacs 0:764779eedf2d 263 if (pXSEED)
andreikovacs 0:764779eedf2d 264 {
andreikovacs 0:764779eedf2d 265 /* b. XVAL = (XKEY + XSEEDj) mod 2^b */
andreikovacs 0:764779eedf2d 266 for (i=0; i<mPRNG_NoOfBytes_c; i++)
andreikovacs 0:764779eedf2d 267 {
andreikovacs 0:764779eedf2d 268 ctx.buffer[i] = ((uint8_t*)XKEY)[i] + pXSEED[i];
andreikovacs 0:764779eedf2d 269 }
andreikovacs 0:764779eedf2d 270 }
andreikovacs 0:764779eedf2d 271 else
andreikovacs 0:764779eedf2d 272 {
andreikovacs 0:764779eedf2d 273 for (i=0; i<mPRNG_NoOfBytes_c; i++)
andreikovacs 0:764779eedf2d 274 {
andreikovacs 0:764779eedf2d 275 ctx.buffer[i] = ((uint8_t*)XKEY)[i];
andreikovacs 0:764779eedf2d 276 }
andreikovacs 0:764779eedf2d 277 }
andreikovacs 0:764779eedf2d 278
andreikovacs 0:764779eedf2d 279 /* c. xj = G(t,XVAL) mod q
andreikovacs 0:764779eedf2d 280 ***************************/
andreikovacs 0:764779eedf2d 281 SHA1_Hash(&ctx, ctx.buffer, mPRNG_NoOfBytes_c);
andreikovacs 0:764779eedf2d 282
andreikovacs 0:764779eedf2d 283 /* d. XKEY = (1 + XKEY + xj) mod 2^b */
andreikovacs 0:764779eedf2d 284 XKEY[0] += 1;
andreikovacs 0:764779eedf2d 285 for (i=0; i<mPRNG_NoOfLongWords_c; i++)
andreikovacs 0:764779eedf2d 286 {
andreikovacs 0:764779eedf2d 287 XKEY[i] += ctx.hash[i];
andreikovacs 0:764779eedf2d 288 }
andreikovacs 0:764779eedf2d 289
andreikovacs 0:764779eedf2d 290 /* Check if the length provided exceeds the output data size */
andreikovacs 0:764779eedf2d 291 if (outBytes > mPRNG_NoOfBytes_c)
andreikovacs 0:764779eedf2d 292 {
andreikovacs 0:764779eedf2d 293 outBytes = mPRNG_NoOfBytes_c;
andreikovacs 0:764779eedf2d 294 }
andreikovacs 0:764779eedf2d 295
andreikovacs 0:764779eedf2d 296 /* Copy the generated number */
andreikovacs 0:764779eedf2d 297 for (i=0; i < outBytes; i++)
andreikovacs 0:764779eedf2d 298 {
andreikovacs 0:764779eedf2d 299 pOut[i] = ((uint8_t*)ctx.hash)[i];
andreikovacs 0:764779eedf2d 300 }
andreikovacs 0:764779eedf2d 301
andreikovacs 0:764779eedf2d 302 return outBytes;
andreikovacs 0:764779eedf2d 303 }
andreikovacs 0:764779eedf2d 304 #endif
andreikovacs 0:764779eedf2d 305
andreikovacs 0:764779eedf2d 306 /********************************** EOF ***************************************/