Beispiel #1
0
//*****************************************************************************
//
//! main - populate the parameters from predefines Test Vector or User
//!
//! \param None
//!
//! \return None
//
//*****************************************************************************
void
main()
{
    unsigned int uiConfig,uiHashLength,uiDataLength;
    unsigned char *puiKey1,*puiData,*puiResult;
    unsigned int u8count;
#ifndef USER_INPUT
    unsigned char *puiTempExpResult;
#endif
    //
    // Initialize board configurations
    BoardInit();
    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    //
    // Enable the module .
    //
    MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK);
    //
    // Enable interrupts.
    //
    MAP_SHAMD5IntRegister(SHAMD5_BASE, SHAMD5IntHandler);

#ifdef USER_INPUT
    while(FOREVER)
    {
        //
        // Read values either from User or from Vector based on macro USER_INPUT
        // defined or not
        //

        //
        // Read the values from the user over uart and Populate the variables
        //
        puiData=ReadFromUser(&uiConfig,&uiHashLength,&puiKey1,&uiDataLength,
                             &puiResult);
        if(puiData==NULL)
        {
            continue;
        }
#else
    //
    // Load Default values
    //
    UART_PRINT("Running Keyed Hashing HMAC_MD5\n\r\n\r");
    UART_PRINT("loading default values\n\r\n\r");
    uiHMAC=1;
    puiData= LoadDefaultValues(SHAMD5_ALGO_HMAC_MD5,&uiConfig,&uiHashLength,
                               &puiKey1,&uiDataLength,&puiResult);
    UART_PRINT("Data Length (in Bytes) %d\n\r\n\r",uiDataLength);
#endif

        //
        // Generate Hash Value
        //
        UART_PRINT("\n\rHashing in Progress... \n\r");
        GenerateHash(uiConfig,puiKey1,puiData,puiResult,uiDataLength);
        UART_PRINT("Hash Value is generated\n\r");
        //
        // Display/Verify Result
        //

#ifdef USER_INPUT
        //
        // Display Hash Value Generated
        //
        UART_PRINT("\n\r The Hash Value in Hex is: 0x%02x",*puiResult);
        for(u8count=0; u8count<(uiHashLength/4); u8count++)
        {
            UART_PRINT("%02x",*(puiResult+u8count));
        }
        UART_PRINT("\n\r");
    } //end while(FOREVER)
#else
        //
        // Comapre Hash Generated and expected values from predefined vector
        //
        UART_PRINT("Hash Length (in Bytes) %d\n\r\n\r",uiHashLength);
        UART_PRINT("\n\r Computed Hash Value in Hex is: ");
        for(u8count=0; u8count<uiHashLength; u8count++)
        {
            UART_PRINT("%02x",*(puiResult+u8count));
        }
        UART_PRINT("\n\r");

        puiTempExpResult = (unsigned char *)g_psHMACShaMD5TestVectors.puiExpectedHash;

        UART_PRINT("\n\r Expected Hash Value in Hex is: ");
        for(u8count=0; u8count<uiHashLength; u8count++)
        {
            UART_PRINT("%02x",*(puiTempExpResult+u8count));
        }
        UART_PRINT("\n\r");

        if(memcmp(puiResult,g_psHMACShaMD5TestVectors.puiExpectedHash,uiHashLength)==0)
        {
            UART_PRINT("\n\r Hashing verified successfully");
        }
        else
        {
            UART_PRINT("\n\r Error in Hashing computation");
        }
        while(FOREVER);
#endif


}
Beispiel #2
0
//*****************************************************************************
//
//! main - calls Crypt function after populating either from pre- defined vector 
//! or from User
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
void 
main()
{
    unsigned int uiConfig,uiKeySize,*puiKey1,*puiData,*puiResult=NULL,
    uiDataLength,uiIV[4]={0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c};

#ifdef USER_INPUT
    unsigned int uiCharCount;
    unsigned char* pucResult;
#else
    unsigned int *puiIV;
    puiIV=&uiIV[0];

#endif
    BoardInit();
    
    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    //
    // Enable AES Module
    //
    MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK);
    
    //
    // Enable AES interrupts.
    //
    MAP_AESIntRegister(AES_BASE, AESIntHandler);
#ifdef USER_INPUT
    while(FOREVER)
    {
        //
        // Read values either from User or from Vector based on macro USER_INPUT
        // defined or not
        //

        //
        // Read the values from the user over uart and Populate the variables
        //
        puiData = ReadFromUser(&uiConfig,&uiKeySize,&puiKey1,&uiDataLength,\
                                &puiResult);
        if((puiData == NULL) || (puiResult == NULL))
        {
            continue;
        }
#else
        //
        // Load Default values
        //
        puiData = LoadDefaultValues(AES_CFG_DIR_ENCRYPT | AES_CFG_MODE_CBC ,
                                    &uiConfig,&uiKeySize,&puiIV,&puiKey1,
                                    &uiDataLength,&puiResult);
        
        if((puiData == NULL) || (puiResult == NULL))
        {
            while(FOREVER);
        }
#endif

        //
        // Carry out Encryption
        //
        UART_PRINT("\n\r Encryption in progress....");
        AESCrypt(uiConfig,uiKeySize,puiKey1,puiData,puiResult,uiDataLength,uiIV);
        UART_PRINT("\n\r Encryption done, cipher text created");
        
        //
        // Copy Result into Data Vector to continue with Decryption. and change 
        // config value
        //
        memcpy(puiData,puiResult,uiDataLength);
        uiConfig &= ~(1 << 2);
        //
        // Carry out Decryption
        //
        UART_PRINT("\n\r\n\r Decryption in progress....");
        AESCrypt(uiConfig,uiKeySize,puiKey1,puiData,puiResult,uiDataLength,uiIV);
        UART_PRINT("\n\r Decryption done");
        
        //
        // Display/Verify Result
        //

    #ifdef USER_INPUT
        //
        // Display Plain Text
        //
        UART_PRINT("\n\r Text after decryption ");
        pucResult = (unsigned char *)puiResult;
        for(uiCharCount=0;uiCharCount<uiDataLength;uiCharCount++)
        {
            UART_PRINT("%c",*(pucResult+uiCharCount));
        }
        UART_PRINT("\n\r");
        if(puiResult)
        {
        	free(puiResult);
        }
        if(puiData)
        {
        	free(puiData);
        }
    }
    #else
        //
        // Compare Cipher Text and Plain Text with the expected values from 
        // predefined vector
        //
        if(memcmp(puiData,psAESCBCTestVectors.pui32CipherText,
                        psAESCBCTestVectors.ui32DataLength)==0)
        {
            UART_PRINT("\n\r\n\r Encryption verification Successful");
        }
        else
        {
            UART_PRINT("\n\r\n\r Error in Encryption");
        }

        if(memcmp(puiResult,psAESCBCTestVectors.pui32PlainText,
                        psAESCBCTestVectors.ui32DataLength)==0)
        {
            UART_PRINT("\n\r Decryption verification Successful");
        }
        else
        {
            UART_PRINT("\n\r\n\r Error in Decryption");
        }
        while(FOREVER);
    #endif

}
Beispiel #3
0
//*****************************************************************************
//
//! main - calls Crypt function after populating either from pre- defined vector 
//! or from User
//!
//! \param  none
//!
//! \return none
//!
//*****************************************************************************
void 
main()
{
    unsigned long  uiAdcInputPin;  
    unsigned int  uiChannel;
    unsigned int  uiIndex=0;
    unsigned long ulSample;      

    //
    // Initialize Board configurations
    //
    BoardInit();

    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    while(FOREVER)
    {
        //
        // Initialize Array index for multiple execution
        //
        uiIndex=0;
      
        //
        // Read inputs from user
        //
        if(!ReadFromUser(&uiAdcInputPin))
        {
          UART_PRINT("\n\rInvalid Input. Please try again. HAHAHAHAHAHAHAHAHA\n\r");
          continue;
        }

#ifdef CC3200_ES_1_2_1
        //
        // Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32
        //
        HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043;
        HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100;
        HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;
#endif
        //
        // Pinmux for the selected ADC input pin
        //
        MAP_PinTypeADC(uiAdcInputPin,PIN_MODE_255);

        //
        // Convert pin number to channel number
        //
        switch(uiAdcInputPin)
        {
            case PIN_58:
                uiChannel = ADC_CH_1;
                break;
            case PIN_59:
                uiChannel = ADC_CH_2;
                break;
            case PIN_60:
                uiChannel = ADC_CH_3;
                break;
            default:
                break;
        }

        //
        // Configure ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerConfig(ADC_BASE,2^17);

        //
        // Enable ADC timer which is used to timestamp the ADC data samples
        //
        MAP_ADCTimerEnable(ADC_BASE);

        //
        // Enable ADC module
        //
        MAP_ADCEnable(ADC_BASE);

        //
        // Enable ADC channel
        //

        MAP_ADCChannelEnable(ADC_BASE, uiChannel);

        while(uiIndex < NO_OF_SAMPLES + 4)
        {
            if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
            {
                ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);
                pulAdcSamples[uiIndex++] = ulSample;
            }


        }

        MAP_ADCChannelDisable(ADC_BASE, uiChannel);

        uiIndex = 0;

        //UART_PRINT("\n\rTotal no of 32 bit ADC data printed :4096 \n\r");
        //UART_PRINT("\n\rADC data format:\n\r");
        //UART_PRINT("\n\rbits[13:2] : ADC sample\n\r");
        //UART_PRINT("\n\rbits[31:14]: Time stamp of ADC sample \n\r");

        //
        // Print out ADC samples
        //

        while(uiIndex < NO_OF_SAMPLES)
        {
            UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.4)/4096);
            uiIndex++;
        }


        //UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.4/4096);
        UART_PRINT("\n\r");

    }

}
Beispiel #4
0
//*****************************************************************************
//
//! Main 
//!
//! \param None
//!
//! \return None
//
//*****************************************************************************
void 
main()
{
    unsigned int uiConfig,uiSeed=0x0000a5a5,uiDataLength,*puiData,uiResult;
    
    //
    // Initialize Board configurations
    //
    BoardInit();
    
    //
    // Configuring UART for Receiving input and displaying output
    // 1. PinMux setting
    // 2. Initialize UART
    // 3. Displaying Banner
    //
    PinMuxConfig();
    InitTerm();
    DisplayBanner(APP_NAME);

    //
    // Enable CRC Module
    //
    MAP_PRCMPeripheralClkEnable(PRCM_DTHE, PRCM_RUN_MODE_CLK);
#ifdef USER_INPUT
    while(FOREVER)
    {
        //
        // Read values either from User or from Vector based on macro USER_INPUT
        // defined or not
        //

        //
        // Read the values from the user over uart and Populate the variables
        //
        puiData=ReadFromUser(&uiConfig,&uiDataLength,&uiResult);
        if(puiData == NULL)
        {
            UART_PRINT("\n\rInvalid Input. Please try again. \n\r");
            continue;
        }
#else
        //
        // Load Default values
        //
        UART_PRINT("Running CRC-16-IBM 0x8005 Vectors\n");
        puiData=LoadDefaultValues(CRC_CFG_INIT_SEED | CRC_CFG_TYPE_P8005 |
                                   CRC_CFG_SIZE_32BIT,
                                   &uiConfig,&uiDataLength,&uiSeed,&uiResult);
#endif

        //
        // Carry out Encryption
        //
        UART_PRINT("\n\r CRC Generation in progress....");
        RunCRC(uiConfig,uiDataLength,uiSeed,puiData,&uiResult);
        UART_PRINT("\n\r CRC Result is generated\n\r");
        
        //
        // Display/Verify Result
        //

#ifdef USER_INPUT
        //
        // Display Plain Text
        //
        UART_PRINT("\n\r The CRC Result in hex is: 0x%02x \n\r",uiResult);
    }
#else
    //
    // Comapre Cipher Text and Plain Text with the expected values from 
    // predefined vector
    //
    UART_PRINT("\n\r The Generated CRC Result in hex is: 0x%02x \n\r",uiResult);
    UART_PRINT("\n\r The Expected CRC in hex is: 0x%02x \n\r",
                                            g_psCRC8005TestVectors.ui32Result);
    if(uiResult==g_psCRC8005TestVectors.ui32Result)
    {
      UART_PRINT("\n\r\n\r CRC result is verified successfully");
    }
    else
    {
      UART_PRINT("\n\r\n\r Error in CRC generation");
    }

    while(FOREVER);

#endif

}