Update repo

This commit is contained in:
2026-08-30 23:04:35 -07:00
parent 749dab5721
commit ce65a0f59a
14950 changed files with 4408250 additions and 1 deletions
@@ -0,0 +1,128 @@
//###########################################################################
//
// FILE: aes_cbc.h
//
// TITLE: AES CBC mode header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef AES_CBC_H
#define AES_CBC_H
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup aes_cbc_api AES CBC API
//! @{
//
//*****************************************************************************
#include <stdint.h>
#include "aes_common.h"
#ifndef MEM_PACKED_SPEED_OPT
//*****************************************************************************
//
//! Perform AES CBC Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is the AES operation mode of encryption or decryption
//! \param iv is the initialization vector of size 128 bits
//!
//! This function performs AES Cipher Block Chaining (CBC) mode
//! encryption or decryption on the requested number of 128-bit input blocks.
//!
//! \return None.
//
//*****************************************************************************
extern void AES_performCBC(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *iv);
#endif
//*****************************************************************************
//
//! Perform AES CBC fast Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is the AES operation mode of encryption or decryption
//! \param iv is the initialization vector of size 128 bits
//!
//! This function performs AES Cipher Block Chaining (CBC) mode fast
//! encryption or decryption on the requested number of 128-bit input blocks.
//!
//! \return None.
//
//*****************************************************************************
extern void AES_performCBCFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *iv);
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif //AES_CBC_H
@@ -0,0 +1,132 @@
//###########################################################################
//
// FILE: aes_cmac.h
//
// TITLE: AES CMAC mode header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef AES_CMAC_H
#define AES_CMAC_H
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup aes_cmac_api AES CMAC API
//! @{
//
//*****************************************************************************
//*****************************************************************************
#include <stdint.h>
#include "aes_common.h"
#ifndef MEM_PACKED_SPEED_OPT
//*****************************************************************************
//
//! Perform AES CMAC to generate Message Authentication Code (MAC)
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//!
//! This function performs AES Cipher-based Message Authentication
//! (CMAC) on the requested number of 128-bit input plain text blocks.
//! The calculated Message Authentication Code(MAC) is returned.
//!
//! - \b Note: Size of the plain text must be a multiple of 128-bits
//!
//! \return MAC Starting address of a 128 element array
//! containing the MAC(128-bits)
//
//*****************************************************************************
extern uint16_t *AES_performCMAC(uint16_t *text, uint16_t length,
uint16_t *key, AES_KeySize keysize);
#endif
//*****************************************************************************
//
//! Perform AES fast CMAC to generate Message Authentication Code (MAC)
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//!
//! This function performs AES fast Cipher-based Message Authentication
//! (CMAC) on the requested number of 128-bit input plain text blocks.
//! The calculated Message Authentication Code(MAC) is returned.
//!
//! - \b Note: Size of the plain text must be a multiple of 128-bits
//!
//! \return MAC Starting address of a 128 element array
//! containing the MAC(128-bits)
//
//*****************************************************************************
extern uint16_t *AES_performCMACFast(uint16_t *text, uint16_t length,
uint16_t *key, AES_KeySize keysize);
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif //AES_CMAC_H
@@ -0,0 +1,155 @@
//###########################################################################
//
// FILE: aes_common.h
//
// TITLE: AES algorithm header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef AES_H
#define AES_H
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
#include <stdint.h>
//*****************************************************************************
//
//! Modes that can be used in the encryption/decryption functions
//
//*****************************************************************************
typedef enum
{
AES_OPMODE_ENCRYPT, //!< Encryption mode
AES_OPMODE_DECRYPT //!< Decryption mode
} AES_OperationMode;
//*****************************************************************************
//
//! Key sizes that can be used in the AES algorithm
//
//*****************************************************************************
typedef enum
{
AES_128, //!< AES 128 bit key size
AES_256 //!< AES 128 bit key size
} AES_KeySize;
#ifndef MEM_PACKED_SPEED_OPT
//*****************************************************************************
//
//! Perform AES Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param mode is the AES operation mode of encryption or decryption
//!
//! This function performs AES encryption/decryption algorithm
//! with 128-bit/256-bit key sizes
//!
//! \return None.
//
//*****************************************************************************
void AES_perform(uint16_t *text, AES_OperationMode mode);
//*****************************************************************************
//
//! Perform AES key expansion
//!
//! \param key is the AES key
//! \param keysize is the size of the AES key
//!
//! This function performs AES key expansion algorithm for 128/256 bit keys
//!
//! \return None.
//
//*****************************************************************************
void AES_expandKey(uint16_t *key, AES_KeySize keysize);
#endif
//*****************************************************************************
//
//! Perform AES fast Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param mode is the AES operation mode of encryption or decryption
//!
//! This function performs AES fast encryption/decryption algorithm
//! with 128-bit/256-bit key sizes
//!
//! \return None.
//
//*****************************************************************************
void AES_performFast(uint16_t *text, AES_OperationMode mode);
//*****************************************************************************
//
//! Perform AES key expansion
//!
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is operation mode encryption or decryption
//!
//! This function performs AES key expansion algorithm for 128/256 bit keys
//!
//! \return None.
//
//*****************************************************************************
void AES_expandKeyFast(uint16_t *key, AES_KeySize keysize,
AES_OperationMode mode);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* AES_AES */
@@ -0,0 +1,132 @@
//###########################################################################
//
// FILE: aes_ctr.h
//
// TITLE: AES CTR mode header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef AES_CTR_H
#define AES_CTR_H
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup aes_ctr_api AES CTR API
//! @{
//
//*****************************************************************************
#include <stdint.h>
#include "aes_common.h"
#ifndef MEM_PACKED_SPEED_OPT
//*****************************************************************************
//
//! Perform AES CTR Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is the AES operation mode of encryption or decryption
//! \param nonceCounter is the required number-used-once 128-bit counter
//! value
//!
//! This function performs AES Counter (CTR) mode encryption or
//! decryption on the requested number of 128-bit input blocks.
//!
//! \return None.
//
//*****************************************************************************
extern void AES_performCTR(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *nonceCounter);
#endif
//*****************************************************************************
//
//! Perform AES CTR fast Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is the AES operation mode of encryption or decryption
//! \param nonceCounter is the required number-used-once 128-bit counter
//! value
//!
//! This function performs AES Counter (CTR) mode fast encryption or
//! decryption on the requested number of 128-bit input blocks.
//!
//! \return None.
//
//*****************************************************************************
extern void AES_performCTRFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *nonceCounter);
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif //AES_CTR_H
@@ -0,0 +1,120 @@
//###########################################################################
//
// FILE: aes_ecb.h
//
// TITLE: AES ECB mode header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef AES_ECB_H_
#define AES_ECB_H_
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
#include <stdint.h>
#include "aes_common.h"
#ifndef MEM_PACKED_SPEED_OPT
//*****************************************************************************
//
//! Perform AES ECB Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is the AES operation mode of encryption or decryption
//!
//! This function performs AES Electronic Code Book (ECB) mode
//! encryption or decryption on the requested number of 128-bit input blocks.
//!
//! \return None.
//
//*****************************************************************************
extern void AES_performECB(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode);
#endif
//*****************************************************************************
//
//! Perform AES ECB fast Encryption/Decryption
//!
//! \param text is the input plaintext or ciphertext and once operation is
//! complete, this parameter contains the output plaintext or ciphertext
//! \param length is the length of the input data in blocks (block size is
//! 128-bits)
//! \param key is the AES key
//! \param keysize is the size of the AES key
//! \param mode is the AES operation mode of encryption or decryption
//!
//! This function performs AES Electronic Code Book (ECB) mode fast
//! encryption or decryption on the requested number of 128-bit input blocks.
//!
//! \return None.
//
//*****************************************************************************
extern void AES_performECBFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode);
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* AES_ECB_H_ */
@@ -0,0 +1,341 @@
//###########################################################################
//
// FILE: aes_cbc.c
//
// TITLE: Implementation of the AES CBC mode
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "aes_cbc.h"
//*****************************************************************************
//
// CBC_splitText - Split text into 128 bit blocks based on blockNumber
//
//*****************************************************************************
void CBC_splitText(uint16_t *text, uint16_t *output, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = text[(16 * blockNumber) + i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = text[(8 * blockNumber) + i];
}
#endif
}
//*****************************************************************************
//
// CBC_perform128bitXOR - Perform XOR operation on two 16 byte arrays
//
//*****************************************************************************
void CBC_perform128bitXOR(uint16_t *input1, uint16_t *input2, uint16_t *out)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0U; i < 16U; i++)
#else
for(i = 0U; i < 8U; i++)
#endif
{
out[i] = input1[i] ^ input2[i];
}
}
//*****************************************************************************
//
// CBC_move128bitArray - Move input array into output array
//
//*****************************************************************************
void CBC_move128bitArray(uint16_t *input, uint16_t *output)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = input[i];
}
#endif
}
//*****************************************************************************
//
// CBC_mergeText - Merge final plaintext/ciphertext into text array
//
//*****************************************************************************
void CBC_mergeText(uint16_t *text, uint16_t *input, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
text[(16 * blockNumber) + i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
text[(8 * blockNumber) + i] = input[i];
}
#endif
}
//*****************************************************************************
//
// AES CBC mode of operation
//
//*****************************************************************************
#ifndef MEM_PACKED_SPEED_OPT
void AES_performCBC(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode, uint16_t *iv)
{
//
// Initialize local variables
//
uint16_t previousCiphertext[16];
uint16_t currentCiphertext[16];
uint16_t decryptionCiphertext[16];
uint16_t i;
//
// Key expansion
//
AES_expandKey(key, keysize);
//
// set previousCiphertext equal to the initialization vector
//
CBC_move128bitArray(iv, previousCiphertext);
//
// main loop
// Encryption order of operations: XOR plaintext with previousCiphertext,
// encrypt plaintext, save result for next
// round
// Decryption order of operations: save ciphertext for next round, decrypt
// ciphertext, XOR ciphertext with
// previousCiphertext
//
for(i = 0; i < length; i++)
{
if(mode == AES_OPMODE_ENCRYPT)
{
//
// Get 128 bit block of plaintext from array passed in
//
CBC_splitText(text, currentCiphertext, i);
//
// XOR initialization vector/previousCiphertext with new plaintext
//
CBC_perform128bitXOR(currentCiphertext, previousCiphertext,
currentCiphertext);
//
// AES encryption
//
AES_perform(currentCiphertext, mode);
//
// move result to previousCiphertext for use in next round
//
CBC_move128bitArray(currentCiphertext, previousCiphertext);
}
else
{
//
// Get 128 bit block of ciphertext from array passed in
//
CBC_splitText(text, currentCiphertext, i);
//
// Copy ciphertext into temporary variable so it can be moved into
// previousCiphertext later on
//
CBC_move128bitArray(currentCiphertext, decryptionCiphertext);
//
// AES decryption
//
AES_perform(currentCiphertext, mode);
//
// XOR initialization vector/previousCiphertext with new ciphertext
//
CBC_perform128bitXOR(currentCiphertext, previousCiphertext,
currentCiphertext);
//
// Move temporary ciphertext array into previousCiphertext
//
CBC_move128bitArray(decryptionCiphertext, previousCiphertext);
}
//
// Move the final plaintext/ciphertext into text
//
CBC_mergeText(text, currentCiphertext , i);
}
}
#endif
//*****************************************************************************
//
// AES CBC fast mode of operation
//
//*****************************************************************************
void AES_performCBCFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *iv)
{
//
// Initialize local variables
//
#ifndef MEM_PACKED_SPEED_OPT
uint16_t previousCiphertext[16];
#else
uint16_t previousCiphertext[8];
#endif
#ifndef MEM_PACKED_SPEED_OPT
uint16_t currentCiphertext[16];
#else
uint16_t currentCiphertext[8];
#endif
#ifndef MEM_PACKED_SPEED_OPT
uint16_t decryptionCiphertext[16];
#else
uint16_t decryptionCiphertext[8];
#endif
uint16_t i;
//
// Key expansion
//
AES_expandKeyFast(key, keysize, mode);
//
// set previousCiphertext equal to the initialization vector
//
CBC_move128bitArray(iv, previousCiphertext);
//
// Main loop
// Encryption order of operations: XOR plaintext with previousCiphertext,
// encrypt plaintext, save result for next
// round
// Decryption order of operations: save ciphertext for next round, decrypt
// ciphertext, XOR ciphertext with
// previousCiphertext
//
for(i = 0; i < length; i++)
{
if(mode == AES_OPMODE_ENCRYPT)
{
//
// Get 128 bit block of plaintext from array passed in
//
CBC_splitText(text, currentCiphertext, i);
//
// XOR initialization vector/previousCiphertext with new plaintext
//
CBC_perform128bitXOR(currentCiphertext, previousCiphertext,
currentCiphertext);
//
// AES fast encryption
//
AES_performFast(currentCiphertext, mode);
//
// move result to previousCiphertext for use in next round
//
CBC_move128bitArray(currentCiphertext, previousCiphertext);
}
else
{
//
// Get 128 bit block of ciphertext from array passed in
//
CBC_splitText(text, currentCiphertext, i);
//
// Copy ciphertext into temporary variable so it can be moved into
// previousCiphertext later on
//
CBC_move128bitArray(currentCiphertext, decryptionCiphertext);
//
// AES fast decryption
//
AES_performFast(currentCiphertext, mode);
//
// XOR initialization vector/previousCiphertext with new ciphertext
//
CBC_perform128bitXOR(currentCiphertext, previousCiphertext,
currentCiphertext);
//
// Move temporary ciphertext array into previousCiphertext
//
CBC_move128bitArray(decryptionCiphertext, previousCiphertext);
}
//
// Move the final plaintext/ciphertext into text
//
CBC_mergeText(text, currentCiphertext , i);
}
}
//
// End of File
//
@@ -0,0 +1,417 @@
//###########################################################################
//
// FILE: aes_cmac.c
//
// TITLE: Implementation of the AES CMAC mode.
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "aes_cmac.h"
//*****************************************************************************
//
// Array to store the generated Message Authentication Code
//
//*****************************************************************************
#ifndef MEM_PACKED_SPEED_OPT
uint16_t CMAC_Tag[16];
#else
uint16_t CMAC_Tag[8];
#endif
//*****************************************************************************
//
// CMAC_splitText - Split text into 128 bit blocks based on blockNumber
//
//*****************************************************************************
void CMAC_splitText(uint16_t *text, uint16_t *output, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = text[(16 * blockNumber) + i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = text[(8 * blockNumber) + i];
}
#endif
}
//*****************************************************************************
//
// CMAC_perform128bitXOR - Perform XOR operation on two 16 byte arrays
//
//*****************************************************************************
void CMAC_perform128bitXOR(uint16_t *input1, uint16_t *input2)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0U; i < 16U; i++)
#else
for(i = 0U; i < 8U; i++)
#endif
{
input1[i] ^= input2[i];
}
}
//*****************************************************************************
//
// CMAC_performOneBitLeftshift - Perform left shift on 16 byte array
//
//*****************************************************************************
void CMAC_performOneBitLeftshift(uint16_t *input, uint16_t *output)
{
int16_t i;
uint16_t overflow = 0U;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 15; i >= 0; i--)
{
output[i] = (input[i] << 1U) & 0xFFU;
output[i] |= overflow;
overflow = (input[i] & 0x80U)?1U:0U;
}
#else
for(i = 7; i >= 0; i--)
{
output[i] = (input[i] << 1U) & 0xFFFFU;
output[i] |= overflow;
overflow = (input[i] & 0x8000U)?1U:0U;
}
#endif
}
//*****************************************************************************
//
// CMAC_memset - Copy of compiler memset to quickly clear arrays
//
//*****************************************************************************
void CMAC_memset(void *mem, int16_t ch, uint32_t length)
{
char *m = (char *)mem;
while(length--)
{
*m++ = ch;
}
}
//*****************************************************************************
//
// CMAC_move128bitArray - Move input array into output array
//
//*****************************************************************************
void CMAC_move128bitArray(uint16_t *input, uint16_t *output)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = input[i];
}
#endif
}
//*****************************************************************************
//
// AES256_performCMAC
//
//*****************************************************************************
#ifndef MEM_PACKED_SPEED_OPT
uint16_t *AES_performCMAC(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize)
{
//
// Setup local variables for calculation
//
int16_t i = 0;
uint16_t k0[16];
uint16_t k1[16];
uint16_t CMAC_AES_CONSTANT[16];
uint16_t currentMessage[16];
//
// Key expansion
//
AES_expandKey(key, keysize);
//
// Set arrays to zero
//
CMAC_memset(currentMessage, 0, sizeof(currentMessage));
CMAC_memset(CMAC_Tag, 0, sizeof(CMAC_Tag));
CMAC_memset(CMAC_AES_CONSTANT, 0, sizeof(CMAC_AES_CONSTANT));
//
// Configure AES Constant
//
CMAC_AES_CONSTANT[15] = 0x87U;
//
// Begin CMAC Algorithm
//
//
// Calculate k0 with encryption of 0
//
AES_perform(currentMessage, AES_OPMODE_ENCRYPT);
//
// Move ciphertext into k0 for future use
//
CMAC_move128bitArray(currentMessage, k0);
//
// Generate k1
// Note: Not generating k2 since plain text length is in multiple of
// 128-bits
// No padding will be required or performed.
//
if((k0[0] & 0x80U) == 0U)
{
//
// Left shift k0 by 1 to calculate k1
//
CMAC_performOneBitLeftshift(k0, k1);
}
else
{
//
// Left shift k0 by 1 to calculate temporary k1. Then XOR temporary k1
// by the AES-256bit constant to calculate k1.
//
CMAC_performOneBitLeftshift(k0, k1);
CMAC_perform128bitXOR(k1, CMAC_AES_CONSTANT);
}
//
// Perform message block cipher encryption on all blocks except last one
//
for(i = 0; i < length - 1; i++)
{
//
// Get 128 bit block of plaintext from array passed in
//
CMAC_splitText(text, currentMessage, i);
//
// XOR initialization vector/previousCiphertext with new plaintext
//
CMAC_perform128bitXOR(CMAC_Tag,currentMessage);
//
// Perform AES encryption on CMAC_TAG
//
AES_perform(CMAC_Tag, AES_OPMODE_ENCRYPT);
}
//
// Get 128 bit block of plaintext from array passed in
//
CMAC_splitText(text, currentMessage, i);
//
// XOR last message with k1
//
CMAC_perform128bitXOR(currentMessage, k1);
//
// Generate final tag - XOR CMAC_TAG and CMAC_LAST_MESSAGE.
// Encrypt CMAC_TAG.
//
CMAC_perform128bitXOR(CMAC_Tag, currentMessage);
AES_perform(CMAC_Tag, AES_OPMODE_ENCRYPT);
return(CMAC_Tag);
}
#endif
//*****************************************************************************
//
// AES perform fast CMAC
//
//*****************************************************************************
uint16_t *AES_performCMACFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize)
{
//
// Setup local variables for calculation
//
int16_t i = 0;
#ifndef MEM_PACKED_SPEED_OPT
uint16_t k0[16];
#else
uint16_t k0[8];
#endif
#ifndef MEM_PACKED_SPEED_OPT
uint16_t k1[16];
#else
uint16_t k1[8];
#endif
#ifndef MEM_PACKED_SPEED_OPT
uint16_t CMAC_AES_CONSTANT[16];
#else
uint16_t CMAC_AES_CONSTANT[8];
#endif
#ifndef MEM_PACKED_SPEED_OPT
uint16_t currentMessage[16];
#else
uint16_t currentMessage[8];
#endif
//
// Key expansion
//
AES_expandKeyFast(key, keysize, AES_OPMODE_ENCRYPT);
//
// Set arrays to zero
//
CMAC_memset(currentMessage, 0, sizeof(currentMessage));
CMAC_memset(CMAC_Tag, 0, sizeof(CMAC_Tag));
CMAC_memset(CMAC_AES_CONSTANT, 0, sizeof(CMAC_AES_CONSTANT));
//
// Configure AES Constant
//
#ifndef MEM_PACKED_SPEED_OPT
CMAC_AES_CONSTANT[15] = 0x87U;
#else
CMAC_AES_CONSTANT[7] = 0x87U;
#endif
//
// Begin CMAC Algorithm
//
//
// Calculate k0 with fast encryption of 0
//
AES_performFast(currentMessage, AES_OPMODE_ENCRYPT);
//
// Move ciphertext into k0 for future use
//
CMAC_move128bitArray(currentMessage, k0);
//
// Generate k1
// Not generating k2 since plain text length is in multiple of 128-bits
// No padding will be required or performed.
//
#ifndef MEM_PACKED_SPEED_OPT
if((k0[0] & 0x80U) == 0U)
#else
if((k0[0] & 0x8000U) == 0U)
#endif
{
//
// Left shift k0 by 1 to calculate k1
//
CMAC_performOneBitLeftshift(k0, k1);
}
else
{
//
// Left shift k0 by 1 to calculate temporary k1. Then XOR temporary k1
// by the AES-256bit constant to calculate k1.
//
CMAC_performOneBitLeftshift(k0, k1);
CMAC_perform128bitXOR(k1, CMAC_AES_CONSTANT);
}
//
// Perform message block cipher encryption on all blocks except last one
//
for(i = 0; i < length - 1; i++)
{
//
// Get 128 bit block of plaintext from array passed in
//
CMAC_splitText(text, currentMessage, i);
//
// XOR initialization vector/previousCiphertext with new plaintext
//
CMAC_perform128bitXOR(CMAC_Tag, currentMessage);
//
// Perform AES fast encryption on CMAC_TAG
//
AES_performFast(CMAC_Tag, AES_OPMODE_ENCRYPT);
}
//
// Get 128 bit block of plaintext from array passed in
//
CMAC_splitText(text, currentMessage, i);
//
// XOR last message with k1
//
CMAC_perform128bitXOR(currentMessage, k1);
//
// Generate final CMAC_Tag - XOR CMAC_TAG and CMAC_LAST_MESSAGE.
// Encrypt CMAC_TAG.
//
CMAC_perform128bitXOR(CMAC_Tag, currentMessage);
AES_performFast(CMAC_Tag, AES_OPMODE_ENCRYPT);
return(CMAC_Tag);
}
//
// End of File
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,315 @@
//###########################################################################
//
// FILE: aes_ctr.c
//
// TITLE: Implementation of the AES CTR mode
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "aes_ctr.h"
//*****************************************************************************
//
// CTR_splitText - Split text into 128 bit blocks based on blockNumber
//
//*****************************************************************************
void CTR_splitText(uint16_t *text, uint16_t *output, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = text[(16 * blockNumber) + i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = text[(8 * blockNumber) + i];
}
#endif
}
//*****************************************************************************
//
// CTR_perform128bitXOR - Perform XOR operation on two 16 byte arrays
//
//*****************************************************************************
void CTR_perform128bitXOR(uint16_t *input1, uint16_t *input2, uint16_t *out)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0U; i < 16U; i++)
#else
for(i = 0U; i < 8U; i++)
#endif
{
out[i] = input1[i] ^ input2[i];
}
}
//*****************************************************************************
//
// CTR_move128bitArray - Move input array into output array
//
//*****************************************************************************
void CTR_move128bitArray(uint16_t *input, uint16_t *output)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = input[i];
}
#endif
}
//*****************************************************************************
//
// CTR_incrementCounter - Increment nonceCounter for next round
//
//*****************************************************************************
void CTR_incrementCounter(uint16_t *input)
{
int16_t i = 0;
#ifndef MEM_PACKED_SPEED_OPT
input[15] = input[15] + 1;
//
// If overflow, then carry the overflow into more significant bytes
// until there is no more overflow. If the input is 0xFFFFFFFFFFFFFFFF,
// it will become 0x0000000000000000 when incremented.
//
for(i = 15; i >= 0; i--)
{
if(((input[i] & 0x100) >> 8) == 1)
{
if(i != 0)
{
input[i - 1] = input[i - 1] + 1;
}
input[i] = 0x00;
}
}
#else
uint32_t CTR_temp;
CTR_temp = (uint32_t)input[7] + 1;
input[7] = input[7] + 1;
for(i = 7; i >= 0; i--)
{
if(((CTR_temp & 0x10000) >> 16) == 1)
{
if( i != 0)
{
CTR_temp = (uint32_t)input[i - 1] + 1;
input[i - 1] = input[i - 1] + 1;
}
input[i] = 0x0000;
}
}
#endif
}
//*****************************************************************************
//
// CTR_mergeText - Merge final plaintext/ciphertext into text array
//
//*****************************************************************************
void CTR_mergeText(uint16_t *text, uint16_t *input, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
text[(16 * blockNumber) + i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
text[(8 * blockNumber) + i] = input[i];
}
#endif
}
//*****************************************************************************
//
// AES CTR mode of operation
//
//*****************************************************************************
#ifndef MEM_PACKED_SPEED_OPT
void AES_performCTR(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *nonceCounter)
{
//
// Initialize local variables
//
uint16_t i;
uint16_t roundText[16];
uint16_t encryptionInput[16];
//
// Key expansion
//
AES_expandKey(key, keysize);
//
// main loop
// Encryption/Decryption order of operations: get block of text, encrypt
// nonceCounter, XOR with text,
// update text
//
for(i = 0; i < length; i++)
{
//
// Get 128 bit block of plaintext/ciphertext from array passed in
//
CTR_splitText(text, roundText, i);
//
// Set encryption input for round equal to round counter
//
CTR_move128bitArray(nonceCounter, encryptionInput);
//
// AES ECB encryption
//
AES_perform(encryptionInput, AES_OPMODE_ENCRYPT);
//
// XOR ciphertext with new plaintext/ciphertext to get final
// ciphertext/plaintext
//
CTR_perform128bitXOR(encryptionInput, roundText, roundText);
//
// Increment counter for next round
//
CTR_incrementCounter(nonceCounter);
//
// Move the final plaintext/ciphertext into text
//
CTR_mergeText(text, roundText , i);
}
}
#endif
//*****************************************************************************
//
// AES CTR fast mode of operation
//
//*****************************************************************************
void AES_performCTRFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode,
uint16_t *nonceCounter)
{
//
// Initialize local variables
//
uint16_t i;
#ifndef MEM_PACKED_SPEED_OPT
uint16_t roundText[16];
#else
uint16_t roundText[8];
#endif
#ifndef MEM_PACKED_SPEED_OPT
uint16_t encryptionInput[16];
#else
uint16_t encryptionInput[8];
#endif
//
// Key expansion
//
AES_expandKeyFast(key, keysize, AES_OPMODE_ENCRYPT);
//
// Main loop
// Encryption/Decryption order of operations: get block of text, encrypt
// nonceCounter, XOR with text,
// update text
//
for(i = 0; i < length; i++)
{
//
// Get 128 bit block of plaintext/ciphertext from array passed in
//
CTR_splitText(text, roundText, i);
//
// Set encryption input for round equal to round counter
//
CTR_move128bitArray(nonceCounter, encryptionInput);
//
// AES fast encryption
//
AES_performFast(encryptionInput, AES_OPMODE_ENCRYPT);
//
// XOR ciphertext with new plaintext/ciphertext to get final
// ciphertext/plaintext
//
CTR_perform128bitXOR(encryptionInput, roundText, roundText);
//
// Increment counter for next round
//
CTR_incrementCounter(nonceCounter);
//
// Move the final plaintext/ciphertext into text
//
CTR_mergeText(text, roundText , i);
}
}
//
// End of File
//
@@ -0,0 +1,197 @@
//###########################################################################
//
// FILE: aes_ecb.c
//
// TITLE: Implementation of the AES ECB mode
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "aes_ecb.h"
//*****************************************************************************
//
// ECB_splitText - Split text into 128 bit blocks based on blockNumber
//
//*****************************************************************************
void ECB_splitText(uint16_t *text, uint16_t *output, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = text[(16 * blockNumber) + i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = text[(8 * blockNumber) + i];
}
#endif
}
//*****************************************************************************
//
// ECB_move128bitArray - Move input array into output array
//
//*****************************************************************************
void ECB_move128bitArray(uint16_t *input, uint16_t *output)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
output[i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
output[i] = input[i];
}
#endif
}
//*****************************************************************************
//
// ECB_mergeText - Merge final plaintext/ciphertext into text array
//
//*****************************************************************************
void ECB_mergeText(uint16_t *text, uint16_t *input, uint16_t blockNumber)
{
int16_t i;
#ifndef MEM_PACKED_SPEED_OPT
for(i = 0; i < 16; i++)
{
text[(16 * blockNumber) + i] = input[i];
}
#else
for(i = 0; i < 8; i++)
{
text[(8 * blockNumber) + i] = input[i];
}
#endif
}
//*****************************************************************************
//
// AES ECB mode of operation
//
//*****************************************************************************
#ifndef MEM_PACKED_SPEED_OPT
void AES_performECB(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode)
{
//
// Initialize local variables
//
uint16_t currentText[16];
uint16_t i;
//
// Key expansion
//
AES_expandKey(key, keysize);
//
// main loop
//
for(i = 0; i < length; i++)
{
//
// Get 128 bit block of plaintext from array passed in
//
ECB_splitText(text, currentText, i);
//
// AES encryption/decryption
//
AES_perform(currentText, mode);
//
// Move the final plaintext/ciphertext into text
//
ECB_mergeText(text, currentText , i);
}
}
#endif
//*****************************************************************************
//
// AES ECB fast mode of operation
//
//*****************************************************************************
void AES_performECBFast(uint16_t *text, uint16_t length, uint16_t *key,
AES_KeySize keysize, AES_OperationMode mode)
{
//
// Initialize local variables
//
uint16_t currentText[16];
uint16_t i;
//
// Key expansion
//
AES_expandKeyFast(key, keysize, mode);
//
// Main loop
//
for(i = 0; i < length; i++)
{
//
// Get 128 bit block of plaintext from array passed in
//
ECB_splitText(text, currentText, i);
//
// AES fast encryption/decryption
//
AES_performFast(currentText, mode);
//
// Move the final plaintext/ciphertext into text
//
ECB_mergeText(text, currentText , i);
}
}
//
// End of File
//
@@ -0,0 +1,133 @@
MEMORY
{
BEGIN : origin = 0x00080000, length = 0x00000002
BOOT_RSVD : origin = 0x00000002, length = 0x00000126
RAMM0 : origin = 0x00000128, length = 0x000002D8
RAMM1 : origin = 0x00000400, length = 0x000003F8
// RAMM1_RSVD : origin = 0x000007F8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMLS0 : origin = 0x00008000, length = 0x00000800
RAMLS1 : origin = 0x00008800, length = 0x00000800
RAMLS2 : origin = 0x00009000, length = 0x00000800
RAMLS3 : origin = 0x00009800, length = 0x00000800
RAMLS4 : origin = 0x0000A000, length = 0x00000800
RAMLS5 : origin = 0x0000A800, length = 0x00000800
RAMLS6 : origin = 0x0000B000, length = 0x00000800
RAMLS7 : origin = 0x0000B800, length = 0x00000800
RAMGS0 : origin = 0x0000C000, length = 0x00001000
RAMGS1 : origin = 0x0000D000, length = 0x00001000
RAMGS2 : origin = 0x0000E000, length = 0x00001000
RAMGS3 : origin = 0x0000F000, length = 0x00000FF8
// RAMGS3_RSVD : origin = 0x0000FFF8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
BOOTROM : origin = 0x003F8000, length = 0x00007FC0
SECURE_ROM : origin = 0x003F2000, length = 0x00006000
RESET : origin = 0x003FFFC0, length = 0x00000002
/* Flash sectors */
/* BANK 0 */
FLASH_BANK0_SEC0 : origin = 0x080002, length = 0x000FFE
FLASH_BANK0_SEC1 : origin = 0x081000, length = 0x001000
FLASH_BANK0_SEC2 : origin = 0x082000, length = 0x001000
FLASH_BANK0_SEC3 : origin = 0x083000, length = 0x001000
FLASH_BANK0_SEC4 : origin = 0x084000, length = 0x001000
FLASH_BANK0_SEC5 : origin = 0x085000, length = 0x001000
FLASH_BANK0_SEC6 : origin = 0x086000, length = 0x001000
FLASH_BANK0_SEC7 : origin = 0x087000, length = 0x001000
FLASH_BANK0_SEC8 : origin = 0x088000, length = 0x001000
FLASH_BANK0_SEC9 : origin = 0x089000, length = 0x001000
FLASH_BANK0_SEC10 : origin = 0x08A000, length = 0x001000
FLASH_BANK0_SEC11 : origin = 0x08B000, length = 0x001000
FLASH_BANK0_SEC12 : origin = 0x08C000, length = 0x001000
FLASH_BANK0_SEC13 : origin = 0x08D000, length = 0x001000
FLASH_BANK0_SEC14 : origin = 0x08E000, length = 0x001000
FLASH_BANK0_SEC15 : origin = 0x08F000, length = 0x001000
/* BANK 1 */
FLASH_BANK1_SEC0 : origin = 0x090000, length = 0x001000
FLASH_BANK1_SEC1 : origin = 0x091000, length = 0x001000
FLASH_BANK1_SEC2 : origin = 0x092000, length = 0x001000
FLASH_BANK1_SEC3 : origin = 0x093000, length = 0x001000
FLASH_BANK1_SEC4 : origin = 0x094000, length = 0x001000
FLASH_BANK1_SEC5 : origin = 0x095000, length = 0x001000
FLASH_BANK1_SEC6 : origin = 0x096000, length = 0x001000
FLASH_BANK1_SEC7 : origin = 0x097000, length = 0x001000
FLASH_BANK1_SEC8 : origin = 0x098000, length = 0x001000
FLASH_BANK1_SEC9 : origin = 0x099000, length = 0x001000
FLASH_BANK1_SEC10 : origin = 0x09A000, length = 0x001000
FLASH_BANK1_SEC11 : origin = 0x09B000, length = 0x001000
FLASH_BANK1_SEC12 : origin = 0x09C000, length = 0x001000
FLASH_BANK1_SEC13 : origin = 0x09D000, length = 0x001000
FLASH_BANK1_SEC14 : origin = 0x09E000, length = 0x001000
FLASH_BANK1_SEC15 : origin = 0x09F000, length = 0x001000
/* BANK 2 */
FLASH_BANK2_SEC0 : origin = 0x0A0000, length = 0x001000
FLASH_BANK2_SEC1 : origin = 0x0A1000, length = 0x001000
FLASH_BANK2_SEC2 : origin = 0x0A2000, length = 0x001000
FLASH_BANK2_SEC3 : origin = 0x0A3000, length = 0x001000
FLASH_BANK2_SEC4 : origin = 0x0A4000, length = 0x001000
FLASH_BANK2_SEC5 : origin = 0x0A5000, length = 0x001000
FLASH_BANK2_SEC6 : origin = 0x0A6000, length = 0x001000
FLASH_BANK2_SEC7 : origin = 0x0A7000, length = 0x001000
FLASH_BANK2_SEC8 : origin = 0x0A8000, length = 0x001000
FLASH_BANK2_SEC9 : origin = 0x0A9000, length = 0x001000
FLASH_BANK2_SEC10 : origin = 0x0AA000, length = 0x001000
FLASH_BANK2_SEC11 : origin = 0x0AB000, length = 0x001000
FLASH_BANK2_SEC12 : origin = 0x0AC000, length = 0x001000
FLASH_BANK2_SEC13 : origin = 0x0AD000, length = 0x001000
FLASH_BANK2_SEC14 : origin = 0x0AE000, length = 0x001000
FLASH_BANK2_SEC15 : origin = 0x0AF000, length = 0x000FF0
// FLASH_BANK0_SEC15_RSVD : origin = 0x0AFFF0, length = 0x000010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
}
SECTIONS
{
codestart : > BEGIN, ALIGN(8)
.text : >> FLASH_BANK0_SEC2 | FLASH_BANK0_SEC3 | FLASH_BANK0_SEC4, ALIGN(8)
.cinit : > FLASH_BANK0_SEC1, ALIGN(8)
.switch : > FLASH_BANK0_SEC1, ALIGN(8)
.reset : > RESET, TYPE = DSECT /* not used, */
.stack : > RAMM1
#if defined(__TI_EABI__)
.init_array : > FLASH_BANK0_SEC1, ALIGN(8)
.bss : > RAMLS5
.bss:output : > RAMLS3
.bss:cio : > RAMLS0
.data : > RAMLS5
.sysmem : > RAMLS5
.const : > FLASH_BANK0_SEC4, ALIGN(8)
#else
.pinit : > FLASH_BANK0_SEC1, ALIGN(8)
.ebss : > RAMLS5
.esysmem : > RAMLS5
.cio : > RAMLS0
.econst : > FLASH_BANK0_SEC4, ALIGN(8)
#endif
ramgs0 : > RAMGS0
ramgs1 : > RAMGS0
/* Allocate IQ math areas: */
IQmath : > FLASH_BANK0_SEC1, ALIGN(8)
IQmathTables : > FLASH_BANK0_SEC2, ALIGN(8)
.TI.ramfunc : LOAD = FLASH_BANK0_SEC1,
RUN = RAMLS0,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
ALIGN(8)
}
@@ -0,0 +1,130 @@
MEMORY
{
BEGIN : origin = 0x00000000, length = 0x00000002
BOOT_RSVD : origin = 0x00000002, length = 0x00000126
RAMM0 : origin = 0x00000128, length = 0x000002D8
RAMM1 : origin = 0x00000400, length = 0x000003F8
// RAMM1_RSVD : origin = 0x000007F8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMLS0 : origin = 0x00008000, length = 0x00000800
RAMLS1 : origin = 0x00008800, length = 0x00000800
RAMLS2 : origin = 0x00009000, length = 0x00000800
RAMLS3 : origin = 0x00009800, length = 0x00000800
RAMLS4 : origin = 0x0000A000, length = 0x00000800
RAMLS5 : origin = 0x0000A800, length = 0x00000800
RAMLS6_7 : origin = 0x0000B000, length = 0x00001000
// RAMLS7 : origin = 0x0000B800, length = 0x00000800
RAMGS0 : origin = 0x0000C000, length = 0x00001000
RAMGS1 : origin = 0x0000D000, length = 0x00001000
RAMGS2 : origin = 0x0000E000, length = 0x00001000
RAMGS3 : origin = 0x0000F000, length = 0x00000FF8
// RAMGS3_RSVD : origin = 0x0000FFF8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
BOOTROM : origin = 0x003F8000, length = 0x00007FC0
SECURE_ROM : origin = 0x003F2000, length = 0x00006000
RESET : origin = 0x003FFFC0, length = 0x00000002
/* Flash sectors */
/* BANK 0 */
FLASH_BANK0_SEC0 : origin = 0x080002, length = 0x000FFE
FLASH_BANK0_SEC1 : origin = 0x081000, length = 0x001000
FLASH_BANK0_SEC2 : origin = 0x082000, length = 0x001000
FLASH_BANK0_SEC3 : origin = 0x083000, length = 0x001000
FLASH_BANK0_SEC4 : origin = 0x084000, length = 0x001000
FLASH_BANK0_SEC5 : origin = 0x085000, length = 0x001000
FLASH_BANK0_SEC6 : origin = 0x086000, length = 0x001000
FLASH_BANK0_SEC7 : origin = 0x087000, length = 0x001000
FLASH_BANK0_SEC8 : origin = 0x088000, length = 0x001000
FLASH_BANK0_SEC9 : origin = 0x089000, length = 0x001000
FLASH_BANK0_SEC10 : origin = 0x08A000, length = 0x001000
FLASH_BANK0_SEC11 : origin = 0x08B000, length = 0x001000
FLASH_BANK0_SEC12 : origin = 0x08C000, length = 0x001000
FLASH_BANK0_SEC13 : origin = 0x08D000, length = 0x001000
FLASH_BANK0_SEC14 : origin = 0x08E000, length = 0x001000
FLASH_BANK0_SEC15 : origin = 0x08F000, length = 0x001000
/* BANK 1 */
FLASH_BANK1_SEC0 : origin = 0x090000, length = 0x001000
FLASH_BANK1_SEC1 : origin = 0x091000, length = 0x001000
FLASH_BANK1_SEC2 : origin = 0x092000, length = 0x001000
FLASH_BANK1_SEC3 : origin = 0x093000, length = 0x001000
FLASH_BANK1_SEC4 : origin = 0x094000, length = 0x001000
FLASH_BANK1_SEC5 : origin = 0x095000, length = 0x001000
FLASH_BANK1_SEC6 : origin = 0x096000, length = 0x001000
FLASH_BANK1_SEC7 : origin = 0x097000, length = 0x001000
FLASH_BANK1_SEC8 : origin = 0x098000, length = 0x001000
FLASH_BANK1_SEC9 : origin = 0x099000, length = 0x001000
FLASH_BANK1_SEC10 : origin = 0x09A000, length = 0x001000
FLASH_BANK1_SEC11 : origin = 0x09B000, length = 0x001000
FLASH_BANK1_SEC12 : origin = 0x09C000, length = 0x001000
FLASH_BANK1_SEC13 : origin = 0x09D000, length = 0x001000
FLASH_BANK1_SEC14 : origin = 0x09E000, length = 0x001000
FLASH_BANK1_SEC15 : origin = 0x09F000, length = 0x001000
/* BANK 2 */
FLASH_BANK2_SEC0 : origin = 0x0A0000, length = 0x001000
FLASH_BANK2_SEC1 : origin = 0x0A1000, length = 0x001000
FLASH_BANK2_SEC2 : origin = 0x0A2000, length = 0x001000
FLASH_BANK2_SEC3 : origin = 0x0A3000, length = 0x001000
FLASH_BANK2_SEC4 : origin = 0x0A4000, length = 0x001000
FLASH_BANK2_SEC5 : origin = 0x0A5000, length = 0x001000
FLASH_BANK2_SEC6 : origin = 0x0A6000, length = 0x001000
FLASH_BANK2_SEC7 : origin = 0x0A7000, length = 0x001000
FLASH_BANK2_SEC8 : origin = 0x0A8000, length = 0x001000
FLASH_BANK2_SEC9 : origin = 0x0A9000, length = 0x001000
FLASH_BANK2_SEC10 : origin = 0x0AA000, length = 0x001000
FLASH_BANK2_SEC11 : origin = 0x0AB000, length = 0x001000
FLASH_BANK2_SEC12 : origin = 0x0AC000, length = 0x001000
FLASH_BANK2_SEC13 : origin = 0x0AD000, length = 0x001000
FLASH_BANK2_SEC14 : origin = 0x0AE000, length = 0x001000
FLASH_BANK2_SEC15 : origin = 0x0AF000, length = 0x000FF0
// FLASH_BANK0_SEC15_RSVD : origin = 0x0AFFF0, length = 0x000010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
}
SECTIONS
{
codestart : > BEGIN
.TI.ramfunc : > RAMM0
.text : >> RAMLS0 | RAMLS1 | RAMLS2 | RAMLS3 | RAMLS4
.cinit : > RAMM0 | RAMM1
.switch : > RAMM0
.reset : > RESET, TYPE = DSECT /* not used, */
.stack : > RAMM1
#if defined(__TI_EABI__)
.bss : > RAMLS5
.bss:output : > RAMLS5
.init_array : > RAMM0
.const : > RAMLS5 | RAMLS4
.data : > RAMLS5
.sysmem : > RAMLS5
.bss:cio : > RAMLS0
#else
.pinit : > RAMM0
.ebss : > RAMLS5
.econst : > RAMLS5
.esysmem : > RAMLS5
.cio : > RAMLS0
#endif
ramgs0 : > RAMGS0
ramgs1 : > RAMGS1
/* The following section definition are for SDFM examples */
Filter1_RegsFile : > RAMLS6_7
Filter2_RegsFile : > RAMLS6_7
Filter3_RegsFile : > RAMLS6_7
Filter4_RegsFile : > RAMLS6_7
/* Allocate IQ math areas: */
IQmath : > RAMLS6_7
IQmathTables : > RAMLS6_7
}
@@ -0,0 +1,133 @@
MEMORY
{
PAGE 0 :
/* BEGIN is used for the "boot to Flash" bootloader mode */
BEGIN : origin = 0x080000, length = 0x000002
RAMM0 : origin = 0x0000F6, length = 0x00030A
RAMLS0 : origin = 0x008000, length = 0x000800
RAMLS1 : origin = 0x008800, length = 0x000800
RAMLS2 : origin = 0x009000, length = 0x000800
RAMLS3 : origin = 0x009800, length = 0x000800
RAMLS4 : origin = 0x00A000, length = 0x000800
RESET : origin = 0x3FFFC0, length = 0x000002
/* Flash sectors */
/* BANK 0 */
FLASH_BANK0_SEC0 : origin = 0x080002, length = 0x000FFE /* on-chip Flash */
FLASH_BANK0_SEC1 : origin = 0x081000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC2_5 : origin = 0x082000, length = 0x004000 /* on-chip Flash */
// FLASH_BANK0_SEC3 : origin = 0x083000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC4 : origin = 0x084000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC5 : origin = 0x085000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC6 : origin = 0x086000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC7_10 : origin = 0x087000, length = 0x004000 /* on-chip Flash */
// FLASH_BANK0_SEC8 : origin = 0x088000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC9 : origin = 0x089000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC10 : origin = 0x08A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC11 : origin = 0x08B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC12 : origin = 0x08C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC13 : origin = 0x08D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC14 : origin = 0x08E000, length = 0x002000 /* on-chip Flash */
// FLASH_BANK0_SEC15 : origin = 0x08F000, length = 0x001000 /* on-chip Flash */
/* BANK 1 */
FLASH_BANK1_SEC0 : origin = 0x090000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC1 : origin = 0x091000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC2 : origin = 0x092000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC3 : origin = 0x093000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC4 : origin = 0x094000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC5 : origin = 0x095000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC6 : origin = 0x096000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC7 : origin = 0x097000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC8 : origin = 0x098000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC9 : origin = 0x099000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC10 : origin = 0x09A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC11 : origin = 0x09B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC12 : origin = 0x09C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC13 : origin = 0x09D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC14 : origin = 0x09E000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC15 : origin = 0x09F000, length = 0x000FF0 /* on-chip Flash */
// FLASH_BANK1_SEC15_RSVD : origin = 0x09FFF0, length = 0x000010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
PAGE 1 :
BOOT_RSVD : origin = 0x000002, length = 0x0000F1 /* Part of M0, BOOT rom will use this for stack */
RAMM1 : origin = 0x000400, length = 0x0003F8 /* on-chip RAM block M1 */
// RAMM1_RSVD : origin = 0x0007F8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMLS5 : origin = 0x00A800, length = 0x001000
// RAMLS6 : origin = 0x00B000, length = 0x000800
RAMLS7 : origin = 0x00B800, length = 0x000800
RAMGS0 : origin = 0x00C000, length = 0x002000
RAMGS1 : origin = 0x00E000, length = 0x002000
RAMGS2 : origin = 0x010000, length = 0x002000
RAMGS3 : origin = 0x012000, length = 0x001FF8
// RAMGS3_RSVD : origin = 0x013FF8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
}
SECTIONS
{
codestart : > BEGIN, PAGE = 0, ALIGN(4)
.text : >> FLASH_BANK0_SEC2_5, PAGE = 0, ALIGN(4)
.cinit : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.switch : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */
.stack : > RAMM1, PAGE = 1
#if defined(__TI_EABI__)
.init_array : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.bss : > RAMLS7, PAGE = 1
.bss:output : > RAMLS3, PAGE = 0
.bss:cio : > RAMLS0, PAGE = 0
.data : > RAMGS1, PAGE = 1
.sysmem : > RAMGS2, PAGE = 1
/* Initalized sections go in Flash */
.const : > FLASH_BANK0_SEC7_10, PAGE = 0, ALIGN(4)
#else
.pinit : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.ebss : > RAMLS5, PAGE = 1
.esysmem : > RAMGS2, PAGE = 1
.cio : > RAMLS0, PAGE = 0
.econst : > FLASH_BANK0_SEC14, PAGE = 0, ALIGN(4)
#endif
ramgs0 : > RAMGS0, PAGE = 1
ramgs1 : > RAMGS1, PAGE = 1
#if defined(__TI_EABI__)
.TI.ramfunc : LOAD = FLASH_BANK0_SEC1,
RUN = RAMLS0,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
#else
.TI.ramfunc : LOAD = FLASH_BANK0_SEC1,
RUN = RAMLS0,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
#endif
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
@@ -0,0 +1,153 @@
MEMORY
{
PAGE 0 :
RAMM0 : origin = 0x0000F5, length = 0x00030B
RAMLS0 : origin = 0x008000, length = 0x000800
RAMLS1 : origin = 0x008800, length = 0x000800
RAMLS2 : origin = 0x009000, length = 0x000800
RAMLS3 : origin = 0x009800, length = 0x001600
//RAMLS4 : origin = 0x00A000, length = 0x000800
RESET : origin = 0x3FFFC0, length = 0x000002
#ifdef __TI_COMPILER_VERSION__
#if __TI_COMPILER_VERSION__ >= 20012000
GROUP { /* GROUP memory ranges for crc/checksum of entire flash */
#endif
#endif
/* BEGIN is used for the "boot to Flash" bootloader mode */
BEGIN : origin = 0x080000, length = 0x000002
/* Flash sectors */
/* BANK 0 */
FLASH_BANK0 : origin = 0x080002, length = 0x00FFFE
//FLASH_BANK0_SEC0 : origin = 0x080002, length = 0x000FFE /* on-chip Flash */
//FLASH_BANK0_SEC1 : origin = 0x081000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC2 : origin = 0x082000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC3 : origin = 0x083000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC4 : origin = 0x084000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC5 : origin = 0x085000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC6 : origin = 0x086000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC7 : origin = 0x087000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC8 : origin = 0x088000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC9 : origin = 0x089000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC10 : origin = 0x08A000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC11 : origin = 0x08B000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC12 : origin = 0x08C000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC13 : origin = 0x08D000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC14 : origin = 0x08E000, length = 0x001000 /* on-chip Flash */
//FLASH_BANK0_SEC15 : origin = 0x08F000, length = 0x001000 /* on-chip Flash */
/* BANK 1 */
FLASH_BANK1_SEC0 : origin = 0x090000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC1 : origin = 0x091000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC2 : origin = 0x092000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC3 : origin = 0x093000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC4 : origin = 0x094000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC5 : origin = 0x095000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC6 : origin = 0x096000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC7 : origin = 0x097000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC8 : origin = 0x098000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC9 : origin = 0x099000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC10 : origin = 0x09A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC11 : origin = 0x09B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC12 : origin = 0x09C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC13 : origin = 0x09D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC14 : origin = 0x09E000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC15 : origin = 0x09F000, length = 0x000FF0 /* on-chip Flash */
FLASH_BANK1_SEC15_DO_NOT_USE : origin = 0x09FFF0, length = 0x000010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
#ifdef __TI_COMPILER_VERSION__
#if __TI_COMPILER_VERSION__ >= 20012000
} crc(_ccs_flash_checksum, algorithm=C28_CHECKSUM_16)
#endif
#endif
PAGE 1 :
BOOT_RSVD : origin = 0x000002, length = 0x0000F3 /* Part of M0, BOOT rom will use this for stack */
RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */
RAMLS5 : origin = 0x00A800, length = 0x000800
RAMLS6 : origin = 0x00B000, length = 0x000800
RAMLS7 : origin = 0x00B800, length = 0x000800
RAMGS0 : origin = 0x00C000, length = 0x002000
RAMGS1 : origin = 0x00E000, length = 0x002000
RAMGS2 : origin = 0x010000, length = 0x002000
RAMGS3 : origin = 0x012000, length = 0x002000
}
SECTIONS
{
codestart : > BEGIN, PAGE = 0, ALIGN(4)
.text : > FLASH_BANK0, PAGE = 0, ALIGN(4)
.pinit : > RAMGS2, PAGE = 1
.switch : > RAMGS2, PAGE = 1
.cinit : > FLASH_BANK0, PAGE = 0, ALIGN(8)
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */
.stack : > RAMGS1, PAGE = 1
.bss : >> RAMLS5 | RAMGS0, PAGE = 1
.sysmem : > RAMGS3 , PAGE = 1
.const : >> RAMLS5 | RAMLS6 | RAMGS0, PAGE = 1
.data : >> RAMLS0 | RAMLS1 | RAMLS2 | RAMLS3, PAGE = 0
#if defined(__TI_EABI__)
.init_array : > FLASH_BANK0, PAGE = 0, ALIGN(4)
.bss : > RAMLS5, PAGE = 1
.bss:output : > RAMLS3, PAGE = 0
.bss:cio : > RAMLS0, PAGE = 0
.data : > RAMLS5, PAGE = 1
.sysmem : > RAMLS6 | RAMLS7, PAGE = 1
/* Initalized sections go in Flash */
.const : > FLASH_BANK1_SEC4, PAGE = 0, ALIGN(4)
#else
.pinit : > FLASH_BANK0, PAGE = 0, ALIGN(4)
.ebss : > RAMLS5, PAGE = 1
.esysmem : > RAMLS5, PAGE = 1
.cio : > RAMLS0, PAGE = 0
.econst : > FLASH_BANK1, PAGE = 0, ALIGN(4)
#endif
ramgs0 : > RAMGS0, PAGE = 1
ramgs1 : > RAMGS1, PAGE = 1
#if defined(__TI_EABI__)
.TI.ramfunc : LOAD = FLASH_BANK0,
RUN = RAMLS0,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
#else
.TI.ramfunc : LOAD = FLASH_BANK0_SEC1,
RUN = RAMLS0,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
#endif
/* crc/checksum section configured as COPY section to avoid including in executable */
.TI.memcrc : type = COPY
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
@@ -0,0 +1,133 @@
MEMORY
{
PAGE 0 :
/* BEGIN is used for the "boot to Flash" bootloader mode */
BEGIN : origin = 0x080000, length = 0x000002
RAMM0 : origin = 0x0000F6, length = 0x00030A
RAMLS0 : origin = 0x008000, length = 0x000800
RAMLS1 : origin = 0x008800, length = 0x000800
RAMLS2 : origin = 0x009000, length = 0x000800
RAMLS3 : origin = 0x009800, length = 0x000800
RAMLS4 : origin = 0x00A000, length = 0x000800
RESET : origin = 0x3FFFC0, length = 0x000002
/* Flash sectors */
/* BANK 0 */
FLASH_BANK0_SEC0 : origin = 0x080002, length = 0x000FFE /* on-chip Flash */
FLASH_BANK0_SEC1 : origin = 0x081000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC2_5 : origin = 0x082000, length = 0x004000 /* on-chip Flash */
// FLASH_BANK0_SEC3 : origin = 0x083000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC4 : origin = 0x084000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC5 : origin = 0x085000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC6 : origin = 0x086000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC7_10 : origin = 0x087000, length = 0x004000 /* on-chip Flash */
// FLASH_BANK0_SEC8 : origin = 0x088000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC9 : origin = 0x089000, length = 0x001000 /* on-chip Flash */
// FLASH_BANK0_SEC10 : origin = 0x08A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC11 : origin = 0x08B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC12 : origin = 0x08C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC13 : origin = 0x08D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC14 : origin = 0x08E000, length = 0x002000 /* on-chip Flash */
// FLASH_BANK0_SEC15 : origin = 0x08F000, length = 0x001000 /* on-chip Flash */
/* BANK 1 */
FLASH_BANK1_SEC0 : origin = 0x090000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC1 : origin = 0x091000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC2 : origin = 0x092000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC3 : origin = 0x093000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC4 : origin = 0x094000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC5 : origin = 0x095000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC6 : origin = 0x096000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC7 : origin = 0x097000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC8 : origin = 0x098000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC9 : origin = 0x099000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC10 : origin = 0x09A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC11 : origin = 0x09B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC12 : origin = 0x09C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC13 : origin = 0x09D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC14 : origin = 0x09E000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC15 : origin = 0x09F000, length = 0x000FF0 /* on-chip Flash */
// FLASH_BANK1_SEC15_RSVD : origin = 0x09FFF0, length = 0x000010 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
PAGE 1 :
BOOT_RSVD : origin = 0x000002, length = 0x0000F1 /* Part of M0, BOOT rom will use this for stack */
RAMM1 : origin = 0x000400, length = 0x0003F8 /* on-chip RAM block M1 */
// RAMM1_RSVD : origin = 0x0007F8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMLS5 : origin = 0x00A800, length = 0x000800
RAMLS6 : origin = 0x00B000, length = 0x000800
RAMLS7 : origin = 0x00B800, length = 0x000800
RAMGS0 : origin = 0x00C000, length = 0x002000
RAMGS1 : origin = 0x00E000, length = 0x002000
RAMGS2 : origin = 0x010000, length = 0x002000
RAMGS3 : origin = 0x012000, length = 0x001FF8
// RAMGS3_RSVD : origin = 0x013FF8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
}
SECTIONS
{
codestart : > BEGIN, PAGE = 0, ALIGN(4)
.text : >> FLASH_BANK0_SEC2_5, PAGE = 0, ALIGN(4)
.cinit : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.switch : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */
.stack : > RAMM1, PAGE = 1
#if defined(__TI_EABI__)
.init_array : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.bss : > RAMLS5, PAGE = 1
.bss:output : > RAMLS3, PAGE = 0
.bss:cio : > RAMLS0, PAGE = 0
.data : > RAMLS5, PAGE = 1
.sysmem : > RAMLS5, PAGE = 1
/* Initalized sections go in Flash */
.const : > FLASH_BANK0_SEC7_10, PAGE = 0, ALIGN(4)
#else
.pinit : > FLASH_BANK0_SEC1, PAGE = 0, ALIGN(4)
.ebss : > RAMLS5, PAGE = 1
.esysmem : > RAMLS5, PAGE = 1
.cio : > RAMLS0, PAGE = 0
.econst : > FLASH_BANK0_SEC14, PAGE = 0, ALIGN(4)
#endif
ramgs0 : > RAMGS0, PAGE = 1
ramgs1 : > RAMGS1, PAGE = 1
#if defined(__TI_EABI__)
.TI.ramfunc : LOAD = FLASH_BANK0_SEC1,
RUN = RAMLS0,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
#else
.TI.ramfunc : LOAD = FLASH_BANK0_SEC1,
RUN = RAMLS0,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
PAGE = 0, ALIGN(4)
#endif
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
@@ -0,0 +1,107 @@
MEMORY
{
PAGE 0 :
/* BEGIN is used for the "boot to SARAM" bootloader mode */
BEGIN : origin = 0x000000, length = 0x000002
RAMM0 : origin = 0x0000F6, length = 0x00030A
RAMLS0 : origin = 0x008000, length = 0x002800
// RAMLS1 : origin = 0x008800, length = 0x000800
// RAMLS2 : origin = 0x009000, length = 0x000800
// RAMLS3 : origin = 0x009800, length = 0x000800
// RAMLS4 : origin = 0x00A000, length = 0x000800
RESET : origin = 0x3FFFC0, length = 0x000002
/* Flash sectors: you can use FLASH for program memory when the RAM is filled up*/
/* BANK 0 */
FLASH_BANK0_SEC0 : origin = 0x080000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC1 : origin = 0x081000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC2 : origin = 0x082000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC3 : origin = 0x083000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC4 : origin = 0x084000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC5 : origin = 0x085000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC6 : origin = 0x086000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC7 : origin = 0x087000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC8 : origin = 0x088000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC9 : origin = 0x089000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC10 : origin = 0x08A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC11 : origin = 0x08B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC12 : origin = 0x08C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC13 : origin = 0x08D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC14 : origin = 0x08E000, length = 0x001000 /* on-chip Flash */
FLASH_BANK0_SEC15 : origin = 0x08F000, length = 0x001000 /* on-chip Flash */
/* BANK 1 */
FLASH_BANK1_SEC0 : origin = 0x090000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC1 : origin = 0x091000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC2 : origin = 0x092000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC3 : origin = 0x093000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC4 : origin = 0x094000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC5 : origin = 0x095000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC6 : origin = 0x096000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC7 : origin = 0x097000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC8 : origin = 0x098000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC9 : origin = 0x099000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC10 : origin = 0x09A000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC11 : origin = 0x09B000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC12 : origin = 0x09C000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC13 : origin = 0x09D000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC14 : origin = 0x09E000, length = 0x001000 /* on-chip Flash */
FLASH_BANK1_SEC15 : origin = 0x09F000, length = 0x001000 /* on-chip Flash */
PAGE 1 :
BOOT_RSVD : origin = 0x000002, length = 0x0000F1 /* Part of M0, BOOT rom will use this for stack */
RAMM1 : origin = 0x000400, length = 0x0003F8 /* on-chip RAM block M1 */
// RAMM1_RSVD : origin = 0x0007F8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMLS5 : origin = 0x00A800, length = 0x000800
RAMLS6 : origin = 0x00B000, length = 0x000800
RAMLS7 : origin = 0x00B800, length = 0x000800
RAMGS0 : origin = 0x00C000, length = 0x002000
RAMGS1 : origin = 0x00E000, length = 0x004000
// RAMGS2 : origin = 0x010000, length = 0x002000
RAMGS3 : origin = 0x012000, length = 0x001FF8
// RAMGS3_RSVD : origin = 0x013FF8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
}
/*You can arrange the .text, .cinit, .const, .pinit, .switch and .econst to FLASH when RAM is filled up.*/
SECTIONS
{
codestart : > BEGIN, PAGE = 0
.TI.ramfunc : > RAMM0, PAGE = 0
.text : >> RAMGS1, PAGE = 1
.cinit : > RAMM0, PAGE = 0
.switch : > RAMM0, PAGE = 0
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used, */
.stack : > RAMM1, PAGE = 1
#if defined(__TI_EABI__)
.bss : > RAMLS5, PAGE = 1
.bss:output : > RAMLS5, PAGE = 1
.init_array : > RAMM0, PAGE = 0
.const : > RAMLS0, PAGE = 0
.data : > RAMLS5, PAGE = 1
.sysmem : > RAMGS3, PAGE = 1
.bss:cio : > RAMLS0, PAGE = 0
#else
.pinit : > RAMM0, PAGE = 0
.ebss : > RAMLS5, PAGE = 1
.econst : > RAMLS5, PAGE = 1
.esysmem : > RAMLS5, PAGE = 1
.cio : > RAMLS0, PAGE = 0
#endif
ramgs0 : > RAMGS0, PAGE = 1
ramgs1 : > RAMGS1, PAGE = 1
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
@@ -0,0 +1,109 @@
MEMORY
{
/* BEGIN is used for the "boot to SARAM" bootloader mode */
BEGIN : origin = 0x000000, length = 0x000002
BOOT_RSVD : origin = 0x000002, length = 0x0001AF /* Part of M0, BOOT rom will use this for stack */
RAMM0 : origin = 0x0001B1, length = 0x00024F
RAMM1 : origin = 0x000400, length = 0x0003F8 /* on-chip RAM block M1 */
// RAMM1_RSVD : origin = 0x0007F8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMD0 : origin = 0x00C000, length = 0x000800
RAMD1 : origin = 0x00C800, length = 0x000800
RAMLS0 : origin = 0x008000, length = 0x000800
RAMLS1 : origin = 0x008800, length = 0x000800
RAMLS2 : origin = 0x009000, length = 0x000800
RAMLS3 : origin = 0x009800, length = 0x000800
RAMLS4 : origin = 0x00A000, length = 0x000800
RAMLS5 : origin = 0x00A800, length = 0x001800
RAMGS0 : origin = 0x00D000, length = 0x001000
RAMGS1 : origin = 0x00E000, length = 0x001000
RAMGS2 : origin = 0x00F000, length = 0x001000
RAMGS3 : origin = 0x010000, length = 0x001000
RAMGS4 : origin = 0x011000, length = 0x001000
RAMGS5 : origin = 0x012000, length = 0x001000
RAMGS6 : origin = 0x013000, length = 0x001000
RAMGS7 : origin = 0x014000, length = 0x001000
RAMGS8 : origin = 0x015000, length = 0x001000
RAMGS9 : origin = 0x016000, length = 0x001000
RAMGS10 : origin = 0x017000, length = 0x001000
RAMGS11 : origin = 0x018000, length = 0x001000
RAMGS12 : origin = 0x019000, length = 0x001000
RAMGS13 : origin = 0x01A000, length = 0x001000
RAMGS14 : origin = 0x01B000, length = 0x001000
RAMGS15 : origin = 0x01C000, length = 0x000FF8
// RAMGS15_RSVD : origin = 0x01CFF8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
/* Flash sectors */
FLASH0 : origin = 0x080000, length = 0x002000 /* on-chip Flash */
FLASH1 : origin = 0x082000, length = 0x002000 /* on-chip Flash */
FLASH2 : origin = 0x084000, length = 0x002000 /* on-chip Flash */
FLASH3 : origin = 0x086000, length = 0x002000 /* on-chip Flash */
FLASH4 : origin = 0x088000, length = 0x008000 /* on-chip Flash */
FLASH5 : origin = 0x090000, length = 0x008000 /* on-chip Flash */
FLASH6 : origin = 0x098000, length = 0x008000 /* on-chip Flash */
FLASH7 : origin = 0x0A0000, length = 0x008000 /* on-chip Flash */
FLASH8 : origin = 0x0A8000, length = 0x008000 /* on-chip Flash */
FLASH9 : origin = 0x0B0000, length = 0x008000 /* on-chip Flash */
FLASH10 : origin = 0x0B8000, length = 0x002000 /* on-chip Flash */
FLASH11 : origin = 0x0BA000, length = 0x002000 /* on-chip Flash */
FLASH12 : origin = 0x0BC000, length = 0x002000 /* on-chip Flash */
FLASH13 : origin = 0x0BE000, length = 0x002000 /* on-chip Flash */
CPU1TOCPU2RAM : origin = 0x03A000, length = 0x000800
CPU2TOCPU1RAM : origin = 0x03B000, length = 0x000800
CPUTOCMRAM : origin = 0x039000, length = 0x000800
CMTOCPURAM : origin = 0x038000, length = 0x000800
CANA_MSG_RAM : origin = 0x049000, length = 0x000800
CANB_MSG_RAM : origin = 0x04B000, length = 0x000800
RESET : origin = 0x3FFFC0, length = 0x000002
}
SECTIONS
{
codestart : > BEGIN
.text : >> RAMD0 | RAMD1 | RAMLS0 | RAMLS1 | RAMLS2 | RAMLS3
.cinit : > RAMM0
.switch : > RAMM0
.reset : > RESET, TYPE = DSECT /* not used, */
.stack : > RAMM1
#if defined(__TI_EABI__)
.bss : > RAMLS5
.bss:output : > RAMLS3
.init_array : > RAMM0
.const : > RAMLS5
.data : > RAMLS5
.sysmem : > RAMLS4
#else
.pinit : > RAMM0
.ebss : >> RAMLS5 | RAMLS6
.econst : > RAMLS5
.esysmem : > RAMLS5
#endif
ramgs0 : > RAMGS0, type=NOINIT
ramgs1 : > RAMGS1, type=NOINIT
MSGRAM_CPU1_TO_CPU2 > CPU1TOCPU2RAM, type=NOINIT
MSGRAM_CPU2_TO_CPU1 > CPU2TOCPU1RAM, type=NOINIT
MSGRAM_CPU_TO_CM > CPUTOCMRAM, type=NOINIT
MSGRAM_CM_TO_CPU > CMTOCPURAM, type=NOINIT
/* The following section definition are for SDFM examples */
Filter_RegsFile : > RAMGS0
Filter1_RegsFile : > RAMGS1, fill=0x1111
Filter2_RegsFile : > RAMGS2, fill=0x2222
Filter3_RegsFile : > RAMGS3, fill=0x3333
Filter4_RegsFile : > RAMGS4, fill=0x4444
Difference_RegsFile : >RAMGS5, fill=0x3333
.TI.ramfunc : {} > RAMM0
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
@@ -0,0 +1,131 @@
MEMORY
{
BOOT_RSVD : origin = 0x000002, length = 0x0001AF /* Part of M0, BOOT rom will use this for stack */
RAMM0 : origin = 0x0001B1, length = 0x00024F
RAMM1 : origin = 0x00000400, length = 0x000003F8 /* on-chip RAM block M1 */
// RAMM1_RSVD : origin = 0x000007F8, length = 0x00000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */
RAMD0 : origin = 0x00C000, length = 0x002000
RAMD1 : origin = 0x00E000, length = 0x002000
RAMD2 : origin = 0x01A000, length = 0x002000 // Can be mapped to either CPU1 or CPU2. When configured to CPU2, use the address 0x8000. User should comment/uncomment based on core selection
RAMD3 : origin = 0x01C000, length = 0x002000 // Can be mapped to either CPU1 or CPU2. When configured to CPU2, use the address 0xA000. User should comment/uncomment based on core selection
RAMD4 : origin = 0x01E000, length = 0x002000 // Can be mapped to either CPU1 or CPU2. When configured to CPU2, use the address 0xC000. User should comment/uncomment based on core selection
RAMD5 : origin = 0x020000, length = 0x002000 // Can be mapped to either CPU1 or CPU2. When configured to CPU2, use the address 0xE000. User should comment/uncomment based on core selection
RAMLS0 : origin = 0x008000, length = 0x000800
RAMLS1 : origin = 0x008800, length = 0x000800
RAMLS2 : origin = 0x009000, length = 0x000800
RAMLS3 : origin = 0x009800, length = 0x000800
RAMLS4 : origin = 0x00A000, length = 0x000800
RAMLS5 : origin = 0x00A800, length = 0x000800
RAMLS6 : origin = 0x00B000, length = 0x000800
RAMLS7 : origin = 0x00B800, length = 0x000800
RAMLS8 : origin = 0x022000, length = 0x002000 // When configured as CLA program use the address 0x4000
RAMLS9 : origin = 0x024000, length = 0x002000 // When configured as CLA program use the address 0x6000
// RAMLS8_CLA : origin = 0x004000, length = 0x002000 // Use only if configured as CLA program memory
// RAMLS9_CLA : origin = 0x006000, length = 0x002000 // Use only if configured as CLA program memory
RAMGS0 : origin = 0x010000, length = 0x00A000
//RAMGS1 : origin = 0x012000, length = 0x002000
//RAMGS2 : origin = 0x014000, length = 0x002000
//RAMGS3 : origin = 0x016000, length = 0x004000
//RAMGS4 : origin = 0x018000, length = 0x002000
CPU1TOCPU2RAM : origin = 0x03A000, length = 0x000400
CPU2TOCPU1RAM : origin = 0x03B000, length = 0x000400
CLATOCPURAM : origin = 0x001480, length = 0x000080
CPUTOCPURAM : origin = 0x001500, length = 0x000080
CLATODMARAM : origin = 0x001680, length = 0x000080
DMATOCLARAM : origin = 0x001700, length = 0x000080
ETHERCAT_RAM : origin = 0x030800, length = 0x002000
USB_RAM : origin = 0x041000, length = 0x000800
CANA_MSG_RAM : origin = 0x049000, length = 0x000800
CANB_MSG_RAM : origin = 0x04B000, length = 0x000800
RESET : origin = 0x3FFFC0, length = 0x000002
#ifdef __TI_COMPILER_VERSION__
#if __TI_COMPILER_VERSION__ >= 20012000
GROUP { /* GROUP memory ranges for crc/checksum of entire flash */
#endif
#endif
/* BEGIN is used for the "boot to Flash" bootloader mode */
BEGIN : origin = 0x080000, length = 0x000002 // Update the codestart location as needed
/* Flash Banks (128 sectors each) */
FLASH_BANK0 : origin = 0x080002, length = 0x1FFFE // Can be mapped to either CPU1 or CPU2. User should comment/uncomment based on core selection
FLASH_BANK1 : origin = 0x0A0000, length = 0x20000 // Can be mapped to either CPU1 or CPU2. User should comment/uncomment based on core selection
FLASH_BANK2 : origin = 0x0C0000, length = 0x20000 // Can be mapped to either CPU1 or CPU2. User should comment/uncomment based on core selection
FLASH_BANK3 : origin = 0x0E0000, length = 0x20000 // Can be mapped to either CPU1 or CPU2. User should comment/uncomment based on core selection
FLASH_BANK4 : origin = 0x100000, length = 0x20000 // Can be mapped to either CPU1 or CPU2. User should comment/uncomment based on core selection
#ifdef __TI_COMPILER_VERSION__
#if __TI_COMPILER_VERSION__ >= 20012000
} crc(_ccs_flash_checksum, algorithm=C28_CHECKSUM_16)
#endif
#endif
}
SECTIONS
{
codestart : > BEGIN
.text : >> FLASH_BANK0 | FLASH_BANK1, ALIGN(8)
.cinit : > FLASH_BANK0, ALIGN(8)
.switch : > FLASH_BANK0, ALIGN(8)
.reset : > RESET, TYPE = DSECT /* not used, */
.stack : > RAMD0
#if defined(__TI_EABI__)
.bss : > RAMLS5
.bss:output : > RAMLS3
.init_array : > FLASH_BANK0, ALIGN(8)
.const : > FLASH_BANK0, ALIGN(8)
.data : > RAMGS0
.sysmem : > RAMD1, ALIGN(8)
#else
.pinit : > FLASH_BANK0, ALIGN(8)
.ebss : >> RAMLS5 | RAMLS6
.econst : > FLASH_BANK0, ALIGN(8)
.esysmem : > RAMGS0 , ALIGN(8)
#endif
ramgs0 : > RAMGS0, type=NOINIT
//ramgs1 : > RAMGS1, type=NOINIT
#if defined(__TI_EABI__)
.TI.ramfunc : {} LOAD = FLASH_BANK0,
RUN = RAMLS0,
LOAD_START(RamfuncsLoadStart),
LOAD_SIZE(RamfuncsLoadSize),
LOAD_END(RamfuncsLoadEnd),
RUN_START(RamfuncsRunStart),
RUN_SIZE(RamfuncsRunSize),
RUN_END(RamfuncsRunEnd),
ALIGN(8)
#else
.TI.ramfunc : {} LOAD = FLASH_BANK0,
RUN = RAMLS0,
LOAD_START(_RamfuncsLoadStart),
LOAD_SIZE(_RamfuncsLoadSize),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
RUN_SIZE(_RamfuncsRunSize),
RUN_END(_RamfuncsRunEnd),
ALIGN(8)
#endif
/* crc/checksum section configured as COPY section to avoid including in executable */
.TI.memcrc : type = COPY
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
@@ -0,0 +1,259 @@
//#############################################################################
//
// FILE: aes_ex11_cbc_packed.c
//
// TITLE: AES CBC
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CBC Example</h1>
//!
//! This example encrypts block cipher-text using AES in CBC mode with 16-bit
//! packed input plaintext and key.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_cbc.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CBC tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t initVector[16];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorCBC;
//
// Test Cases
//
testVectorCBC testVectorCBCArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b7e, 0x1516, 0x28ae, 0xd2a6,
0xabf7, 0x1588, 0x09cf, 0x4f3c},
.initVector = {0x0001, 0x0203, 0x0405, 0x0607,
0x0809, 0x0A0B, 0x0C0D, 0x0E0F},
.dataLength = 4U,
.plainText = {0x6bc1, 0xbee2, 0x2e40, 0x9f96,
0xe93d, 0x7e11, 0x7393, 0x172a,
0xae2d, 0x8a57, 0x1e03, 0xac9c,
0x9eb7, 0x6fac, 0x45af, 0x8e51,
0x30c8, 0x1c46, 0xa35c, 0xe411,
0xe5fb, 0xc119, 0x1a0a, 0x52ef,
0xf69f, 0x2445, 0xdf4f, 0x9b17,
0xad2b, 0x417b, 0xe66c, 0x3710},
.cipherText = {0x7649, 0xabac, 0x8119, 0xb246,
0xcee9, 0x8e9b, 0x12e9, 0x197d,
0x5086, 0xcb9b, 0x5072, 0x19ee,
0x95db, 0x113a, 0x9176, 0x78b2,
0x73be, 0xd6b8, 0xe3c1, 0x743b,
0x7116, 0xe69e, 0x2222, 0x9516,
0x3ff1, 0xcaa1, 0x681f, 0xac09,
0x120e, 0xca30, 0x7586, 0xe1a7}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b7e, 0x1516, 0x28ae, 0xd2a6,
0xabf7, 0x1588, 0x09cf, 0x4f3c},
.initVector = {0x0001, 0x0203, 0x0405, 0x0607,
0x0809, 0x0A0B, 0x0C0D, 0x0E0F},
.dataLength = 4U,
.plainText = {0x7649, 0xabac, 0x8119, 0xb246,
0xcee9, 0x8e9b, 0x12e9, 0x197d,
0x5086, 0xcb9b, 0x5072, 0x19ee,
0x95db, 0x113a, 0x9176, 0x78b2,
0x73be, 0xd6b8, 0xe3c1, 0x743b,
0x7116, 0xe69e, 0x2222, 0x9516,
0x3ff1, 0xcaa1, 0x681f, 0xac09,
0x120e, 0xca30, 0x7586, 0xe1a7},
.cipherText = {0x6bc1, 0xbee2, 0x2e40, 0x9f96,
0xe93d, 0x7e11, 0x7393, 0x172a,
0xae2d, 0x8a57, 0x1e03, 0xac9c,
0x9eb7, 0x6fac, 0x45af, 0x8e51,
0x30c8, 0x1c46, 0xa35c, 0xe411,
0xe5fb, 0xc119, 0x1a0a, 0x52ef,
0xf69f, 0x2445, 0xdf4f, 0x9b17,
0xad2b, 0x417b, 0xe66c, 0x3710}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, *initVector, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCBCArray) /
sizeof(testVectorCBCArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCBCArray[vectorCnt].keySize;
opMode = testVectorCBCArray[vectorCnt].opMode;
keyArray = testVectorCBCArray[vectorCnt].keyArray;
initVector = testVectorCBCArray[vectorCnt].initVector;
dataLength = testVectorCBCArray[vectorCnt].dataLength;
plainTextArray = testVectorCBCArray[vectorCnt].plainText;
expCipherTextArray = testVectorCBCArray[vectorCnt].cipherText;
//
// Perform AES-CBC
//
AES_performCBCFast(plainTextArray, dataLength, keyArray, keySize, opMode,
initVector);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 8U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,249 @@
//#############################################################################
//
// FILE: aes_ex1_ecb.c
//
// TITLE: AES ECB
//
//! \addtogroup library_example_c28x_list
//! <h1>AES ECB Example</h1>
//!
//! This example encrypts block cipher-text using AES in ECB mode.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_ecb.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES ECB tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorECB;
//
// Test Cases
//
testVectorECB testVectorECBArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.dataLength = 4U,
.plainText = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10},
.cipherText = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23,
0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88,
0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f,
0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.dataLength = 4U,
.plainText = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23,
0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88,
0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f,
0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4},
.cipherText = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorECBArray) /
sizeof(testVectorECBArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorECBArray[vectorCnt].keySize;
opMode = testVectorECBArray[vectorCnt].opMode;
keyArray = testVectorECBArray[vectorCnt].keyArray;
dataLength = testVectorECBArray[vectorCnt].dataLength;
plainTextArray = testVectorECBArray[vectorCnt].plainText;
expCipherTextArray = testVectorECBArray[vectorCnt].cipherText;
//
// Perform AES-ECB
//
AES_performECB(plainTextArray, dataLength, keyArray, keySize, opMode);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 16U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,258 @@
//#############################################################################
//
// FILE: aes_ex2_cbc.c
//
// TITLE: AES CBC
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CBC Example</h1>
//!
//! This example encrypts block cipher-text using AES in CBC mode.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_cbc.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CBC tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t initVector[16];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorCBC;
//
// Test Cases
//
testVectorCBC testVectorCBCArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.initVector = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
.dataLength = 4U,
.plainText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10},
.cipherText = {0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.initVector = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
.dataLength = 4U,
.plainText = {0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7},
.cipherText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, *initVector, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCBCArray) /
sizeof(testVectorCBCArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCBCArray[vectorCnt].keySize;
opMode = testVectorCBCArray[vectorCnt].opMode;
keyArray = testVectorCBCArray[vectorCnt].keyArray;
initVector = testVectorCBCArray[vectorCnt].initVector;
dataLength = testVectorCBCArray[vectorCnt].dataLength;
plainTextArray = testVectorCBCArray[vectorCnt].plainText;
expCipherTextArray = testVectorCBCArray[vectorCnt].cipherText;
//
// Perform AES-CBC
//
AES_performCBC(plainTextArray, dataLength, keyArray, keySize, opMode,
initVector);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 16U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,258 @@
//#############################################################################
//
// FILE: aes_ex3_ctr.c
//
// TITLE: AES CTR
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CTR Example</h1>
//!
//! This example encrypts block cipher-text using AES in CTR mode.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_ctr.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CTR tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t nonceCtr[16];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorCTR;
//
// Test Cases
//
testVectorCTR testVectorCTRArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.nonceCtr = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF},
.dataLength = 4U,
.plainText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10},
.cipherText = {0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.nonceCtr = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF},
.dataLength = 4U,
.plainText = {0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee},
.cipherText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, *nonceCtr, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCTRArray) /
sizeof(testVectorCTRArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCTRArray[vectorCnt].keySize;
opMode = testVectorCTRArray[vectorCnt].opMode;
keyArray = testVectorCTRArray[vectorCnt].keyArray;
nonceCtr = testVectorCTRArray[vectorCnt].nonceCtr;
dataLength = testVectorCTRArray[vectorCnt].dataLength;
plainTextArray = testVectorCTRArray[vectorCnt].plainText;
expCipherTextArray = testVectorCTRArray[vectorCnt].cipherText;
//
// Perform AES-CTR
//
AES_performCTR(plainTextArray, dataLength, keyArray, keySize,
opMode, nonceCtr);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 16U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,234 @@
//#############################################################################
//
// FILE: aes_ex4_cmac.c
//
// TITLE: AES CMAC
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CMAC Example</h1>
//!
//! This example encrypts block cipher-text using AES in CMAC mode to generate
//! a message authentication code.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_cmac.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CMAC tests
//
typedef struct
{
AES_KeySize keySize;
uint16_t keyArray[32];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t tag[16];
} testVectorCMAC;
//
// Test Cases
//
testVectorCMAC testVectorCMACArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.dataLength = 4U,
.plainText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10},
.tag = {0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe}
},
//
// Test Case #1
//
{
.keySize = AES_256,
.keyArray = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4},
.dataLength = 4U,
.plainText = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10},
.tag = {0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, dataLength;
uint16_t *expTag, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCMACArray) /
sizeof(testVectorCMACArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCMACArray[vectorCnt].keySize;
keyArray = testVectorCMACArray[vectorCnt].keyArray;
dataLength = testVectorCMACArray[vectorCnt].dataLength;
plainTextArray = testVectorCMACArray[vectorCnt].plainText;
expTag = testVectorCMACArray[vectorCnt].tag;
//
// Perform AES-CMAC
//
uint16_t *tag = AES_performCMAC(plainTextArray, dataLength, keyArray,
keySize);
//
// Check the results
//
for(cnt = 0; cnt < 16U; cnt++)
{
if(tag[cnt] != expTag[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,251 @@
//#############################################################################
//
// FILE: aes_ex5_ecb_fast.c
//
// TITLE: AES ECB fast
//
//! \addtogroup library_example_c28x_list
//! <h1>AES ECB fast Example</h1>
//!
//! This example encrypts block cipher-text using AES fast implementation in
//! ECB mode.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_ecb.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES ECB tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorECB;
//
// Test Cases
//
testVectorECB testVectorECBArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.dataLength = 4U,
.plainText = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10},
.cipherText = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23,
0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88,
0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f,
0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.dataLength = 4U,
.plainText = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23,
0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88,
0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f,
0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4},
.cipherText = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorECBArray) /
sizeof(testVectorECBArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorECBArray[vectorCnt].keySize;
opMode = testVectorECBArray[vectorCnt].opMode;
keyArray = testVectorECBArray[vectorCnt].keyArray;
dataLength = testVectorECBArray[vectorCnt].dataLength;
plainTextArray = testVectorECBArray[vectorCnt].plainText;
expCipherTextArray = testVectorECBArray[vectorCnt].cipherText;
//
// Perform AES-ECB fast
//
AES_performECBFast(plainTextArray, dataLength, keyArray,
keySize, opMode);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 16U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,259 @@
//#############################################################################
//
// FILE: aes_ex6_cbc_fast.c
//
// TITLE: AES CBC fast
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CBC fast Example</h1>
//!
//! This example encrypts block cipher-text using AES fast implementation in
//! CBC mode.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_cbc.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CBC tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t initVector[16];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorCBC;
//
// Test Cases
//
testVectorCBC testVectorCBCArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.initVector = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
.dataLength = 4U,
.plainText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10},
.cipherText = {0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.initVector = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
.dataLength = 4U,
.plainText = {0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7},
.cipherText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, *initVector, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCBCArray) /
sizeof(testVectorCBCArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCBCArray[vectorCnt].keySize;
opMode = testVectorCBCArray[vectorCnt].opMode;
keyArray = testVectorCBCArray[vectorCnt].keyArray;
initVector = testVectorCBCArray[vectorCnt].initVector;
dataLength = testVectorCBCArray[vectorCnt].dataLength;
plainTextArray = testVectorCBCArray[vectorCnt].plainText;
expCipherTextArray = testVectorCBCArray[vectorCnt].cipherText;
//
// Perform AES-CBC
//
AES_performCBCFast(plainTextArray, dataLength, keyArray, keySize,
opMode, initVector);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 16U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,259 @@
//#############################################################################
//
// FILE: aes_ex7_ctr_fast.c
//
// TITLE: AES CTR fast
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CTR fast Example</h1>
//!
//! This example encrypts block cipher-text using AES fast implementation in
//! CTR mode.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_ctr.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CTR tests
//
typedef struct
{
AES_KeySize keySize;
AES_OperationMode opMode;
uint16_t keyArray[32];
uint16_t nonceCtr[16];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t cipherText[64];
} testVectorCTR;
//
// Test Cases
//
testVectorCTR testVectorCTRArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_ENCRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.nonceCtr = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF},
.dataLength = 4U,
.plainText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10},
.cipherText = {0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee}
},
//
// Test Case #2
//
{
.keySize = AES_128,
.opMode = AES_OPMODE_DECRYPT,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.nonceCtr = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF},
.dataLength = 4U,
.plainText = {0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee},
.cipherText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, *nonceCtr, dataLength;
uint16_t *expCipherTextArray, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
AES_OperationMode opMode;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCTRArray) /
sizeof(testVectorCTRArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCTRArray[vectorCnt].keySize;
opMode = testVectorCTRArray[vectorCnt].opMode;
keyArray = testVectorCTRArray[vectorCnt].keyArray;
nonceCtr = testVectorCTRArray[vectorCnt].nonceCtr;
dataLength = testVectorCTRArray[vectorCnt].dataLength;
plainTextArray = testVectorCTRArray[vectorCnt].plainText;
expCipherTextArray = testVectorCTRArray[vectorCnt].cipherText;
//
// Perform AES-CTR
//
AES_performCTRFast(plainTextArray, dataLength, keyArray, keySize,
opMode, nonceCtr);
//
// Check the results
//
for(cnt = 0; cnt < (dataLength * 16U); cnt++)
{
if(plainTextArray[cnt] != expCipherTextArray[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,234 @@
//#############################################################################
//
// FILE: aes_ex8_cmac_fast.c
//
// TITLE: AES CMAC_fast
//
//! \addtogroup library_example_c28x_list
//! <h1>AES CMAC fast Example</h1>
//!
//! This example encrypts block cipher-text using AES fast implementation in
//! CMAC mode to generate a message authentication code.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <aes_cmac.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// Structure for AES CMAC tests
//
typedef struct
{
AES_KeySize keySize;
uint16_t keyArray[32];
uint16_t dataLength;
uint16_t plainText[64];
uint16_t tag[16];
} testVectorCMAC;
//
// Test Cases
//
testVectorCMAC testVectorCMACArray[] =
{
//
// Test Case #1
//
{
.keySize = AES_128,
.keyArray = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c},
.dataLength = 4U,
.plainText = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10},
.tag = {0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe}
},
//
// Test Case #1
//
{
.keySize = AES_256,
.keyArray = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4},
.dataLength = 4U,
.plainText = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10},
.tag = {0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t *keyArray, dataLength;
uint16_t *expTag, *plainTextArray;
uint16_t vectorCnt;
AES_KeySize keySize;
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorCMACArray) /
sizeof(testVectorCMACArray[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
keySize = testVectorCMACArray[vectorCnt].keySize;
keyArray = testVectorCMACArray[vectorCnt].keyArray;
dataLength = testVectorCMACArray[vectorCnt].dataLength;
plainTextArray = testVectorCMACArray[vectorCnt].plainText;
expTag = testVectorCMACArray[vectorCnt].tag;
//
// Perform AES-CMAC fast
//
uint16_t *tag = AES_performCMACFast(plainTextArray, dataLength,
keyArray,keySize);
//
// Check the results
//
for(cnt = 0; cnt < 16U; cnt++)
{
if(tag[cnt] != expTag[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex11_cbc_packed"
device="TMS320F280049C"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f28004x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --define=MEM_PACKED_SPEED_OPT --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f28004x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=MEM_PACKED_SPEED_OPT --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_cbc.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_cbc.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex11_cbc_packed.c" targetDirectory="" />
<file action="copy" path="EXAMPLE_ROOT/28004x_generic_ram_lnk.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM" />
<file action="copy" path="EXAMPLE_ROOT/28004x_generic_flash_lnk.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_FLASH" />
<!-- DRIVERLIB -->
<!-- f28004x f28004x f28004x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/driverlib.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/device.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/device.c" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/f28004x_codestartbranch.asm" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/targetConfigs/TMS320F280049C.ccxml" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/" targetDirectory="f28004x" excludeFromBuild="True" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex1_ecb"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH -g --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 -g --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_ecb.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_ecb.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex1_ecb.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex2_cbc"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_cbc.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_cbc.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex2_cbc.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex3_ctr"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_ctr.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_ctr.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex3_ctr.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex4_cmac"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_cmac.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_cmac.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex4_cmac.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex5_ecb_fast"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_ecb.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_ecb.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex5_ecb_fast.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="EXAMPLE_ROOT/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex6_cbc_fast"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_cbc.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_cbc.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex6_cbc_fast.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="EXAMPLE_ROOT/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex7_ctr_fast"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_ctr.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_ctr.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex7_ctr_fast.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="EXAMPLE_ROOT/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,42 @@
<projectSpec>
<project
name="aes_ex8_cmac_fast"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/aes_cmac.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_cmac.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/aes_ex8_cmac_fast.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="EXAMPLE_ROOT/2838x_RAM_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,50 @@
<projectSpec>
<project
name="rsassapkcs1_v1_5_ex15"
device="TMS320F28P650DK9"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="SHA256_RSA_2048_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${COM_TI_C2000WARE_SOFTWARE_PACKAGE_INSTALL_DIR}/libraries/security/crypto/c28/sha/include -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=SHA_256 --define=CPU1 --define=RSA_2048 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x2000 --heap_size=0x2000 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="SHA256_RSA_3072_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${COM_TI_C2000WARE_SOFTWARE_PACKAGE_INSTALL_DIR}/libraries/security/crypto/c28/sha/include -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=SHA_256 --define=CPU1 --define=RSA_3072 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x2000 --heap_size=0x2000 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="SHA384_RSA_2048_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${COM_TI_C2000WARE_SOFTWARE_PACKAGE_INSTALL_DIR}/libraries/security/crypto/c28/sha/include -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=SHA_384 --define=CPU1 --define=RSA_2048 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x2000 --heap_size=0x2000 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="SHA384_RSA_3072_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${COM_TI_C2000WARE_SOFTWARE_PACKAGE_INSTALL_DIR}/libraries/security/crypto/c28/sha/include -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=SHA_384 --define=CPU1 --define=RSA_3072 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x2000 --heap_size=0x2000 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="SHA_ROOT" path="../../sha" scope="project" />
<pathVariable name="RSA_ROOT" path="../../rsa" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="SHA_ROOT/source/sha256.c" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/source/sha256_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/source/sha384_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/include/sha256.h" targetDirectory="inc" />
<file action="copy" path="SHA_ROOT/source/sha384.c" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/include/sha384.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/source/aes_ctr.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_ctr.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/emsa_pkcs1_v1_5.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/emsa_pkcs1_v1_5.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/mpi.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/mpi.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/rsassa_pkcs1_v1_5.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/rsassa_pkcs1_v1_5.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/yarrow.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/yarrow.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/include/logtab.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/include/mpi-config.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/include/mpi-types.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/rsassa_pkcs1_v1_5_ex15.c" targetDirectory="" />
<file action="copy" path="EXAMPLE_ROOT/28p65x_generic_flash_lnk_cpu1.cmd" targetDirectory="" applicableConfigurations="SHA256_RSA_2048_FLASH, SHA256_RSA_3072_FLASH, SHA384_RSA_2048_FLASH, SHA384_RSA_3072_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,59 @@
<projectSpec>
<project
name="rsassapss_ex14"
device="TMS320F280049C"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f28004x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=RSA_3072 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x3f8 --heap_size=0x2000 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f28004x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=RSA_3072 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x3f8 --heap_size=0x2000 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../aes" scope="project" />
<pathVariable name="SHA_ROOT" path="../../sha" scope="project" />
<pathVariable name="RSA_ROOT" path="../../rsa" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="SHA_ROOT/source/sha256.c" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/source/sha256_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/source/sha384_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/include/sha256.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/source/aes_common.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_common.h" targetDirectory="inc" />
<file action="copy" path="AES_ROOT/source/aes_ctr.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/aes_ctr.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/emsa_pss.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/emsa_pss.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/mpi.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/mpi.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/rsassa_pss.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/rsassa_pss.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/source/yarrow.c" targetDirectory="src" />
<file action="copy" path="RSA_ROOT/include/yarrow.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/include/logtab.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/include/mpi-config.h" targetDirectory="inc" />
<file action="copy" path="RSA_ROOT/include/mpi-types.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/rsassapss_ex14.c" targetDirectory="" />
<file action="copy" path="EXAMPLE_ROOT/280049M_RAM_lnk.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM" />
<file action="copy" path="EXAMPLE_ROOT/280049M_FLASH_lnk.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_FLASH" />
<!-- DRIVERLIB -->
<!-- f28004x f28004x f28004x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/driverlib.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/device.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/device.c" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/f28004x_codestartbranch.asm" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/targetConfigs/TMS320F280049C.ccxml" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/" targetDirectory="f28004x" excludeFromBuild="True" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,41 @@
<projectSpec>
<project
name="sha256_ex10_wordwise"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../sha" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/sha256.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/sha256_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/sha256.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/sha256_ex10_wordwise.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_RAM_lnk_SHA_combined.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,41 @@
<projectSpec>
<project
name="sha256_ex9_bytewise"
device="Generic C28xx Device"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f2838x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f2838x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f2838x -I${PROJECT_ROOT}/f2838x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --float_support=fpu64 --tmu_support=tmu0 --define=CPU1 --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="AES_ROOT" path="../../sha" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="AES_ROOT/source/sha256_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="AES_ROOT/source/sha256.c" targetDirectory="src" />
<file action="copy" path="AES_ROOT/include/sha256.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/sha256_ex9_bytewise.c" targetDirectory="" />
<!-- DRIVERLIB -->
<!-- f2838x f2838x f2838x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/driverlib.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/include/device.h" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/device.c" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/source/f2838x_codestartbranch.asm" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/targetConfigs/TMS320F28388D.ccxml" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_RAM_lnk_SHA_combined.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_RAM" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f2838x/common/cmd/2838x_FLASH_lnk_cpu1.cmd" targetDirectory="f2838x" applicableConfigurations="f2838x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f2838x/driverlib/" targetDirectory="f2838x" excludeFromBuild="True" applicableConfigurations="f2838x_RAM,f2838x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,40 @@
<projectSpec>
<project
name="sha384_ex12_bytewise"
device="TMS320F280049C"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f28004x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --define=MEM_PACKED_SPEED_OPT --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f28004x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=MEM_PACKED_SPEED_OPT --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="SHA_ROOT" path="../../sha" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="SHA_ROOT/source/sha384.c" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/source/sha384_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/include/sha384.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/sha384_ex12_bytewise.c" targetDirectory="" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/cmd/28004x_RAM_lnk_SHA_combined.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM" />
<file action="copy" path="EXAMPLE_ROOT/28004x_generic_flash_lnk.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_FLASH" />
<!-- DRIVERLIB -->
<!-- f28004x f28004x f28004x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/driverlib.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/device.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/device.c" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/f28004x_codestartbranch.asm" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/targetConfigs/TMS320F280049C.ccxml" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/" targetDirectory="f28004x" excludeFromBuild="True" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,41 @@
<projectSpec>
<project
name="sha384_ex13_wordwise"
device="TMS320F280049C"
cgtVersion="21.6.0.LTS"
products="C2000WARE"
launchWizard="False"
linkerCommandFile=""
>
<configuration name="f28004x_FLASH" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=_FLASH --define=MEM_PACKED_SPEED_OPT --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<configuration name="f28004x_RAM" compilerBuildOptions="-Ooff --opt_for_speed=2 --fp_mode=relaxed -I${PROJECT_ROOT} -I${PROJECT_ROOT}/inc -I${PROJECT_ROOT}/f28004x -I${PROJECT_ROOT}/f28004x/driverlib -I${CG_TOOL_ROOT}/include -v28 -ml -mt --cla_support=cla2 --tmu_support=tmu0 --define=CPU1 --define=MEM_PACKED_SPEED_OPT --diag_warning=225 --diag_wrap=off --gen_func_subsections=on --abi=eabi" linkerBuildOptions="--stack_size=0x200 --heap_size=0x200 --define=CPU1 -I${CG_TOOL_ROOT}/include -I${CG_TOOL_ROOT}/lib" />
<pathVariable name="C2000WARE_DEVICE_SUPPORT_ROOT" path="../../../../../../device_support/" scope="project" />
<pathVariable name="C2000WARE_DLIB_ROOT" path="../../../../../../driverlib/" scope="project" />
<pathVariable name="SHA_ROOT" path="../../sha" scope="project" />
<pathVariable name="EXAMPLE_ROOT" path="../" scope="project" />
<file action="copy" path="SHA_ROOT/source/sha384.c" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/source/sha384_casm_C28.asm" targetDirectory="src" />
<file action="copy" path="SHA_ROOT/include/sha384.h" targetDirectory="inc" />
<file action="copy" path="EXAMPLE_ROOT/sha384_ex13_wordwise.c" targetDirectory="" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/cmd/28004x_RAM_lnk_SHA_combined.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM" />
<file action="copy" path="EXAMPLE_ROOT/28004x_generic_flash_lnk.cmd" targetDirectory="f28004x" applicableConfigurations="f28004x_FLASH" />
<!-- DRIVERLIB -->
<!-- f28004x f28004x f28004x -->
<!-- DRIVERLIB -->
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/driverlib.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/include/device.h" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/device.c" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/source/f28004x_codestartbranch.asm" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="link" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/ccs/Debug/driverlib.lib" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DEVICE_SUPPORT_ROOT/f28004x/common/targetConfigs/TMS320F280049C.ccxml" targetDirectory="f28004x" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
<file action="copy" path="C2000WARE_DLIB_ROOT/f28004x/driverlib/" targetDirectory="f28004x" excludeFromBuild="True" applicableConfigurations="f28004x_RAM,f28004x_FLASH" />
</project>
</projectSpec>
@@ -0,0 +1,239 @@
//###########################################################################
//
// FILE: rsassapkcs1_v1_5_ex15.c
//
// TITLE: RSASSA-PKCS1 Example
//
//###########################################################################
// $Copyright:
// Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "emsa_pkcs1_v1_5.h"
#include "rsassa_pkcs1_v1_5.h"
#include "sha256.h"
#include "sha384.h"
#include <stdlib.h>
#include <string.h>
#include "stdio.h"
#ifdef SHA_384
#define DIGEST_SIZE 6
#define SHA_hashByteWise SHA384_hashByteWise
#define SHA_ObjectByteWise SHA384_ObjectByteWise
typedef uint64_t tDigest;
#endif
#ifdef SHA_256
#define DIGEST_SIZE 8
#define SHA_hashByteWise SHA256_hashByteWise
#define SHA_ObjectByteWise SHA256_ObjectByteWise
typedef uint32_t tDigest;
#endif
typedef const unsigned char cuChar;
//*****************************************************************************
//
// SHA object for hashing the message
//
//*****************************************************************************
SHA_ObjectByteWise md;
//*****************************************************************************
//
// RSA-SSA PKCS Parameters
//
//*****************************************************************************
#ifdef RSA_2048
cuChar n[] = "c5062b58d8539c765e1e5dbaf14cf75dd56c2e13105fecfd1a930bbb5948ff328f126abe779359ca59bca752c308d281573bc6178b6c0fef7dc445e4f826430437b9f9d790581de5749c2cb9cb26d42b2fee15b6b26f09c99670336423b86bc5bec71113157be2d944d7ff3eebffb28413143ea36755db0ae62ff5b724eecb3d316b6bac67e89cacd8171937e2ab19bd353a89acea8c36f81c89a620d5fd2effea896601c7f9daca7f033f635a3a943331d1b1b4f5288790b53af352f1121ca1bef205f40dc012c412b40bdd27585b946466d75f7ee0a7f9d549b4bece6f43ac3ee65fe7fd37123359d9f1a850ad450aaf5c94eb11dea3fc0fc6e9856b1805ef";
cuChar e[] = "86c94f";
cuChar d[] = "49e5786bb4d332f94586327bde088875379b75d128488f08e574ab4715302a87eea52d4c4a23d8b97af7944804337c5f55e16ba9ffafc0c9fd9b88eca443f39b7967170ddb8ce7ddb93c6087c8066c4a95538a441b9dc80dc9f7810054fd1e5c9d0250c978bb2d748abe1e9465d71a8165d3126dce5db2adacc003e9062ba37a54b63e5f49a4eafebd7e4bf5b0a796c2b3a950fa09c798d3fa3e86c4b62c33ba9365eda054e5fe74a41f21b595026acf1093c90a8c71722f91af1ed29a41a2449a320fc7ba3120e3e8c3e4240c04925cc698ecd66c7c906bdf240adad972b4dff4869d400b5d13e33eeba38e075e872b0ed3e91cc9c283867a4ffc3901d2069f";
cuChar msg[] = "dfc22604b95d15328059745c6c98eb9dfb347cf9f170aff19deeec555f22285a6706c4ecbf0fb1458c60d9bf913fbae6f4c554d245d946b4bc5f34aec2ac6be8b33dc8e0e3a9d601dfd53678f5674443f67df78a3a9e0933e5f158b169ac8d1c4cd0fb872c14ca8e001e542ea0f9cfda88c42dcad8a74097a00c22055b0bd41f";
#endif
#ifdef RSA_3072
cuChar n[] = "a7a1882a7fb896786034d07fb1b9f6327c27bdd7ce6fe39c285ae3b6c34259adc0dc4f7b9c7dec3ca4a20d3407339eedd7a12a421da18f5954673cac2ff059156ecc73c6861ec761e6a0f2a5a033a6768c6a42d8b459e1b4932349e84efd92df59b45935f3d0e30817c66201aa99d07ae36c5d74f408d69cc08f044151ff4960e531360cb19077833adf7bce77ecfaa133c0ccc63c93b856814569e0b9884ee554061b9a20ab46c38263c094dae791aa61a17f8d16f0e85b7e5ce3b067ece89e20bc4e8f1ae814b276d234e04f4e766f501da74ea7e3817c24ea35d016676cece652b823b051625573ca92757fc720d254ecf1dcbbfd21d98307561ecaab545480c7c52ad7e9fa6b597f5fe550559c2fe923205ac1761a99737ca02d7b19822e008a8969349c87fb874c81620e38f613c8521f0381fe5ba55b74827dad3e1cf2aa29c6933629f2b286ad11be88fa6436e7e3f64a75e3595290dc0d1cd5eee7aaac54959cc53bd5a934a365e72dd81a2bd4fb9a67821bffedf2ef2bd94913de8b";
cuChar e[] = "1415a7";
cuChar d[] = "073a5fc4cd642f6113dffc4f84035cee3a2b8acc549703751a1d6a5eaa13487229a58ef7d7a522bb9f4f25510f1aa0f74c6a8fc8a5c5be8b91a674ede50e92f7e34a90a3c9da999fffb1d695e4588f451256c163484c151350cb9c7825a7d910845ee5cf826fecf9a7c0fbbbba22bb4a531c131d2e7761ba898f002ebef8ab87218511f81d3266e1ec07a7ca8622514c6dfdc86c67679a2c8f5f031de9a0c22b5a88060b46ee0c64d3b9af3c0a379bcd9c6a1b51cf6480456d3fd6def94cd2a6c171dd3f010e3c9d662bc857208248c94ebcb9fd997b9ff4a7e5fd95558569906525e741d78344f6f6cfdbd59d4faa52ee3fa964fb7cccb2d6be1935d211fe1498217716273939a946081fd8509913fd47747c5c2f03efd4d6fc9c6fcfd8402e9f40a0a5b3de3ca2b3c0fac9456938faa6cf2c20e3912e5981c9876d8ca1ff29b87a15eeae0ccce3f8a8f1e405091c083b98bcc5fe0d0deaae33c67c0394437f0eccb385b7efb17aeebba8afaecca30a2f63eac8f0ac8f1eacad85bbcaf3960b";
cuChar msg[] = "3b8a68da11b61b5fee1c2ca00a6aa35bbfdbdd42855b284320ec8d0c1848edcf6ac850427d8479eb57bcbe9a11771637886974bd561a5387014592cb717e8364a8183fd4ad463c89c980215ff629d867956ee5e75f71f7a19ea7bd589d7efb915d44dd9789448bc1ac32fdf7a2c911734db2dbc589a83c1a61dab6bd83907ede";
#endif
#define HASH_LEN (DIGEST_SIZE * sizeof(tDigest) * 2)
//*****************************************************************************
//
// Data structures to work with
//
//*****************************************************************************
rsa_PublicKey key_pub;
rsa_PrivateKey key_pvt;
rsa_Modulus modulus;
rsa_Signature sign;
int16_t verified = -1;
//*****************************************************************************
//
// Main function
//
//*****************************************************************************
void main(void)
{
//
// Application locals
//
uint16_t i, j;
char temp[3]= {0};
uint16_t *hash = NULL;
uint16_t msg_data[256] = {0};
tDigest digest[DIGEST_SIZE] = {0};
volatile char *strSignature = NULL;
uint16_t datalen = strlen((char *)msg)/2;
//convert message character string to a uint16_t byte array.
for(i=0; i<strlen((char *)msg); i+=2)
{
temp[0] = msg[i];
temp[1] = msg[i+1];
msg_data[i/2] = strtol(temp,NULL,16);
}
//Compute the hash digest
SHA_hashByteWise(&md, msg_data, datalen, digest);
//
// Initialize RSASSA-PKCS parameters
//
rsa_init_pvtkey(&key_pvt);
rsa_init_pubkey(&key_pub);
rsa_init_modulus(&modulus);
rsa_init_modulus(&sign);
//
// Set RSASSA-PKCS parameters with values from hex strings
//
rsa_set_pvtkey_from_hex(&key_pvt, (unsigned char*)d);
rsa_set_pubkey_from_hex(&key_pub, (unsigned char*)e);
rsa_set_modulus_from_hex(&modulus, (unsigned char*)n);
//
// Create the hash stream from the digest data
//
hash = (uint16_t*)calloc(HASH_LEN,1);
if(!hash)
{
asm(" ESTOP0");
//hash allocation failed. Loop forever.
while(1);
}
//create a serialized uint16_t type hash based on the digest
for (i=0; i < HASH_LEN; i++)
{
int index = i / (sizeof(tDigest) * 2);
hash[i] = (uint16_t) (digest[index] >> ((sizeof(tDigest) * 16) - 8 - (8 * i))) & 0x00FF;
}
//
// Generate the signature
//
rsassa_pkcs1_v1_5_sign(&key_pvt, &modulus, &sign, hash, HASH_LEN);
//Release private Key Memory
mp_clear(&key_pvt);
//
// Convert Signature to a string
//
uint16_t sign_len = sign.used * 2;
uint16_t* sign_str = (uint16_t*)malloc(sign_len);
if(sign_str != NULL)
{
rsa_signature_to_mem(&sign, sign_str, sign_len);
strSignature = (char*)calloc((sign_len * 2) + 1, 1);
for(i=0, j=0; i<sign_len; i++, j+=2)
{
ltoa(sign_str[i], (char*)strSignature + j, 16);
if(strSignature[j+1] == 0x0000)
{
strSignature[j+1] = strSignature[j];
strSignature[j] = '0';
}
}
free(sign_str);
mp_clear(&sign);
}
//***************************************************
// strSignature now holds the
// string format of the signature.
//***************************************************
//===================================================
// VERIFICATION OF SIGNATURE
//===================================================
int mod_len = strlen((char*)n) * 4;
rsa_Signature signVerify;
rsa_init_modulus(&signVerify);
rsa_set_modulus_from_hex(&signVerify, (unsigned char*)strSignature);
//Free the signature mem
free((void*)strSignature);
//
//
// Verify the generated signature
// if verified == 1, then successful
// if verified == 0, then signature incorrect
// if verified == -1, then verification incomplete
//
rsassa_pkcs1_v1_5_verify(&signVerify, hash, HASH_LEN, mod_len, &key_pub, &modulus, &verified);
mp_clear(&key_pub);
mp_clear(&modulus);
mp_clear(&signVerify);
while (1);
}
//
// End of file
//
@@ -0,0 +1,188 @@
//###########################################################################
//
// FILE: rsassapss_ex14.c
//
// TITLE: RSASSA-PSS Example
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "emsa_pss.h"
#include "rsassa_pss.h"
#include "sha256.h"
#include "yarrow.h"
#include <time.h>
#include "driverlib.h"
#include "device.h"
#include <stdlib.h>
#include <string.h>
#define HASH_SIZE 32
void runTest(void);
//*****************************************************************************
//
// SHA-256 object for hashing the message
//
//*****************************************************************************
SHA256_ObjectByteWise md;
//*****************************************************************************
//
// RSA-SSA PSS Parameters
//
//*****************************************************************************
#ifdef RSA_2048
unsigned char n[] = "c5062b58d8539c765e1e5dbaf14cf75dd56c2e13105fecfd1a930bbb5948ff328f126abe779359ca59bca752c308d281573bc6178b6c0fef7dc445e4f826430437b9f9d790581de5749c2cb9cb26d42b2fee15b6b26f09c99670336423b86bc5bec71113157be2d944d7ff3eebffb28413143ea36755db0ae62ff5b724eecb3d316b6bac67e89cacd8171937e2ab19bd353a89acea8c36f81c89a620d5fd2effea896601c7f9daca7f033f635a3a943331d1b1b4f5288790b53af352f1121ca1bef205f40dc012c412b40bdd27585b946466d75f7ee0a7f9d549b4bece6f43ac3ee65fe7fd37123359d9f1a850ad450aaf5c94eb11dea3fc0fc6e9856b1805ef";
unsigned char e[] = "86c94f";
unsigned char d[] = "49e5786bb4d332f94586327bde088875379b75d128488f08e574ab4715302a87eea52d4c4a23d8b97af7944804337c5f55e16ba9ffafc0c9fd9b88eca443f39b7967170ddb8ce7ddb93c6087c8066c4a95538a441b9dc80dc9f7810054fd1e5c9d0250c978bb2d748abe1e9465d71a8165d3126dce5db2adacc003e9062ba37a54b63e5f49a4eafebd7e4bf5b0a796c2b3a950fa09c798d3fa3e86c4b62c33ba9365eda054e5fe74a41f21b595026acf1093c90a8c71722f91af1ed29a41a2449a320fc7ba3120e3e8c3e4240c04925cc698ecd66c7c906bdf240adad972b4dff4869d400b5d13e33eeba38e075e872b0ed3e91cc9c283867a4ffc3901d2069f";
unsigned char msg[] = "dfc22604b95d15328059745c6c98eb9dfb347cf9f170aff19deeec555f22285a6706c4ecbf0fb1458c60d9bf913fbae6f4c554d245d946b4bc5f34aec2ac6be8b33dc8e0e3a9d601dfd53678f5674443f67df78a3a9e0933e5f158b169ac8d1c4cd0fb872c14ca8e001e542ea0f9cfda88c42dcad8a74097a00c22055b0bd41f";
#endif
#ifdef RSA_3072
unsigned char n[] = "a7a1882a7fb896786034d07fb1b9f6327c27bdd7ce6fe39c285ae3b6c34259adc0dc4f7b9c7dec3ca4a20d3407339eedd7a12a421da18f5954673cac2ff059156ecc73c6861ec761e6a0f2a5a033a6768c6a42d8b459e1b4932349e84efd92df59b45935f3d0e30817c66201aa99d07ae36c5d74f408d69cc08f044151ff4960e531360cb19077833adf7bce77ecfaa133c0ccc63c93b856814569e0b9884ee554061b9a20ab46c38263c094dae791aa61a17f8d16f0e85b7e5ce3b067ece89e20bc4e8f1ae814b276d234e04f4e766f501da74ea7e3817c24ea35d016676cece652b823b051625573ca92757fc720d254ecf1dcbbfd21d98307561ecaab545480c7c52ad7e9fa6b597f5fe550559c2fe923205ac1761a99737ca02d7b19822e008a8969349c87fb874c81620e38f613c8521f0381fe5ba55b74827dad3e1cf2aa29c6933629f2b286ad11be88fa6436e7e3f64a75e3595290dc0d1cd5eee7aaac54959cc53bd5a934a365e72dd81a2bd4fb9a67821bffedf2ef2bd94913de8b";
unsigned char e[] = "1415a7";
unsigned char d[] = "073a5fc4cd642f6113dffc4f84035cee3a2b8acc549703751a1d6a5eaa13487229a58ef7d7a522bb9f4f25510f1aa0f74c6a8fc8a5c5be8b91a674ede50e92f7e34a90a3c9da999fffb1d695e4588f451256c163484c151350cb9c7825a7d910845ee5cf826fecf9a7c0fbbbba22bb4a531c131d2e7761ba898f002ebef8ab87218511f81d3266e1ec07a7ca8622514c6dfdc86c67679a2c8f5f031de9a0c22b5a88060b46ee0c64d3b9af3c0a379bcd9c6a1b51cf6480456d3fd6def94cd2a6c171dd3f010e3c9d662bc857208248c94ebcb9fd997b9ff4a7e5fd95558569906525e741d78344f6f6cfdbd59d4faa52ee3fa964fb7cccb2d6be1935d211fe1498217716273939a946081fd8509913fd47747c5c2f03efd4d6fc9c6fcfd8402e9f40a0a5b3de3ca2b3c0fac9456938faa6cf2c20e3912e5981c9876d8ca1ff29b87a15eeae0ccce3f8a8f1e405091c083b98bcc5fe0d0deaae33c67c0394437f0eccb385b7efb17aeebba8afaecca30a2f63eac8f0ac8f1eacad85bbcaf3960b";
unsigned char msg[] = "3b8a68da11b61b5fee1c2ca00a6aa35bbfdbdd42855b284320ec8d0c1848edcf6ac850427d8479eb57bcbe9a11771637886974bd561a5387014592cb717e8364a8183fd4ad463c89c980215ff629d867956ee5e75f71f7a19ea7bd589d7efb915d44dd9789448bc1ac32fdf7a2c911734db2dbc589a83c1a61dab6bd83907ede";
#endif
//*****************************************************************************
//
// Data structures to work with
//
//*****************************************************************************
rsa_PublicKey key_pub;
rsa_PrivateKey key_pvt;
rsa_Modulus modulus;
rsa_Signature sign;
int16_t verified = -1;
//*****************************************************************************
//
// Main function
//
//*****************************************************************************
void main(void)
{
//
// Device initialize
//
Device_init();
uint16_t i, j;
//
// Yarrow PRNG handler to generate random salt
//
yarrow_prng prng;
//
// Initialize RSASSA-PSS parameters
//
rsa_init_pvtkey(&key_pvt);
rsa_init_pubkey(&key_pub);
rsa_init_modulus(&modulus);
//
// Set RSASSA-PSS parameters with values from hex strings
//
rsa_set_pvtkey_from_hex(&key_pvt, d);
rsa_set_pubkey_from_hex(&key_pub, e);
rsa_set_modulus_from_hex(&modulus, n);
//
// Place the message for which the signature has to be generated
// in memory
//
uint16_t datalen = strlen((char *)msg)/2;
uint16_t *msg_data = (uint16_t *)malloc(datalen);
rsa_hex_to_data(msg, msg_data);
//
// Hashing the message
//
uint32_t digest[8];
SHA256_hashByteWise(&md, msg_data, datalen, digest);
uint16_t hash[40];
for (i = 0, j = 0; i < 8 && j < 32; i++)
{
hash[j++] = (digest[i] >> 24) & 255;
hash[j++] = (digest[i] >> 16) & 255;
hash[j++] = (digest[i] >> 8) & 255;
hash[j++] = (digest[i]) & 255;
}
//
// Free the memory used up for holding the message. It is not needed anymore
//
free(msg_data);
//
// Initialize the Yarrow PRNG handler
//
uc nounce[16] = {0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF};
yarrow_init_with_nounce(&prng, nounce);
yarrow_add_entropy("abcd", 4U, &prng);
yarrow_ready(&prng);
//
// Generate the signature
//
int mod_len = strlen((char *)n)*4;
int saltlen = 20; /* Desired random salt length */
rsassa_pss_sign(hash, HASH_SIZE, saltlen, &key_pvt, &modulus, mod_len, &prng, &sign);
//
// Extract the generated signature into a byte string
//
uint16_t sign_len = strlen((char *)n)/2;
uint16_t *sign_str = (uint16_t *)malloc(sign_len);
rsa_signature_to_mem(&sign, sign_str, sign_len);
//
//
// Verify the generated signature
// if verified == 1, then successful
// if verified == 0, then signature incorrect
// if verified == -1, then verification incomplete
//
rsassa_pss_verify(&sign, hash, HASH_SIZE, saltlen, &key_pub, &modulus, mod_len, &verified);
while(1);
}
//
// End of file
//
@@ -0,0 +1,221 @@
//#############################################################################
//
// FILE: sha_256_ex9_wordwise.c
//
// TITLE: SHA-256 word-wise
//
//! \addtogroup library_example_c28x_list
//! <h1>SHA256 wordwise Example</h1>
//!
//! This example hashes message and produces message digest using SHA256
//! algorithm by taking in the message to be hashed wordwise.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <sha256.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// SHA-256 word-wise handle
//
SHA256_ObjectWordWise SHA256_Obj;
SHA256_HandleWordWise handle = &SHA256_Obj;
//
// Structure for SHA-256 tests
//
typedef struct
{
uint16_t dataLength;
uint32_t plainText[16];
uint32_t digest[8];
} testVectorSHA256;
//
// Test Cases
//
testVectorSHA256 testVectorSHA256Array[] =
{
//
// Test Case #1
//
{
.dataLength = 4U,
//
// String "abcd"
//
.plainText = {0x61626364},
.digest = { 0x88d4266f, 0xd4e6338d, 0x13b845fc,
0xf289579d, 0x209c8978, 0x23b9217d,
0xa3e16193, 0x6f031589 }
},
//
// Test Case #2
//
{
.dataLength = 56U,
.plainText = {0x61626364, 0x62636465, 0x63646566, 0x64656667,
0x65666768, 0x66676869, 0x6768696a, 0x68696a6b,
0x696a6b6c, 0x6a6b6c6d, 0x6b6c6d6e, 0x6c6d6e6f,
0x6d6e6f70, 0x6e6f7071},
.digest = { 0x248D6A61, 0xD20638B8, 0xE5C02693,
0x0C3E6039, 0xA33CE459, 0x64FF2167,
0xF6ECEDD4, 0x19DB06C1 }
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t dataLength;
uint32_t *expDigest, *plainTextArray;
uint16_t vectorCnt;
uint32_t digest[8];
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorSHA256Array) /
sizeof(testVectorSHA256Array[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
dataLength = testVectorSHA256Array[vectorCnt].dataLength;
plainTextArray = testVectorSHA256Array[vectorCnt].plainText;
expDigest = testVectorSHA256Array[vectorCnt].digest;
//
// Perform SHA-256
// Note : For wordwise implementation, dataLength should always
// be a multiple of 4
//
uint16_t retval = SHA256_hashWordWise(handle,
(uint32_t *)plainTextArray,
dataLength, digest);
//
// Check the results
//
for(cnt = 0; cnt < 8U; cnt++)
{
if(digest[cnt] != expDigest[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,214 @@
//#############################################################################
//
// FILE: sha_256_ex9_bytewise.c
//
// TITLE: SHA-256 bytewise
//
//! \addtogroup library_example_c28x_list
//! <h1>SHA256 bytewise Example</h1>
//!
//! This example hashes message and produces message digest using SHA256
//! algorithm by taking in the message to be hashed bytewise.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <sha256.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// SHA-256 byte-wise handle
//
SHA256_ObjectByteWise SHA256_Obj;
SHA256_HandleByteWise handle = &SHA256_Obj;
//
// Structure for SHA-256 tests
//
typedef struct
{
uint16_t dataLength;
char plainText[64];
uint32_t digest[8];
} testVectorSHA256;
//
// Test Cases
//
testVectorSHA256 testVectorSHA256Array[] =
{
//
// Test Case #1
//
{
.dataLength = 3U,
.plainText = "abc",
.digest = { 0xBA7816BF, 0x8F01CFEA, 0x414140DE,
0x5DAE2223, 0xB00361A3, 0x96177A9C,
0xB410FF61, 0xF20015AD }
},
//
// Test Case #2
//
{
.dataLength = 56U,
.plainText = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
.digest = { 0x248D6A61, 0xD20638B8, 0xE5C02693,
0x0C3E6039, 0xA33CE459, 0x64FF2167,
0xF6ECEDD4, 0x19DB06C1 }
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t dataLength;
uint32_t *expDigest;
char *plainTextArray;
uint16_t vectorCnt;
uint32_t digest[8];
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorSHA256Array) /
sizeof(testVectorSHA256Array[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
dataLength = testVectorSHA256Array[vectorCnt].dataLength;
plainTextArray = testVectorSHA256Array[vectorCnt].plainText;
expDigest = testVectorSHA256Array[vectorCnt].digest;
//
// Perform SHA-256
//
uint16_t retval = SHA256_hashByteWise(handle,
(uint16_t *)plainTextArray,
dataLength, digest);
//
// Check the results
//
for(cnt = 0; cnt < 8U; cnt++)
{
if(digest[cnt] != expDigest[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,227 @@
//#############################################################################
//
// FILE: sha_384_ex12_bytewise.c
//
// TITLE: SHA-384 bytewise
//
//! \addtogroup library_example_c28x_list
//! <h1>SHA384 bytewise Example</h1>
//!
//! This example hashes message and produces message digest using SHA384
//! algorithm by taking in the message to be hashed bytewise.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <sha384.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// SHA-384 byte-wise handle
//
SHA384_ObjectByteWise SHA384_Obj;
SHA384_HandleByteWise handle = &SHA384_Obj;
//
// Structure for SHA-384 tests
//
typedef struct
{
uint16_t dataLength;
char plainText[128];
uint64_t digest[6];
} testVectorSHA384;
//
// Test Cases
//
testVectorSHA384 testVectorSHA384Array[] =
{
//
// Test Case #1
//
{
.dataLength = 3U,
.plainText = "abc",
.digest = {0xCB00753F45A35E8B, 0xB5A03D699AC65007, 0x272C32AB0EDED163,
0x1A8B605A43FF5BED, 0x8086072BA1E7CC23, 0x58BAECA134C825A7}
},
//
// Test Case #2
//
{
.dataLength = 128U,
.plainText = { 0x3b, 0xf5, 0x2c, 0xc5, 0xee, 0x86, 0xb9, 0xa0,
0x19, 0x0f, 0x39, 0x0a, 0x5c, 0x03, 0x66, 0xa5,
0x60, 0xb5, 0x57, 0x00, 0x0d, 0xbe, 0x51, 0x15,
0xfd, 0x9e, 0xe1, 0x16, 0x30, 0xa6, 0x27, 0x69,
0x01, 0x15, 0x75, 0xf1, 0x58, 0x81, 0x19, 0x8f,
0x22, 0x78, 0x76, 0xe8, 0xfe, 0x68, 0x5a, 0x69,
0x39, 0xbc, 0x8b, 0x89, 0xfd, 0x48, 0xa3, 0x4e,
0xc5, 0xe7, 0x1e, 0x13, 0x14, 0x62, 0xb2, 0x88,
0x67, 0x94, 0xdf, 0xfa, 0x68, 0xcc, 0xc6, 0xd5,
0x64, 0x73, 0x3e, 0x67, 0xff, 0xef, 0x25, 0xe6,
0x27, 0xc6, 0xf4, 0xb5, 0x46, 0x07, 0x96, 0xe3,
0xbc, 0xe6, 0x7b, 0xf5, 0x8c, 0xa6, 0xe8, 0xe5,
0x55, 0xbc, 0x91, 0x6a, 0x85, 0x31, 0x69, 0x7a,
0xc9, 0x48, 0xb9, 0x0d, 0xc8, 0x61, 0x6f, 0x25,
0x10, 0x1d, 0xb9, 0x0b, 0x50, 0xc3, 0xd3, 0xdb,
0xc9, 0xe2, 0x1e, 0x42, 0xff, 0x38, 0x71, 0x87 },
.digest = { 0x12b6cb35eda92ee3, 0x7356ddee77781a17, 0xb3d90e563824a984,
0xfaffc6fdd1693bd7, 0x626039635563cfc3, 0xb9a2b00f9c65eefd }
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t dataLength;
uint64_t *expDigest;
uint16_t *plainTextArray;
uint16_t vectorCnt;
uint64_t digest[6];
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorSHA384Array) /
sizeof(testVectorSHA384Array[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
dataLength = testVectorSHA384Array[vectorCnt].dataLength;
plainTextArray = (uint16_t *)testVectorSHA384Array[vectorCnt].plainText;
expDigest = testVectorSHA384Array[vectorCnt].digest;
//
// Perform SHA-384
//
uint16_t retval = SHA384_hashByteWise(handle,
(uint16_t *)plainTextArray,
dataLength, digest);
//
// Check the results
//
for(cnt = 0; cnt < 6U; cnt++)
{
if(digest[cnt] != expDigest[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,232 @@
//#############################################################################
//
// FILE: sha_384_ex13_wordwise.c
//
// TITLE: SHA-384 word-wise
//
//! \addtogroup library_example_c28x_list
//! <h1>SHA384 wordwise Example</h1>
//!
//! This example hashes message and produces message digest using SHA384
//! algorithm by taking in the message to be hashed wordwise.
//!
//! \b External \b Connections \n
//! - None
//!
//! \b Watch \b Variables \n
//! - \b errCountGlobal - Error Counter. It should be zero.
//! - \b testStatusGlobal - Test status. It should be equal to PASS.
//!
//
//#############################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//
// Included Files
//
#include <sha384.h>
#include "driverlib.h"
#include "device.h"
//
// Defines
//
#define TEST_PASS 0xABCDABCD
#define TEST_FAIL 0xDEADDEAD
//
// Global Variables
//
//
// Global error counter & status
//
uint16_t errCountGlobal = 0;
uint32_t testStatusGlobal;
//
// SHA-384 word-wise handle
//
SHA384_ObjectWordWise SHA384_Obj;
SHA384_HandleWordWise handle = &SHA384_Obj;
//
// Structure for SHA-384 tests
//
typedef struct
{
uint16_t dataLength;
uint32_t plainText[32];
uint64_t digest[6];
} testVectorSHA384;
//
// Test Cases
//
testVectorSHA384 testVectorSHA384Array[] =
{
//
// Test Case #1
//
{
.dataLength = 4U,
//
// String "abcd"
//
.plainText = {0x61626364},
.digest = {0x1165b3406ff0b52a, 0x3d24721f785462ca, 0x2276c9f454a116c2,
0xb2ba20171a7905ea, 0x5a026682eb659c4d, 0x5f115c363aa3c79b}
},
//
// Test Case #2
//
{
.dataLength = 128U,
.plainText = { 0x3bf52cc5, 0xee86b9a0,
0x190f390a, 0x5c0366a5,
0x60b55700, 0x0dbe5115,
0xfd9ee116, 0x30a62769,
0x011575f1, 0x5881198f,
0x227876e8, 0xfe685a69,
0x39bc8b89, 0xfd48a34e,
0xc5e71e13, 0x1462b288,
0x6794dffa, 0x68ccc6d5,
0x64733e67, 0xffef25e6,
0x27c6f4b5, 0x460796e3,
0xbce67bf5, 0x8ca6e8e5,
0x55bc916a, 0x8531697a,
0xc948b90d, 0xc8616f25,
0x101db90b, 0x50c3d3db,
0xc9e21e42, 0xff387187 },
.digest = { 0x12b6cb35eda92ee3, 0x7356ddee77781a17, 0xb3d90e563824a984,
0xfaffc6fdd1693bd7, 0x626039635563cfc3, 0xb9a2b00f9c65eefd}
}
};
void main(void)
{
uint16_t errCountLocal, cnt;
uint16_t dataLength;
uint64_t *expDigest;
uint32_t *plainTextArray;
uint16_t vectorCnt;
uint64_t digest[6];
//
// Initialize device clock and peripherals
//
Device_init();
//
// Initialize local variables.
//
errCountLocal = 0;
//
// Loop through all the given vectors.
//
for(vectorCnt = 0;
(vectorCnt < (sizeof(testVectorSHA384Array) /
sizeof(testVectorSHA384Array[0]))); vectorCnt++)
{
//
// Get the current vector's data members.
//
dataLength = testVectorSHA384Array[vectorCnt].dataLength;
plainTextArray = testVectorSHA384Array[vectorCnt].plainText;
expDigest = testVectorSHA384Array[vectorCnt].digest;
//
// Perform SHA-384
// Note : For wordwise implementation, dataLength should always
// be a multiple of 4
//
uint16_t retval = SHA384_hashWordWise(handle,
(uint32_t *)plainTextArray,
dataLength, digest);
//
// Check the results
//
for(cnt = 0; cnt < 6U; cnt++)
{
if(digest[cnt] != expDigest[cnt])
{
errCountLocal++;
}
}
//
// Update the global error counter.
//
if(errCountLocal > 0)
{
errCountGlobal++;
}
//
// Clear the local error counter.
//
errCountLocal = 0;
}
//
// Update test status variable
//
if(errCountGlobal == 0)
{
testStatusGlobal = TEST_PASS;
}
else
{
testStatusGlobal = TEST_FAIL;
}
//
// Infinite Loop to keep the core running
//
while(1)
{
}
}
//
// End of file
//
@@ -0,0 +1,104 @@
//###########################################################################
//
// FILE: emsa_pkcs1_v1_5.h
//
// TITLE: EMSA-PKCS message encoding header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef __EMSA_PKCS1_V1_5_H__
#define __EMSA_PKCS1_V1_5_H__
#include <stdint.h>
//*****************************************************************************
//
// Defines
//
//*****************************************************************************
#define SHA256_HASH_SIZE 32 // 32 byte message digest output for SHA-256
#define SHA384_HASH_SIZE 48 // 48 byte message digest output for SHA-384
#define ASN_1_PAD_SIZE 30
#define PKCS_STATUS_SUCCESS 0
#define PKCS_STATUS_FAILURE 1
#define PKCS_STATUS_FAILURE_SIZE 2
#define PKCS_STATUS_FAILURE_NULL 3
#define PKCS_STATUS_FAILURE_READ 4
#define PKCS_STATUS_FAILURE_MEM 5
#define PKCS_STATUS_FAILURE_LEN 6
#define PK_STATUS_INVALID 6
#define STORE32H(x, y) \
do \
{ \
(y)[0] = (unsigned char)(((x) >> 24) & 255); \
(y)[1] = (unsigned char)(((x) >> 16) & 255); \
(y)[2] = (unsigned char)(((x) >> 8) & 255); \
(y)[3] = (unsigned char)((x)&255); \
} while (0)
//*****************************************************************************
//
//! EMSA-PKCS encode message
//!
//! \param emsa_out is the pointer to hold the encoded data
//! \param emsa_outlen is the output length of the encoded data
//! \param digest is the serialized hash data based on the SHA encoding type
//! \param hash_size is the length of the hash
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
int emsa_pkcs1_v1_5_encode(uint16_t* emsa_out, uint16_t* digest, uint16_t hash_size);
//*****************************************************************************
//
//! EMSA-PKCS decode message
//!
//! \param EM_Str is the pointer to the EMSA padding bytes
//! \param hash is the pointer to the hash to be compared (serialized digest)
//! \param hash_size is the size of the hash based on the SHA encoding type
//! \param result is a pointer to the variable to hold the verification result
//! 1 - Verification successful
//! 0 - Incorrect signature. Verification failed
//! -1 - Verification incomplete
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
int emsa_pkcs1_v1_5_decode(uint16_t* EM_Str, uint16_t *hash, uint16_t hash_size, int16_t* result);
#endif
@@ -0,0 +1,124 @@
//###########################################################################
//
// FILE: emsa_pss.h
//
// TITLE: EMSA-PSS message encoding header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef EMSA_PSS_H_
#define EMSA_PSS_H_
#include <stdint.h>
#include "yarrow.h"
//*****************************************************************************
//
// Defines
//
//*****************************************************************************
#define HASH_SIZE 32 // 32 byte message digest output for SHA-256
#define PKCS_STATUS_SUCCESS 0
#define PKCS_STATUS_FAILURE 1
#define PKCS_STATUS_FAILURE_SIZE 2
#define PKCS_STATUS_FAILURE_NULL 3
#define PKCS_STATUS_FAILURE_READ 4
#define PKCS_STATUS_FAILURE_MEM 5
#define PK_STATUS_INVALID 6
#define STORE32H(x, y) \
do \
{ \
(y)[0] = (unsigned char)(((x) >> 24) & 255); \
(y)[1] = (unsigned char)(((x) >> 16) & 255); \
(y)[2] = (unsigned char)(((x) >> 8) & 255); \
(y)[3] = (unsigned char)((x)&255); \
} while (0)
//*****************************************************************************
//
//! PKCS1_MGF mask generation using SHA-256
//!
//! \param seed is the pointer to the input seed
//! \param seedlen is the length of the seed in bytes
//! \param mask is the pointer to the output mask
//! \param masklen is the length of the output mask in bytes
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
int pkcs_1_mgf(uint16_t *seed, int16_t seedlen, uint16_t *mask, int16_t masklen);
//*****************************************************************************
//
//! EMSA-PSS encode message
//!
//! \param msghash is the pointer to the bytewise hash digest of the message
//! \param hashlen is the length of the hash digest of the message in bytes
//! \param saltlen is the length of the random salt in bytes
//! \param modulus_bitlen is the length of the RSA modulus in bits (not bytes)
//! \param prng is the pointer to the yarrow prng handler to generate
//! random salt
//! \param emsa_out is the pointer to hold the encoded data
//! \param emsa_outlen is the output length of the encoded data
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
int emsa_pss_encode(uint16_t *msghash, uint16_t msghashlen, uint16_t saltlen,
uint16_t modulus_bitlen, yarrow_prng *prng,
uint16_t *emsa_out, uint16_t emsa_outlen);
//*****************************************************************************
//
//! EMSA-PSS decode message
//!
//! \param sig is the pointer to the message encoding to be decoded
//! \param siglen is the length in bytes of the message encoding to be decoded
//! \param msghash is the pointer to the bytewise hash digest of the message
//! \param hashlen is the length of the hash digest of the message in bytes
//! \param saltlen is the length of the random salt in bytes
//! \param modulus_bitlen is the length of the RSA modulus in bits (not bytes)
//! \param res is a pointer to the variable to hold the verification result
//! 1 - Verification successful
//! 0 - Incorrect signature. Verification failed
//! -1 - Verification incomplete
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
int emsa_pss_decode(uint16_t *sig, uint16_t siglen, uint16_t *msghash, uint16_t msghashlen,
uint16_t saltlen, uint16_t modulus_bitlen, int16_t *res);
#endif /* EMSA_PSS_H_ */
@@ -0,0 +1,24 @@
const float s_logv_2[] = {
0.000000000, 0.000000000, 1.000000000, 0.630929754, /* 0 1 2 3 */
0.500000000, 0.430676558, 0.386852807, 0.356207187, /* 4 5 6 7 */
0.333333333, 0.315464877, 0.301029996, 0.289064826, /* 8 9 10 11 */
0.278942946, 0.270238154, 0.262649535, 0.255958025, /* 12 13 14 15 */
0.250000000, 0.244650542, 0.239812467, 0.235408913, /* 16 17 18 19 */
0.231378213, 0.227670249, 0.224243824, 0.221064729, /* 20 21 22 23 */
0.218104292, 0.215338279, 0.212746054, 0.210309918, /* 24 25 26 27 */
0.208014598, 0.205846832, 0.203795047, 0.201849087, /* 28 29 30 31 */
0.200000000, 0.198239863, 0.196561632, 0.194959022, /* 32 33 34 35 */
0.193426404, 0.191958720, 0.190551412, 0.189200360, /* 36 37 38 39 */
0.187901825, 0.186652411, 0.185449023, 0.184288833, /* 40 41 42 43 */
0.183169251, 0.182087900, 0.181042597, 0.180031327, /* 44 45 46 47 */
0.179052232, 0.178103594, 0.177183820, 0.176291434, /* 48 49 50 51 */
0.175425064, 0.174583430, 0.173765343, 0.172969690, /* 52 53 54 55 */
0.172195434, 0.171441601, 0.170707280, 0.169991616, /* 56 57 58 59 */
0.169293808, 0.168613099, 0.167948779, 0.167300179, /* 60 61 62 63 */
0.166666667
};
/* $Source$ */
/* $Revision$ */
/* $Date$ */
@@ -0,0 +1,90 @@
/* Default configuration for MPI library */
/* $Id$ */
#ifndef MPI_CONFIG_H_
#define MPI_CONFIG_H_
/*
For boolean options,
0 = no
1 = yes
Other options are documented individually.
*/
#ifndef MP_IOFUNC
#define MP_IOFUNC 0 /* include mp_print() ? */
#endif
#ifndef MP_MODARITH
#define MP_MODARITH 1 /* include modular arithmetic ? */
#endif
#ifndef MP_NUMTH
#define MP_NUMTH 1 /* include number theoretic functions? */
#endif
#ifndef MP_LOGTAB
#define MP_LOGTAB 1 /* use table of logs instead of log()? */
#endif
#ifndef MP_MEMSET
#define MP_MEMSET 1 /* use memset() to zero buffers? */
#endif
#ifndef MP_MEMCPY
#define MP_MEMCPY 1 /* use memcpy() to copy buffers? */
#endif
#ifndef MP_CRYPTO
#define MP_CRYPTO 1 /* erase memory on free? */
#endif
#ifndef MP_ARGCHK
/*
0 = no parameter checks
1 = runtime checks, continue execution and return an error to caller
2 = assertions; dump core on parameter errors
*/
#define MP_ARGCHK 2 /* how to check input arguments */
#endif
#ifndef MP_DEBUG
#define MP_DEBUG 0 /* print diagnostic output? */
#endif
#ifndef MP_DEFPREC
#define MP_DEFPREC 64 /* default precision, in digits */
#endif
#ifndef MP_MACRO
#define MP_MACRO 1 /* use macros for frequent calls? */
#endif
#ifndef MP_SQUARE
#define MP_SQUARE 1 /* use separate squaring code? */
#endif
#ifndef MP_PTAB_SIZE
/*
When building mpprime.c, we build in a table of small prime
values to use for primality testing. The more you include,
the more space they take up. See primes.c for the possible
values (currently 16, 32, 64, 128, 256, and 6542)
*/
#define MP_PTAB_SIZE 128 /* how many built-in primes? */
#endif
#ifndef MP_COMPAT_MACROS
#define MP_COMPAT_MACROS 1 /* define compatibility macros? */
#endif
#endif /* ifndef MPI_CONFIG_H_ */
/* crc==3287762869, version==2, Sat Feb 02 06:43:53 2002 */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
@@ -0,0 +1,22 @@
#include <stdint.h>
/* Type definitions generated by 'types.pl' */
typedef char mp_sign;
typedef uint16_t mp_digit; /* 2 byte type */
typedef uint32_t mp_word; /* 4 byte type */
typedef unsigned int mp_size;
typedef int mp_err;
#define MP_DIGIT_BIT (CHAR_BIT*sizeof(mp_digit))
#define MP_DIGIT_MAX USHRT_MAX
#define MP_WORD_BIT (CHAR_BIT*sizeof(mp_word))
#define MP_WORD_MAX ULONG_MAX
#define MP_DIGIT_SIZE 2
#define DIGIT_FMT "%04X"
#define RADIX ((uint32_t)MP_DIGIT_MAX+1)
/* $Source$ */
/* $Revision$ */
/* $Date$ */
@@ -0,0 +1,232 @@
/*
mpi.h
by Michael J. Fromberger <sting@linguist.dartmouth.edu>
Copyright (C) 1998 Michael J. Fromberger
Arbitrary precision integer arithmetic library
SPDX-License-Identifier: Unlicense
$Id$
*/
#ifndef _H_MPI_
#define _H_MPI_
#include "mpi-config.h"
#define MP_LT -1
#define MP_EQ 0
#define MP_GT 1
#if MP_DEBUG
#undef MP_IOFUNC
#define MP_IOFUNC 1
#endif
#if MP_IOFUNC
#include <stdio.h>
#include <ctype.h>
#endif
#include <limits.h>
#define MP_NEG 1
#define MP_ZPOS 0
/* Included for compatibility... */
#define NEG MP_NEG
#define ZPOS MP_ZPOS
#define MP_OKAY 0 /* no error, all is well */
#define MP_YES 0 /* yes (boolean result) */
#define MP_NO -1 /* no (boolean result) */
#define MP_MEM -2 /* out of memory */
#define MP_RANGE -3 /* argument out of range */
#define MP_BADARG -4 /* invalid parameter */
#define MP_UNDEF -5 /* answer is undefined */
#define MP_LAST_CODE MP_UNDEF
#include "mpi-types.h"
/* Included for compatibility... */
#define DIGIT_BIT MP_DIGIT_BIT
#define DIGIT_MAX MP_DIGIT_MAX
/* Macros for accessing the mp_int internals */
#define SIGN(MP) ((MP)->sign)
#define USED(MP) ((MP)->used)
#define ALLOC(MP) ((MP)->alloc)
#define DIGITS(MP) ((MP)->dp)
#define DIGIT(MP,N) (MP)->dp[(N)]
#if MP_ARGCHK == 1
#define ARGCHK(X,Y) {if(!(X)){return (Y);}}
#elif MP_ARGCHK == 2
#include <assert.h>
#define ARGCHK(X,Y) assert(X)
#else
#define ARGCHK(X,Y) /* */
#endif
/* This defines the maximum I/O base (minimum is 2) */
#define MAX_RADIX 64
typedef struct {
mp_sign sign; /* sign of this quantity */
mp_size alloc; /* how many digits allocated */
mp_size used; /* how many digits used */
mp_digit *dp; /* the digits themselves */
} mp_int;
/*------------------------------------------------------------------------*/
/* Default precision */
unsigned int mp_get_prec(void);
void mp_set_prec(unsigned int prec);
/*------------------------------------------------------------------------*/
/* Memory management */
mp_err mp_init(mp_int *mp);
mp_err mp_init_array(mp_int mp[], int count);
mp_err mp_init_size(mp_int *mp, mp_size prec);
mp_err mp_init_copy(mp_int *mp, mp_int *from);
mp_err mp_copy(mp_int *from, mp_int *to);
void mp_exch(mp_int *mp1, mp_int *mp2);
void mp_clear(mp_int *mp);
void mp_clear_array(mp_int mp[], int count);
void mp_zero(mp_int *mp);
void mp_set(mp_int *mp, mp_digit d);
mp_err mp_set_int(mp_int *mp, long z);
mp_err mp_read_from_mem(mp_int *mp, uint16_t *data, uint16_t data_size);
mp_err mp_to_mem(mp_int *mp, uint16_t *data, uint16_t data_size);
mp_err mp_shrink(mp_int *a);
/*------------------------------------------------------------------------*/
/* Single digit arithmetic */
mp_err mp_add_d(mp_int *a, mp_digit d, mp_int *b);
mp_err mp_sub_d(mp_int *a, mp_digit d, mp_int *b);
mp_err mp_mul_d(mp_int *a, mp_digit d, mp_int *b);
mp_err mp_mul_2(mp_int *a, mp_int *c);
mp_err mp_div_d(mp_int *a, mp_digit d, mp_int *q, mp_digit *r);
mp_err mp_div_2(mp_int *a, mp_int *c);
mp_err mp_expt_d(mp_int *a, mp_digit d, mp_int *c);
/*------------------------------------------------------------------------*/
/* Sign manipulations */
mp_err mp_abs(mp_int *a, mp_int *b);
mp_err mp_neg(mp_int *a, mp_int *b);
/*------------------------------------------------------------------------*/
/* Full arithmetic */
mp_err mp_add(mp_int *a, mp_int *b, mp_int *c);
mp_err mp_sub(mp_int *a, mp_int *b, mp_int *c);
mp_err mp_mul(mp_int *a, mp_int *b, mp_int *c);
mp_err mp_mul_2d(mp_int *a, mp_digit d, mp_int *c);
#if MP_SQUARE
mp_err mp_sqr(mp_int *a, mp_int *b);
#else
#define mp_sqr(a, b) mp_mul(a, a, b)
#endif
mp_err mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r);
mp_err mp_div_2d(mp_int *a, mp_digit d, mp_int *q, mp_int *r);
mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c);
mp_err mp_2expt(mp_int *a, mp_digit k);
mp_err mp_sqrt(mp_int *a, mp_int *b);
/*------------------------------------------------------------------------*/
/* Modular arithmetic */
#if MP_MODARITH
mp_err mp_mod(mp_int *a, mp_int *m, mp_int *c);
mp_err mp_mod_d(mp_int *a, mp_digit d, mp_digit *c);
mp_err mp_addmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
mp_err mp_submod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
mp_err mp_mulmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
#if MP_SQUARE
mp_err mp_sqrmod(mp_int *a, mp_int *m, mp_int *c);
#else
#define mp_sqrmod(a, m, c) mp_mulmod(a, a, m, c)
#endif
mp_err mp_exptmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
mp_err mp_exptmod_d(mp_int *a, mp_digit d, mp_int *m, mp_int *c);
#endif /* MP_MODARITH */
/*------------------------------------------------------------------------*/
/* Comparisons */
int mp_cmp_z(mp_int *a);
int mp_cmp_d(mp_int *a, mp_digit d);
int mp_cmp(mp_int *a, mp_int *b);
int mp_cmp_mag(mp_int *a, mp_int *b);
int mp_cmp_int(mp_int *a, long z);
int mp_isodd(mp_int *a);
int mp_iseven(mp_int *a);
/*------------------------------------------------------------------------*/
/* Number theoretic */
#if MP_NUMTH
mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c);
mp_err mp_lcm(mp_int *a, mp_int *b, mp_int *c);
mp_err mp_xgcd(mp_int *a, mp_int *b, mp_int *g, mp_int *x, mp_int *y);
mp_err mp_invmod(mp_int *a, mp_int *m, mp_int *c);
#endif /* end MP_NUMTH */
/*------------------------------------------------------------------------*/
/* Input and output */
#if MP_IOFUNC
void mp_print(mp_int *mp, FILE *ofp);
#endif /* end MP_IOFUNC */
/*------------------------------------------------------------------------*/
/* Base conversion */
#define BITS 1
#define BYTES CHAR_BIT
mp_err mp_read_signed_bin(mp_int *mp, unsigned char *str, int len);
mp_err mp_read_unsigned_bin(mp_int *mp, unsigned char *str, int len);
int mp_count_bits(mp_int *mp);
#if MP_COMPAT_MACROS
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
#define mp_raw_size(mp) mp_signed_bin_size(mp)
#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
#endif
mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix);
int mp_radix_size(mp_int *mp, int radix);
int mp_value_radix_size(int num, int qty, int radix);
mp_err mp_toradix(mp_int *mp, char *str, int radix);
int mp_char2value(char ch, int r);
#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
#define mp_read_hex(M, S) mp_read_radix((M), (S), 16)
/*------------------------------------------------------------------------*/
/* Error strings */
const char *mp_strerror(mp_err ec);
#endif /* end _H_MPI_ */
/* $Source$ */
/* $Revision$ */
/* $Date$ */
@@ -0,0 +1,245 @@
//###########################################################################
//
// FILE: rsassa_pkcs1_v1_5.h
//
// TITLE: RSASSA-PKCS header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef __RSASSA_PKCS1_1V_5__
#define __RSASSA_PKCS1_1V_5__
#include "mpi.h"
//*****************************************************************************
//
// RSA Private Key data structure
//
//*****************************************************************************
typedef mp_int rsa_PrivateKey;
//*****************************************************************************
//
// RSA Public Key data structure
//
//*****************************************************************************
typedef mp_int rsa_PublicKey;
//*****************************************************************************
//
// RSA Modulus data structure
//
//*****************************************************************************
typedef mp_int rsa_Modulus;
//*****************************************************************************
//
// RSA Signature data structure
//
//*****************************************************************************
typedef mp_int rsa_Signature;
//*****************************************************************************
//
// RSA error data type
//
//*****************************************************************************
typedef mp_err rsa_err;
//*****************************************************************************
//
//! Initialize RSA Public Key data structure
//!
//! \param pub_key is the pointer to the rsa_PublicKey data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_pubkey(pub_key) mp_init(pub_key)
//*****************************************************************************
//
//! Initialize RSA Private Key data structure
//!
//! \param pvt_key is the pointer to the rsa_PrivateKey data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_pvtkey(pvt_key) mp_init(pvt_key)
//*****************************************************************************
//
//! Initialize RSA Modulus data structure
//!
//! \param modulus is the pointer to the rsa_Modulus data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_modulus(modulus) mp_init(modulus)
//*****************************************************************************
//
//! Initialize RSA signature data structure
//!
//! \param pub_key is the pointer to the rsa_Signature data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_signature(sign) mp_init(sign)
//*****************************************************************************
//
//! Set RSA public key value in the data structure from a hex string
//!
//! \param pub_key is the pointer to the rsa_PublicKey data structure
//! \param pub_key_hex is the public key hex string (without the '0x' prefix)
//!
//! \return Returns MP_OKAY if successful. One of the failure macros
//! defined in mpi.h depending on the type of failure.
//
//*****************************************************************************
#define rsa_set_pubkey_from_hex(pub_key, pub_key_hex) \
mp_read_hex(pub_key, pub_key_hex)
//*****************************************************************************
//
//! Set RSA private key value in the data structure from a hex string
//!
//! \param pvt_key is the pointer to the rsa_PrivateKey data structure
//! \param pvt_key_hex is the private key hex string (without the '0x' prefix)
//!
//! \return Returns MP_OKAY if successful. One of the failure macros
//! defined in mpi.h depending on the type of failure.
//
//*****************************************************************************
#define rsa_set_pvtkey_from_hex(pvt_key, pvt_key_hex) \
mp_read_hex(pvt_key, pvt_key_hex)
//*****************************************************************************
//
//! Set RSA modulus value in the data structure from a hex string
//!
//! \param modulus is the pointer to the rsa_Modulus data structure
//! \param modulus_hex is the modulus hex string (without the '0x' prefix)
//!
//! \return Returns MP_OKAY if successful. One of the failure macros
//! defined in mpi.h depending on the type of failure.
//
//*****************************************************************************
#define rsa_set_modulus_from_hex(modulus, modulus_hex ) \
mp_read_hex(modulus, modulus_hex)
//*****************************************************************************
//
//! Extract RSA signature value to a byte array
//!
//! \param sign is the pointer to the rsa_Signature data structure
//! \param sign_str is the pointer to the string where signature has to be
//! written
//! \param sign_len is the length of the signature in bytes
//!
//! \return Returns MP_OKAY if successful.
//
//*****************************************************************************
#define rsa_signature_to_mem(sign, sign_str, sign_len ) \
mp_to_mem(sign, sign_str, sign_len);
//*****************************************************************************
//
//! Function to write data represented in a hex string into the memory bytewise
//!
//! \param hex_str is the hex string (without the '0x' prefix)
//! \param data is the pointer to the memory location where the data will be
//! written
//!
//! \return Returns 0 if successful
//! 3 if the hex string is invalid
//
//*****************************************************************************
rsa_err rsa_hex_to_data(unsigned char* hex_str, uint16_t* data);
//*****************************************************************************
//
//! Function to generate a signature of the data using RSASSA-PKCS algorithm
//!
//! \param key_pvt is the pointer to the rsa_PrivateKey data structure holding
//! the RSA private key value
//! \param modulus is the pointer to the rsa_Modulus data structure holding
//! the RSA modulus value
//! \param sign is the pointer to the rsa_Signature data structure which
//! will hold the generated the signature
//! \param hash is the pointer to the byte wise hash digest of the message
//! \param hash_size is the size of the hash based on the SHA encoding type
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
rsa_err rsassa_pkcs1_v1_5_sign(rsa_PrivateKey* key_pvt, rsa_Modulus* modulus,
rsa_Signature* sign, uint16_t *hash, uint16_t hash_size);
//*****************************************************************************
//
//! Function to verify the signature of a data using RSASSA-PKCS algorithm
//!
//! \param sign is the pointer to the rsa_Signature data structure holding
//! the signature to be verified
//! \param hash is the pointer to the bytewise hash digest of the message
//! \param hashlen is the length of the hash digest of the message in bytes
//! \param key_pub is the pointer to the rsa_PublicKey data structure holding
//! the RSA public key value
//! \param modulus is the pointer to the rsa_Modulus data structure holding
//! the RSA modulus value
//! \param result is the pointer to the verification result
//! 1 - Verification successful
//! 0 - Incorrect signature. Verification failed
//! -1 - Verification incomplete
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
rsa_err rsassa_pkcs1_v1_5_verify(rsa_Signature* sign, uint16_t* hash, uint16_t hashlen,
uint16_t mod_len, rsa_PublicKey* key_pub,
rsa_Modulus* modulus,
int16_t* result);
#endif
@@ -0,0 +1,253 @@
//###########################################################################
//
// FILE: rsassa_pss.h
//
// TITLE: RSASSA-PSS header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef RSASSA_PSS_H_
#define RSASSA_PSS_H_
#include "mpi.h"
#include "yarrow.h"
//*****************************************************************************
//
// RSA Private Key data structure
//
//*****************************************************************************
typedef mp_int rsa_PrivateKey;
//*****************************************************************************
//
// RSA Public Key data structure
//
//*****************************************************************************
typedef mp_int rsa_PublicKey;
//*****************************************************************************
//
// RSA Modulus data structure
//
//*****************************************************************************
typedef mp_int rsa_Modulus;
//*****************************************************************************
//
// RSA Signature data structure
//
//*****************************************************************************
typedef mp_int rsa_Signature;
//*****************************************************************************
//
// RSA error data type
//
//*****************************************************************************
typedef mp_err rsa_err;
//*****************************************************************************
//
//! Initialize RSA Public Key data structure
//!
//! \param pub_key is the pointer to the rsa_PublicKey data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_pubkey(pub_key) mp_init(pub_key)
//*****************************************************************************
//
//! Initialize RSA Private Key data structure
//!
//! \param pvt_key is the pointer to the rsa_PrivateKey data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_pvtkey(pvt_key) mp_init(pvt_key)
//*****************************************************************************
//
//! Initialize RSA Modulus data structure
//!
//! \param modulus is the pointer to the rsa_Modulus data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_modulus(modulus) mp_init(modulus)
//*****************************************************************************
//
//! Initialize RSA signature data structure
//!
//! \param pub_key is the pointer to the rsa_Signature data structure
//!
//! \return Returns MP_OKAY if successful, MP_MEM if memory could not be
//! allocated for the structure.
//
//*****************************************************************************
#define rsa_init_signature(sign) mp_init(sign)
//*****************************************************************************
//
//! Set RSA public key value in the data structure from a hex string
//!
//! \param pub_key is the pointer to the rsa_PublicKey data structure
//! \param pub_key_hex is the public key hex string (without the '0x' prefix)
//!
//! \return Returns MP_OKAY if successful. One of the failure macros
//! defined in mpi.h depending on the type of failure.
//
//*****************************************************************************
#define rsa_set_pubkey_from_hex(pub_key, pub_key_hex) \
mp_read_hex(pub_key, pub_key_hex)
//*****************************************************************************
//
//! Set RSA private key value in the data structure from a hex string
//!
//! \param pvt_key is the pointer to the rsa_PrivateKey data structure
//! \param pvt_key_hex is the private key hex string (without the '0x' prefix)
//!
//! \return Returns MP_OKAY if successful. One of the failure macros
//! defined in mpi.h depending on the type of failure.
//
//*****************************************************************************
#define rsa_set_pvtkey_from_hex(pvt_key, pvt_key_hex) \
mp_read_hex(pvt_key, pvt_key_hex)
//*****************************************************************************
//
//! Set RSA modulus value in the data structure from a hex string
//!
//! \param modulus is the pointer to the rsa_Modulus data structure
//! \param modulus_hex is the modulus hex string (without the '0x' prefix)
//!
//! \return Returns MP_OKAY if successful. One of the failure macros
//! defined in mpi.h depending on the type of failure.
//
//*****************************************************************************
#define rsa_set_modulus_from_hex(modulus, modulus_hex ) \
mp_read_hex(modulus, modulus_hex)
//*****************************************************************************
//
//! Extract RSA signature value to a byte array
//!
//! \param sign is the pointer to the rsa_Signature data structure
//! \param sign_str is the pointer to the string where signature has to be
//! written
//! \param sign_len is the length of the signature in bytes
//!
//! \return Returns MP_OKAY if successful.
//
//*****************************************************************************
#define rsa_signature_to_mem(sign, sign_str, sign_len ) \
mp_to_mem(sign, sign_str, sign_len);
//*****************************************************************************
//
//! Function to write data represented in a hex string into the memory bytewise
//!
//! \param hex_str is the hex string (without the '0x' prefix)
//! \param data is the pointer to the memory location where the data will be
//! written
//!
//! \return Returns 0 if successful
//! 3 if the hex string is invalid
//
//*****************************************************************************
rsa_err rsa_hex_to_data(unsigned char *hex_str, uint16_t *data);
//*****************************************************************************
//
//! Function to generate a signature of the data using RSASSA-PSS algorithm
//!
//! \param hash is the pointer to the bytewise hash digest of the message
//! \param hashlen is the length of the hash digest of the message in bytes
//! \param saltlen is the length of the random salt in bytes
//! \param key_pvt is the pointer to the rsa_PrivateKey data structure holding
//! the RSA private key value
//! \param modulus is the pointer to the rsa_Modulus data structure holding
//! the RSA modulus value
//! \param modulus_bitlen is the length of the RSA modulus in bits (not bytes)
//! \param prng is the pointer to the yarrow prng handler to generate
//! random salt
//! \param sign is the pointer to the rsa_Signature data structure which
//! will hold the generated the signature
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
rsa_err rsassa_pss_sign(uint16_t *hash, uint16_t hashlen, uint16_t saltlen,
rsa_PrivateKey *key_pvt, rsa_Modulus *modulus,
uint16_t modulus_bitlen, yarrow_prng *prng,
rsa_Signature *sign);
//*****************************************************************************
//
//! Function to verify the signature of a data using RSASSA-PSS algorithm
//!
//! \param sign is the pointer to the rsa_Signature data structure holding
//! the signature to be verified
//! \param hash is the pointer to the bytewise hash digest of the message
//! \param hashlen is the length of the hash digest of the message in bytes
//! \param saltlen is the length of the random salt in bytes
//! \param key_pub is the pointer to the rsa_PublicKey data structure holding
//! the RSA public key value
//! \param modulus is the pointer to the rsa_Modulus data structure holding
//! the RSA modulus value
//! \param modulus_bitlen is the length of the RSA modulus in bits (not bytes)
//! \param result is the pointer to the verification result
//! 1 - Verification successful
//! 0 - Incorrect signature. Verification failed
//! -1 - Verification incomplete
//!
//! \return Returns PKCS_STATUS_SUCCESS if successful
//
//*****************************************************************************
rsa_err rsassa_pss_verify( rsa_Signature *sign, uint16_t *hash, uint16_t hashlen,
uint16_t saltlen, rsa_PublicKey *key_pub,
rsa_Modulus *modulus, uint16_t modulus_bitlen,
int16_t *result);
#endif /* RSASSA_PSS_H_ */
@@ -0,0 +1,136 @@
//###########################################################################
//
// FILE: yarrow.h
//
// TITLE: Yarrow PRNG algorithm header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef YARROW_H_
#define YARROW_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include "aes_ctr.h"
#include "sha256.h"
typedef unsigned char uc;
#define MAXBLOCKSIZE 144
#define YARROW_STATUS_SUCCESS 1
#define YARROW_STATUS_ERROR_NULL -1
//*****************************************************************************
//
// Data structure to handle Yarrow PRNG algortithm
//
//*****************************************************************************
typedef struct yarrow_prng
{
uc pool[MAXBLOCKSIZE];
uc ready;
uc nounceCounter[16];
uc key[32];
} yarrow_prng;
//*****************************************************************************
//
//! Initialize yarrow handle with nounce counter values
//!
//! \param prng is the pointer to the yarrow PRNG handle
//! \param nounceCounter is the pointer to the array which contains the counter
//! values to be initialized with
//!
//! \return Returns YARROW_STATUS_SUCCESS if successful.
//
//*****************************************************************************
int yarrow_init_with_nounce(yarrow_prng *prng, const uc *nounceCounter);
//*****************************************************************************
//
//! Initialize yarrow handle with default nounce counter value '0'
//!
//! \param prng is the pointer to the yarrow PRNG handle
//!
//! \return Returns YARROW_STATUS_SUCCESS if successful.
//
//*****************************************************************************
int yarrow_init_default_nounce(yarrow_prng *prng);
//*****************************************************************************
//
//! Introduce entropy in the algorithm to generate pseudo-random values
//!
//! \param in is the random input string which will be used to introduce entropy
//! \param inlen is the length of the random input string
//! \param prng is the pointer to the yarrow PRNG handle
//!
//! \return Returns YARROW_STATUS_SUCCESS if successful.
//
//*****************************************************************************
int yarrow_add_entropy(uc *in, const uint32_t inlen, yarrow_prng *prng);
//*****************************************************************************
//
//! Prepare the yarrow PRNG handle to generate random values
//!
//! \param prng is the pointer to the yarrow PRNG handle
//!
//! \return Returns YARROW_STATUS_SUCCESS if successful.
//
//*****************************************************************************
int yarrow_ready(yarrow_prng *prng);
//*****************************************************************************
//
//! Read random values using yarrow PRNG
//!
//! \param prng is the pointer to the yarrow PRNG handle
//! \param out is the output string of random values
//! \param outlen is the length of the output string of random values
//!
//! \return Returns outlen if successful.
//
//*****************************************************************************
int yarrow_read(yarrow_prng *prng, uc *out, uc outlen);
#ifdef __cplusplus
}
#endif
#endif /* YARROW_H_ */
@@ -0,0 +1,165 @@
//###########################################################################
//
// FILE: emsa_pkcs1_v1_5.c
//
// TITLE: EMSA-PKCS message encoding and decoding
//
//###########################################################################
#include "emsa_pkcs1_v1_5.h"
#include <stdlib.h>
#include <string.h>
//*****************************************************************************
//
//ASN.1 defines
//
//*****************************************************************************
#define ASN_1_ENCODING 0x20
#define ASN_1_TYPE_BIT_STR 0x03
#define ASN_1_TYPE_OCTET_STR 0x04
#define ASN_1_TYPE_NULL 0x05
#define ASN_1_TYPE_OBJ_ID 0x06
#define ASN_1_TYPE_SEQ 0x10
//*****************************************************************************
//
//SHA256 related data for padding
//
//*****************************************************************************
#define SHA256_DIGEST_SIZE 0x20
//*****************************************************************************
//
//SHA384 related data for padding
//
//*****************************************************************************
#define SHA384_DIGEST_SIZE 0x30
//*****************************************************************************
//
//SHA384 digest size (384 bits = 32 bytes)
//
//*****************************************************************************
#define SHA256_DIGEST_SIZE 0x20
//*****************************************************************************
//
//SHA256 with ASN.1 padding
//
//*****************************************************************************
const uint16_t SHA256_ASN_1_PADDING[ASN_1_PAD_SIZE] = \
{ \
0x00, 0x01, \
0xFF, 0xFF, 0xFF, 0xFF, \
0xFF, 0xFF, 0xFF, 0xFF, \
0x00, \
0x30, 0x31, 0x30, 0x0D, \
0x06, 0x09, 0x60, 0x86, \
0x48, 0x01, 0x65, 0x03, \
0x04, 0x02, 0x01, 0x05, \
0x00, 0x04, 0x20
};
//*****************************************************************************
//
//SHA384 with ASN.1 padding
//
//*****************************************************************************
const uint16_t SHA384_ASN_1_PADDING[ASN_1_PAD_SIZE] = \
{ \
0x00, 0x01, \
0xFF, 0xFF, 0xFF, 0xFF, \
0xFF, 0xFF, 0xFF, 0xFF, \
0x00, \
0x30, 0x41, 0x30, 0x0D, \
0x06, 0x09, 0x60, 0x86, \
0x48, 0x01, 0x65, 0x03, \
0x04, 0x02, 0x02, 0x05, \
0x00, 0x04, 0x30
};
//*****************************************************************************
//
// EMSA-PKCS1 encode message
//
//*****************************************************************************
int emsa_pkcs1_v1_5_encode(uint16_t* emsa_out, uint16_t* hash, uint16_t hash_size)
{
const uint16_t* shaPadding = NULL;
if(emsa_out == NULL)
{
return PKCS_STATUS_FAILURE_MEM;
}
if(hash_size == SHA256_HASH_SIZE)
{
shaPadding = SHA256_ASN_1_PADDING;
}
else if(hash_size == SHA384_HASH_SIZE)
{
shaPadding = SHA384_ASN_1_PADDING;
}
// Pad the sequence as EM = 0x00 || 0x01 || PS || 0x00 || T
memcpy(emsa_out, shaPadding, ASN_1_PAD_SIZE);
//Append the hash value
memcpy(emsa_out + ASN_1_PAD_SIZE, hash, hash_size);
return PKCS_STATUS_SUCCESS;
}
//*****************************************************************************
//
// Function to verify the signature of a data using RSASSA-PKCS algorithm
//
//*****************************************************************************
int emsa_pkcs1_v1_5_decode(uint16_t* EM_Str, uint16_t *hash, uint16_t hash_size, int16_t* result)
{
int err = 0;
const uint16_t* shaPadding = NULL;
if ((EM_Str == NULL) || (result == NULL))
{
*result = -1;
return PKCS_STATUS_FAILURE_NULL;
}
*result = -1;
//Check signature length is more than the length of 0x00 || 0x01 || PS || 0x00 || T
if(hash_size == SHA256_HASH_SIZE)
{
shaPadding = SHA256_ASN_1_PADDING;
}
else if(hash_size == SHA384_HASH_SIZE)
{
shaPadding = SHA384_ASN_1_PADDING;
}
//
// Check Padding
//
if(memcmp(EM_Str, shaPadding, ASN_1_PAD_SIZE) != 0)
{
*result = 0;
return PKCS_STATUS_FAILURE;
}
// Compare expected hash vs computed hash
if(memcmp(EM_Str + ASN_1_PAD_SIZE, hash, hash_size) != 0)
{
*result = 0;
return PKCS_STATUS_FAILURE;
}
*result = 1;
return err;
}
//
// End of file
//
@@ -0,0 +1,555 @@
//###########################################################################
//
// FILE: emsa_pss.c
//
// TITLE: EMSA-PSS message encoding and decoding
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "emsa_pss.h"
#include "yarrow.h"
#include "sha256.h"
#include <stdlib.h>
#include <string.h>
//*****************************************************************************
//
// SHA-256 handle
//
//*****************************************************************************
extern SHA256_ObjectByteWise md;
//*****************************************************************************
//
// PKCS1_MGF mask generation using SHA-256
//
//*****************************************************************************
int pkcs_1_mgf(uint16_t *seed, int16_t seedlen, uint16_t *mask, int16_t masklen)
{
int16_t hLen, x, err;
uint32_t counter;
uint16_t *buf;
if (seed == NULL || mask == NULL)
{
return PKCS_STATUS_FAILURE_NULL;
}
hLen = HASH_SIZE;
buf = malloc(hLen * sizeof(uint16_t));
if (buf == NULL)
{
return PKCS_STATUS_FAILURE_MEM;
}
counter = 0;
while (masklen > 0)
{
//
// handle counter
//
STORE32H(counter, buf);
++counter;
uint32_t digest[8];
int i, j;
if ((err = SHA256_startByteWise(&md)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)seed, seedlen)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)buf, 4)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_finalizeByteWise(&md, digest)) != SHA256_STATUS_SUCCESS)
{
return err;
}
for (i = 0, j = 0; i < (HASH_SIZE/4) && j < HASH_SIZE; i++)
{
buf[j++] = (digest[i] >> 24) & 255;
buf[j++] = (digest[i] >> 16) & 255;
buf[j++] = (digest[i] >> 8) & 255;
buf[j++] = (digest[i]) & 255;
}
//
// store it
//
for (x = 0; x < hLen && masklen > 0; x++, masklen--)
{
*mask++ = buf[x];
}
}
free(buf);
return PKCS_STATUS_SUCCESS;
}
//*****************************************************************************
//
// EMSA-PSS encode message
//
//*****************************************************************************
int emsa_pss_encode(uint16_t *msghash, uint16_t msghashlen, uint16_t saltlen,
uint16_t modulus_bitlen, yarrow_prng *prng,
uint16_t *emsa_out, uint16_t emsa_outlen)
{
uint16_t *DB, *mask, *salt, *hash;
uint16_t x, y, hLen, modulus_len;
int err, i ,j;
if ((msghash == NULL) || (emsa_out == NULL) || (msghashlen <= 0))
{
return PKCS_STATUS_FAILURE_NULL;
}
hLen = HASH_SIZE;
modulus_bitlen--;
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
//
// check sizes
//
if ((saltlen > modulus_len) || (modulus_len < hLen + saltlen + 2))
{
return PKCS_STATUS_FAILURE_SIZE;
}
//
// allocate ram for DB/mask/salt/hash
//
DB = (uint16_t *)malloc((modulus_len - hLen - 1) * sizeof(uint16_t));
mask = (uint16_t *)malloc((modulus_len - hLen -1) * sizeof(uint16_t));
salt = (uint16_t *)malloc(saltlen * sizeof(uint16_t));
hash = (uint16_t *)malloc(hLen * sizeof(uint16_t));
if (DB == NULL || mask == NULL || salt == NULL || hash == NULL)
{
if (DB != NULL)
{
free(DB);
}
if (mask != NULL)
{
free(mask);
}
if (salt != NULL)
{
free(salt);
}
if (hash != NULL)
{
free(hash);
}
return PKCS_STATUS_FAILURE_MEM;
}
if (saltlen > 0)
{
//
// Generate random salt using yarrow PRNG
//
if (yarrow_read(prng, (uc *)salt, saltlen) != saltlen)
{
return PKCS_STATUS_FAILURE_READ;
}
}
for (i = 0; i < 8; i++)
DB[i] = '\0';
uint32_t digest[8];
//
// M = (eight) 0x00 || msghash || salt, hash = H(M)
//
if ((err = SHA256_startByteWise(&md)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)DB, 8)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)msghash, msghashlen)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)salt, saltlen)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_finalizeByteWise(&md, digest)) != SHA256_STATUS_SUCCESS)
{
return err;
}
for (i = 0, j = 0; i < (HASH_SIZE/4) && j < HASH_SIZE; i++)
{
hash[j++] = (digest[i] >> 24) & 255;
hash[j++] = (digest[i] >> 16) & 255;
hash[j++] = (digest[i] >> 8) & 255;
hash[j++] = (digest[i]) & 255;
}
//
// generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes
//
x = 0;
//
// memset(DB+x, 0, modulus_len - saltlen - hLen - 2);
//
for (x = 0; x < modulus_len - saltlen - hLen - 2; x++)
{
DB[x] = 0;
}
DB[x++] = 0x01;
//
// memcpy(DB + x, salt, saltlen);
//
for (i = 0; i < saltlen; i++)
{
DB[x++] = salt[i];
}
//
// x += saltlen;
// generate mask of length modulus_len - hLen - 1 from hash
//
if ((err = pkcs_1_mgf(hash, hLen, mask, modulus_len - hLen - 1)) != PKCS_STATUS_SUCCESS)
{
return PKCS_STATUS_FAILURE;
}
//
// xor against DB
//
for (y = 0; y < (modulus_len - hLen - 1); y++)
{
DB[y] ^= mask[y];
}
//
// output is DB || hash || 0xBC
//
if (emsa_outlen < modulus_len)
{
emsa_outlen = modulus_len;
err = PKCS_STATUS_FAILURE_MEM;
return err;
}
//
// DB len = modulus_len - hLen - 1
//
y = 0;
//
// memcpy(out + y, DB, modulus_len - hLen - 1);
//
for (y = 0; y < modulus_len - hLen - 1; y++)
{
emsa_out[y] = DB[y];
}
//
// y += modulus_len - hLen - 1;
// hash: memcpy(out + y, hash, hLen);
//
for (i = 0; i < hLen; i++)
{
emsa_out[y++] = hash[i];
}
//
// y += hLen;
// 0xBC
//
emsa_out[y] = 0xBC;
//
// now clear the 8*modulus_len - modulus_bitlen most significant bits
//
emsa_out[0] &= 0xFF >> ((modulus_len << 3) - modulus_bitlen);
//
// store output size
//
emsa_outlen = modulus_len;
err = PKCS_STATUS_SUCCESS;
//
// Free allocated memory
//
free(hash);
free(salt);
free(mask);
free(DB);
return err;
}
//*****************************************************************************
//
// Function to verify the signature of a data using RSASSA-PSS algorithm
//
//*****************************************************************************
int emsa_pss_decode(uint16_t *sig, uint16_t siglen, uint16_t *msghash, uint16_t msghashlen,
uint16_t saltlen, uint16_t modulus_bitlen, int16_t *res)
{
uint16_t *DB, *mask, *salt, *hash;
int x, y, hLen, modulus_len, i, j;
int err;
*res = -1;
if ((msghash == NULL) || (sig == NULL))
{
return PKCS_STATUS_FAILURE_NULL;
}
hLen = HASH_SIZE;
modulus_bitlen--;
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
//
// check sizes
//
if ((saltlen > modulus_len) ||
(modulus_len < hLen + saltlen + 2))
{
return PKCS_STATUS_FAILURE_SIZE;
}
//
// allocate ram for DB/mask/salt/hash
//
DB = (uint16_t *)malloc((modulus_len - hLen - 1) * sizeof(uint16_t));
mask = (uint16_t *)malloc((modulus_len - hLen -1) * sizeof(uint16_t));
salt = (uint16_t *)malloc(saltlen * sizeof(uint16_t));
hash = (uint16_t *)malloc(hLen * sizeof(uint16_t));
if (DB == NULL || mask == NULL || salt == NULL || hash == NULL)
{
if (DB != NULL)
{
free(DB);
}
if (mask != NULL)
{
free(mask);
}
if (salt != NULL)
{
free(salt);
}
if (hash != NULL)
{
free(hash);
}
return PKCS_STATUS_FAILURE_MEM;
}
//
// ensure the 0xBC byte
//
if (sig[siglen - 1] != 0xBC)
{
err = PKCS_STATUS_FAILURE;
*res = 0;
return err;
}
//
// copy out the DB
//
x = 0;
//
// memcpy(DB, sig + x, modulus_len - hLen - 1);
//
for (x = 0; x < modulus_len - hLen - 1; x++)
{
DB[x] = sig[x];
}
//
// x += modulus_len - hLen - 1;
// copy out the hash
// memcpy(hash, sig + x, hLen);
//
for (i = 0; i < hLen; i++)
{
hash[i] = sig[x++];
}
//
// check the MSB
//
if ((sig[0] & ~(0xFF >> ((modulus_len << 3) - (modulus_bitlen)))) != 0)
{
err = PKCS_STATUS_FAILURE;
*res = 0;
return err;
}
//
// generate mask of length modulus_len - hLen - 1 from hash
//
if ((err = pkcs_1_mgf(hash, hLen, mask, modulus_len - hLen - 1)) != PKCS_STATUS_SUCCESS)
{
return PKCS_STATUS_FAILURE;
}
//
// xor against DB
//
for (y = 0; y < (modulus_len - hLen - 1); y++)
{
DB[y] ^= mask[y];
}
//
// now clear the first byte [make sure smaller than modulus
//
DB[0] &= 0xFF >> ((modulus_len << 3) - (modulus_bitlen));
for (x = 0; x < modulus_len - saltlen - hLen - 2; x++)
{
if (DB[x] != 0x00)
{
err = PKCS_STATUS_FAILURE;
*res = 0;
return err;
}
}
//
// check for the 0x01
//
if (DB[x++] != 0x01)
{
err = PKCS_STATUS_FAILURE;
*res = 0;
return err;
}
//
// M = (eight) 0x00 || msghash || salt, mask = H(M)
//
uint32_t digest[8];
if ((err = SHA256_startByteWise(&md)) != SHA256_STATUS_SUCCESS)
{
return err;
}
for (i = 0; i < 8; i++)
{
mask[i] = '\0';
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)mask, 8)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)msghash, msghashlen)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_addDataByteWise(&md, (uint16_t *)DB + x, saltlen)) != SHA256_STATUS_SUCCESS)
{
return err;
}
if ((err = SHA256_finalizeByteWise(&md, digest)) != SHA256_STATUS_SUCCESS)
{
return err;
}
for (i = 0, j = 0; i < (HASH_SIZE/4) && j < HASH_SIZE; i++)
{
mask[j++] = (digest[i] >> 24) & 255;
mask[j++] = (digest[i] >> 16) & 255;
mask[j++] = (digest[i] >> 8) & 255;
mask[j++] = (digest[i]) & 255;
}
for (i = 0; i < hLen; i++)
{
if (mask[i] != hash[i])
{
err = PK_STATUS_INVALID;
break;
}
}
if (err != PK_STATUS_INVALID)
{
err = PKCS_STATUS_SUCCESS;
*res = 1;
}
else
{
*res = 0;
}
//
// Free allocated memory
//
free(hash);
free(salt);
free(mask);
free(DB);
return err;
}
//
// End of file
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,157 @@
//###########################################################################
//
// FILE: rsassa_pkcs1_v1_5.c
//
// TITLE: RSASSA-PKCS algorithm to generate and verify digital signature
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "rsassa_pkcs1_v1_5.h"
#include "emsa_pkcs1_v1_5.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
rsa_err rsassa_pkcs1_v1_5_sign(rsa_PrivateKey* key_pvt, rsa_Modulus* modulus,
rsa_Signature* sign, uint16_t *hash, uint16_t hash_size)
{
//Array to hold the padding string
uint16_t EM_str[256];
//Padding length
uint16_t EM_len = ASN_1_PAD_SIZE + hash_size;
//
// Multiple precision integer to hold the encoded message
//
mp_int EM;
//
// EMSA-PKCS1 encoding of the message hash
//
if(PKCS_STATUS_SUCCESS != emsa_pkcs1_v1_5_encode(EM_str, hash, hash_size))
{
return -1;
}
if(0 != mp_init(&EM))
{
return -1;
}
if(0 != mp_read_from_mem(&EM, EM_str, EM_len))
{
mp_clear(&EM);
return -1;
}
//
// Modular exponentiation to generate signature
//
if(0 != mp_exptmod(&EM, key_pvt, modulus, sign))
{
mp_clear(&EM);
mp_clear(sign);
return -1;
}
mp_clear(&EM);
return 0;
}
rsa_err rsassa_pkcs1_v1_5_verify(rsa_Signature* sign, uint16_t* hash, uint16_t hash_size,
uint16_t mod_len, rsa_PublicKey* key_pub,
rsa_Modulus* modulus,
int16_t* result)
{
rsa_err rErr = 0;
//
// Array to hold the PKCS encoding of the message
//
uint16_t *EM_str = NULL;
//
// Multiple precision integer to hold the encoded message
//
mp_int EM;
if(mp_init(&EM) != 0)
{
*result = -1;
return -1;
}
//
// Modular exponentiation to generate the message encoding from the signature
//
if(mp_exptmod(sign, key_pub, modulus, &EM) != 0)
{
*result = -1;
mp_clear(&EM);
return -1;
}
EM_str = (uint16_t *)malloc(mod_len);
if(EM_str == NULL)
{
*result = -1;
return -1;
}
if(mp_to_mem(&EM, EM_str, mod_len) != 0)
{
*result = -1;
free(EM_str);
mp_clear(&EM);
return -1;
}
rErr = emsa_pkcs1_v1_5_decode(EM_str, hash, hash_size, result);
if(EM_str)
{
free(EM_str);
}
mp_clear(&EM);
return rErr;
}
@@ -0,0 +1,181 @@
//###########################################################################
//
// FILE: rsassa_pss.c
//
// TITLE: RSASSA-PSS algorithm to generate and verify digital signature
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "rsassa_pss.h"
#include "emsa_pss.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
//*****************************************************************************
//
// Function to write data represented in a hex string into the memory bytewise
//
//*****************************************************************************
rsa_err rsa_hex_to_data(unsigned char *hex_str, uint16_t *data)
{
rsa_err err = 0;
uint16_t i = 0, j = 0;
while(i < strlen((char *)hex_str))
{
if (((uint16_t)hex_str[i] >= 48) && ((uint16_t)hex_str[i] <= 57))
data[j] = (uint16_t)hex_str[i] - 48;
else if (((uint16_t)hex_str[i] >= 65) && ((uint16_t)hex_str[i] <= 70))
data[j] = (uint16_t)hex_str[i] - 55;
else if (((uint16_t)hex_str[i] >= 97) && ((uint16_t)hex_str[i] <= 102))
data[j] = (uint16_t)hex_str[i] - 87;
else
{
err = 3;
return err;
}
if(++i >= strlen((char *)hex_str))
break;
data[j] <<= 4;
if (((uint16_t)hex_str[i] >= 48) && ((uint16_t)hex_str[i] <= 57))
data[j] |= ((uint16_t)hex_str[i] - 48);
else if (((uint16_t)hex_str[i] >= 65) && ((uint16_t)hex_str[i] <= 70))
data[j] |= ((uint16_t)hex_str[i] - 55);
else if (((uint16_t)hex_str[i] >= 97) && ((uint16_t)hex_str[i] <= 102))
data[j] |= ((uint16_t)hex_str[i] - 87);
else
{
err = 3;
return err;
}
i++;
j++;
}
return err;
}
//*****************************************************************************
//
// Function to generate a signature of the data using RSASSA-PSS algorithm
//
//*****************************************************************************
rsa_err rsassa_pss_sign(uint16_t *hash, uint16_t hashlen, uint16_t saltlen,
rsa_PrivateKey *key_pvt, rsa_Modulus *modulus,
uint16_t modulus_bitlen, yarrow_prng *prng,
rsa_Signature *sign)
{
rsa_err err;
uint16_t EM_len = modulus_bitlen/8;
//
// Array to hold the pss encoding of the message
//
uint16_t *EM_str = (uint16_t *)malloc(EM_len);
//
// Multiple precision integer to hold the encoded message
//
mp_int EM;
//
// EMSA-PSS encoding of the message hash
//
err = emsa_pss_encode(hash, hashlen, saltlen, modulus_bitlen, prng, \
EM_str, EM_len);
mp_init(&EM);
mp_read_from_mem(&EM, EM_str, EM_len);
mp_init(sign);
//
// Modular exponentiation to generate signature
//
mp_exptmod(&EM, key_pvt, modulus, sign);
return err;
}
//*****************************************************************************
//
// Function to verify the signature of a data using RSASSA-PSS algorithm
//
//
//*****************************************************************************
rsa_err rsassa_pss_verify( rsa_Signature *sign, uint16_t *hash, uint16_t hashlen,
uint16_t saltlen, rsa_PublicKey *key_pub,
rsa_Modulus *modulus, uint16_t modulus_bitlen,
int16_t *result)
{
rsa_err err;
uint16_t EM_len = modulus_bitlen/8;
//
// Array to hold the pss encoding of the message
//
uint16_t *EM_str = (uint16_t *)malloc(EM_len);
//
// Multiple precision integer to hold the encoded message
//
mp_int EM;
mp_init(&EM);
//
// Modular exponentiation to generate the message encoding from the signature
//
mp_exptmod(sign, key_pub, modulus, &EM);
mp_to_mem(&EM, EM_str, EM_len);
//
// EMSA-PSS decoding to verify the message encoding
//
err = emsa_pss_decode(EM_str, EM_len, hash, hashlen, saltlen, modulus_bitlen, result);
return err;
}
//
// End of file
//
@@ -0,0 +1,251 @@
//###########################################################################
//
// FILE: yarrow.c
//
// TITLE: Yarrow PRNG algorithm
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include "yarrow.h"
//
// SHA-256 handle
//
SHA256_ObjectByteWise hash;
//*****************************************************************************
//
// Initialize yarrow handle with nounce counter values
//
//*****************************************************************************
int yarrow_init_with_nounce(yarrow_prng *prng, const uc *nounceCounter)
{
if(prng == NULL || nounceCounter == NULL)
{
return YARROW_STATUS_ERROR_NULL;
}
uint32_t i = 0;
while (i < MAXBLOCKSIZE)
{
prng->pool[i] = 0;
i++;
}
prng->ready = 0;
for (i = 0; i < 16U; i++)
{
prng->nounceCounter[i] = nounceCounter[i];
}
return YARROW_STATUS_SUCCESS;
}
//*****************************************************************************
//
// Initialize yarrow handle with default nounce counter value '0'
//
//*****************************************************************************
int yarrow_init_default_nounce(yarrow_prng *prng)
{
if(prng == NULL)
{
return YARROW_STATUS_ERROR_NULL;
}
uint32_t i = 0;
while (i < MAXBLOCKSIZE)
{
prng->pool[i] = 0;
i++;
}
prng->ready = 0;
for (i = 0; i < 16U; i++)
{
prng->nounceCounter[i] = 0;
}
return YARROW_STATUS_SUCCESS;
}
//*****************************************************************************
//
// Introduce entropy in the algorithm to generate pseudo-random values
//
//*****************************************************************************
int yarrow_add_entropy(uc *in, const uint32_t inlen, yarrow_prng *prng)
{
if(prng == NULL || in == NULL || inlen <= 0)
{
return YARROW_STATUS_ERROR_NULL;
}
uc error_msg;
//
// Initialize a hash object
//
if ((error_msg = SHA256_startByteWise(&hash)) != SHA256_STATUS_SUCCESS)
{
return error_msg;
}
//
// Hash the initial pool
//
if ((error_msg = SHA256_addDataByteWise(&hash, (uint16_t*)prng->pool, 32U)) != SHA256_STATUS_SUCCESS)
{
return error_msg;
}
//
// Now add the entropy to the pool
//
if ((error_msg = SHA256_addDataByteWise(&hash, (uint16_t*)in, inlen)) != SHA256_STATUS_SUCCESS)
{
return error_msg;
}
//
// Now shift the data from sha256 handle to a temporary digest
//
uint32_t digest[8];
if ((error_msg = SHA256_finalizeByteWise(&hash, digest)) != SHA256_STATUS_SUCCESS)
{
return error_msg;
}
//
// Shift the data from digest to prng->pool
//
uint32_t i, j;
for (i = 0, j = 0; i < 8 && j < 32; i++)
{
prng->pool[j++] = (digest[i] >> 24) & 255;
prng->pool[j++] = (digest[i] >> 16) & 255;
prng->pool[j++] = (digest[i] >> 8) & 255;
prng->pool[j++] = (digest[i]) & 255;
}
return YARROW_STATUS_SUCCESS;
}
//*****************************************************************************
//
// Prepare the yarrow PRNG handle to generate random values
//
//*****************************************************************************
int yarrow_ready(yarrow_prng *prng)
{
if(prng == NULL)
{
return YARROW_STATUS_ERROR_NULL;
}
uint32_t i;
for (i = 0; i < 32; i++)
{
prng->key[i] = prng->pool[i];
}
prng->ready = 1;
return YARROW_STATUS_SUCCESS;
}
//*****************************************************************************
//
// Read random values using yarrow PRNG
//
//*****************************************************************************
int yarrow_read( yarrow_prng *prng, uc *out, uc outlen)
{
//
// Check for invalid input parameters
//
if(prng == NULL || out == NULL || outlen <= 0)
{
return YARROW_STATUS_ERROR_NULL;
}
//
// Check if prng is ready
//
if (prng->ready != 1)
{
return 0;
}
//
// Initialize the out array to 0
//
int i;
for (i = 0; i < outlen; i++)
{
out[i] = 0;
}
//
// Populate the out array with pseudo-random values
//
i = 0;
int len = 0;
int outlenCopy = outlen;
while (outlen > 0)
{
int currlen = (outlen < 32) ? outlen : 32;
AES_performCTR((uint16_t*)prng->pool, 2, (uint16_t*)prng->key,\
AES_256, AES_OPMODE_ENCRYPT,\
(uint16_t*)prng->nounceCounter);
int ptr;
for (ptr = 0; ptr < currlen; ptr++)
{
out[i++] = prng->pool[ptr];
}
outlen -= currlen;
len += currlen;
}
if (outlenCopy == len)
return len;
else
return 0;
}
//
// End of file
//
@@ -0,0 +1,486 @@
//###########################################################################
//
// FILE: sha256.h
//
// TITLE: SHA-256 header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef SHA256_H_
#define SHA256_H_
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup sha256_api SHA256 API
//! @{
//
//*****************************************************************************
#include <stddef.h>
#include <stdint.h>
//*****************************************************************************
//
// SHA-256 object
//
//*****************************************************************************
typedef struct {
uint32_t bitsProcessed; // Only 2^32 bits (512 MiBytes) are supported
int16_t offsetWb; // Byte offset into Ws, used to load message
uint32_t digest[8]; // Holds intermediate/final digest
uint32_t Ws[16];
} SHA256_ObjectWordWise;
typedef struct {
uint32_t bitsProcessed; // Only 2^32 bits (512 MiBytes) are supported
int16_t offsetWb; // Byte offset into Ws, used to load message
uint32_t digest[8]; // Holds intermediate/final digest
uint16_t Ws[64];
} SHA256_ObjectByteWise;
//*****************************************************************************
//
// Handle to the SHA-256 object
//
//*****************************************************************************
typedef SHA256_ObjectWordWise* SHA256_HandleWordWise;
typedef SHA256_ObjectByteWise* SHA256_HandleByteWise;
//*****************************************************************************
//
// Define Macros
//
//*****************************************************************************
/** SHA256- NULL input error */
#define SHA256_STATUS_NULL_INPUT (uint16_t)0x0000
/** SHA256 operation successfull */
#define SHA256_STATUS_SUCCESS (uint16_t)0xABCD
/** SHA256- length of input too large */
#define SHA256_STATUS_LENGTH_TOO_LARGE (uint16_t)0xBADA
/** SHA256- input not aligned */
#define SHA256_STATUS_NOT_ALIGNED (uint16_t)0x0BAD
#define SHA256_GETU32(plaintext) (((uint32_t)(plaintext)[0] << 24U) ^ \
((uint32_t)(plaintext)[1] << 16U) ^ \
((uint32_t)(plaintext)[2] << 8U) ^ \
((uint32_t)(plaintext)[3]))
#define SHA256_PUTU32(ciphertext, st) \
{ (ciphertext)[0] = (uint16_t)((uint16_t)((st) >> 24U) & 0x00FFU); \
(ciphertext)[1] = (uint16_t)((uint16_t)((st) >> 16U) & 0x00FFU); \
(ciphertext)[2] = (uint16_t)((uint16_t)((st) >> 8U) & 0x00FFU); \
(ciphertext)[3] = (uint16_t)((uint16_t)(st) & 0x00FFU); }
#define SHA256_SHR(x, a) ((x) >> (a))
#define SHA256_ROTR32(x, n) (( SHA256_SHR(x, n) ) ^ ( (x) << (32 - (n)) ))
//*****************************************************************************
//
// SHA256_CH function from NIST FIPS 180-4, Eq 4.2.
// Implementation is refactored for efficiency.
//
//*****************************************************************************
#define SHA256_CH(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
//*****************************************************************************
//
// SHA256_MAJ function from NIST FIPS 180-4, Eq 4.3.
// Implementation is refactored for efficiency.
//
//*****************************************************************************
#define SHA256_MAJ(x, y, z) ((((y)^(z)) & (x)) ^ ((y) & (z)))
//*****************************************************************************
//
// Big Sigma 0-512 function from NIST FIPS 180-4, Eq 4.4.
//
//*****************************************************************************
#define SHA256_SIGZ(x) (SHA256_ROTR32(x, 2) ^ SHA256_ROTR32(x, 13) ^ \
SHA256_ROTR32(x, 22))
//*****************************************************************************
//
// Big Sigma 1-512 function from NIST FIPS 180-4, Eq 4.5.
//
//*****************************************************************************
#define SHA256_SIG1(x) (SHA256_ROTR32(x, 6) ^ SHA256_ROTR32(x, 11) ^ \
SHA256_ROTR32(x, 25))
//*****************************************************************************
//
// Little Sigma 0-512 function from NIST FIPS 180-4, Eq 4.6.
//
//*****************************************************************************
#define SHA256_SIGMAZ(x) (SHA256_ROTR32(x, 7) ^ SHA256_ROTR32(x, 18) ^ \
SHA256_SHR(x, 3))
//*****************************************************************************
//
// Little Sigma 1-512 function from NIST FIPS 180-4, Eq 4.7.
//
//*****************************************************************************
#define SHA256_SIGMA1(x) (SHA256_ROTR32(x, 17) ^ SHA256_ROTR32(x, 19) ^ \
SHA256_SHR(x, 10))
//*****************************************************************************
//
//! Perform a complete hash operation when input is supplied as 32-bit words,
//! producing a final digest for the data.
//! - This function wraps #SHA256_startWordWise(), #SHA256_addDataWordWise(),
//! and #SHA256_finalizeWordWise().
//! - There is no need to call #SHA256_startWordWise() prior to calling
//! this function.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.)
//!
//! \param handle A 'SHA256_HandleWordWise' handle
//! \param data 32-bit pointer pointing to the starting memory location of
//! the data to be hashed
//! \param length Length of the data (in number of bytes) to be hashed.
//! Note that for word-wise input, length of the data should be
//! a multiple of 4.
//! \param digest Output location for the final digest
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! #SHA256_STATUS_LENGTH_TOO_LARGE -
//! The requested length of data to
//! hash is more than the
//! implementation supports.
//! #SHA256_STATUS_NULL_INPUT - One or
//! more of the pointer inputs is NULL.
//! #SHA256_STATUS_NOT_ALIGNED - Length.
//! is not a multiple of 4
//
//*****************************************************************************
uint16_t SHA256_hashWordWise(SHA256_HandleWordWise handle, uint32_t *data,
size_t length, uint32_t digest[8]);
//*****************************************************************************
//
//! Perform a complete hash operation when input is supplied as 32-bit words,
//! with High-Low words Swapped,
//! producing a final digest for the data.
//! - This function wraps #SHA256_startWordWise(), #SHA256_addDataWordWiseSwapped(),
//! and #SHA256_finalizeWordWise().
//! - There is no need to call #SHA256_startWordWise() prior to calling
//! this function.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.)
//!
//! \param handle A 'SHA256_HandleWordWise' handle
//! \param data 32-bit pointer pointing to the starting memory location of
//! the data to be hashed
//! \param length Length of the data (in number of bytes) to be hashed.
//! Note that for word-wise input, length of the data should be
//! a multiple of 4.
//! \param digest Output location for the final digest
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! #SHA256_STATUS_LENGTH_TOO_LARGE -
//! The requested length of data to
//! hash is more than the
//! implementation supports.
//! #SHA256_STATUS_NULL_INPUT - One or
//! more of the pointer inputs is NULL.
//! #SHA256_STATUS_NOT_ALIGNED - Length.
//! is not a multiple of 4
//
//*****************************************************************************
uint16_t SHA256_hashWordWiseSwapped(SHA256_HandleWordWise handle, uint32_t *data,
size_t length, uint32_t digest[8]);
//*****************************************************************************
//
//! Perform a complete hash operation when input is supplied byte-wise,
//! producing a final digest for the data.
//! - This function wraps #SHA256_startByteWise(), #SHA256_addDataByteWise(),
//! and #SHA256_finalizeByteWise().
//! - There is no need to call #SHA256_startByteWise() prior to calling
//! this function.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.)
//!
//! \param handle A 'SHA256_HandleByteWise' handle
//! \param data 16-bit pointer pointing to the memory location of the
//! starting byte the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed.
//! \param digest Output location for the final digest
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_LENGTH_TOO_LARGE The requested length of data to
//! hash is more than the
//! implementation supports.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA256_hashByteWise(SHA256_HandleByteWise handle, uint16_t *data,
size_t length, uint32_t digest[8]);
//*****************************************************************************
//
//! Initialize a 'SHA256SW_HandleWordWise' handle, preparing for hashing data.
//!
//! \param handle A 'SHA256_HandleWordWise' handle
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA256_startWordWise(SHA256_HandleWordWise handle);
//*****************************************************************************
//
//! Initialize a 'SHA256SW_HandleByteWise' handle, preparing for hashing data.
//!
//! \param handle A 'SHA256_HandleByteWise' handle
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA256_startByteWise(SHA256_HandleByteWise handle);
//*****************************************************************************
//
//! Add data to SHA256 operation when inputs are supplied as 32-bit words
//! - Adds data to a hash operation. The @c handle must have been
//! initialized by a call to SHA256_startWordWise first.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.).
//! - After passing in all data to be hashed, call #SHA256_finalizeWordWise()
//! to obtain the final digest.
//!
//! \param handle A 'SHA256_HandleWordWise' handle.
//! \param data 32-bit pointer pointing to the starting memory location of
//! the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed
//! Note that for word-wise input, length of the data should
//! be a multiple of 4.
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_LENGTH_TOO_LARGE The requested length of data to
//! hash is more than the
//! implementation supports.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//! \return #SHA256_STATUS_NOT_ALIGNED Length is not a multiple of 4
//
//*****************************************************************************
uint16_t SHA256_addDataWordWise(SHA256_HandleWordWise handle, uint32_t *data,
size_t length);
//*****************************************************************************
//
//! Add data to SHA256 operation when inputs are supplied as 32-bit words
//! - Input words are Swapped High-Low
//! - Adds data to a hash operation. The @c handle must have been
//! initialized by a call to SHA256_startWordWise first.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.).
//! - After passing in all data to be hashed, call #SHA256_finalizeWordWise()
//! to obtain the final digest.
//!
//! \param handle A 'SHA256_HandleWordWise' handle.
//! \param data 32-bit pointer pointing to the starting memory location of
//! the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed
//! Note that for word-wise input, length of the data should
//! be a multiple of 4.
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_LENGTH_TOO_LARGE The requested length of data to
//! hash is more than the
//! implementation supports.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//! \return #SHA256_STATUS_NOT_ALIGNED Length is not a multiple of 4
//
//*****************************************************************************
uint16_t SHA256_addDataWordWiseSwapped(SHA256_HandleWordWise handle, uint32_t *data,
size_t length);
//*****************************************************************************
//
//! Add data to SHA256 operation when inputs are supplied byte-wise
//! - Adds data to a hash operation. The @c handle must have been
//! initialized by a call to SHA256_startByteWise first.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.).
//! - After passing in all data to be hashed, call #SHA256_finalizeWordWise()
//! to obtain the final digest.
//!
//! \param handle A 'SHA256_HandleByteWise' handle.
//! \param data 16-bit pointer pointing to the memory location of the
//! starting byte the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed
//!
//! \return #SHA256_STATUS_SUCCESS hash operation succeeded.
//! #SHA256_STATUS_LENGTH_TOO_LARGE -
//! requested length of data to
//! hash is more than supported length.
//! #SHA256_STATUS_NULL_INPUT- One or
//! more of the pointer inputs is NULL
//
//*****************************************************************************
uint16_t SHA256_addDataByteWise(SHA256_HandleByteWise handle, uint16_t *data,
size_t length);
//*****************************************************************************
//
//! Finalize the SHA256 operation when input is supplied as 32-bit words,
//! creating the final digest.
//! - After calling this function, @c handle should not be used again
//! until it has been reinitialized via a call to #SHA256_startWordWise().
//!
//! \param handle A 'SHA256_HandleWordWise' handle
//! \param digest Output location for the final digest
//! \param digest Output location for the final digest
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA256_finalizeWordWise(SHA256_HandleWordWise handle,
uint32_t digest[8]);
//*****************************************************************************
//
//! Finalize the SHA256 operation when input is supplied byte-wise,
//! creating the final digest.
//! - After calling this function, @c handle should not be used again
//! until it has been reinitialized via a call to #SHA256_startByteWise().
//!
//! \param handle A 'SHA256_HandleByteWise' handle
//! \param digest Output location for the final digest
//!
//! \return #SHA256_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA256_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA256_finalizeByteWise(SHA256_HandleByteWise handle,
uint32_t digest[8]);
//*****************************************************************************
//
//! Cancels SHA256 operation by clearing intermediate
//! data stored in the 'SHA256_HandleWordWise' handle.
//! - The handle will not be ready for a new operation until after
//! #SHA256_startWordWise() is called on the handle.
//!
//! \param handle A 'SHA256_HandleWordWise' handle
//!
//
//*****************************************************************************
void SHA256_cancelWordWise(SHA256_HandleWordWise handle);
//*****************************************************************************
//
//! Cancels SHA256 operation by clearing intermediate
//! data stored in the 'SHA256_HandleByteWise' handle.
//! - The handle will not be ready for a new operation until after
//! #SHA256_startByteWise() is called on the handle.
//!
//! \param handle A 'SHA256_HandleByteWise' handle
//!
//
//*****************************************************************************
void SHA256_cancelByteWise(SHA256_HandleByteWise handle);
//*****************************************************************************
//
//! Performs core SHA2-256 algorithm on one 512 bit block of data when input
//! is supplied as 32-bit words.
//! - object->digest will contain the updated digest resulting from
//! hashing the block.
//!
//! \param digest pre-loaded with previous block's digest (or initial
//! digest if call is to process first block)
//! On function return digest will hold the updated digest.
//! \param Ws loaded with data block, including padding as specified by
//! the SHA256 standard.
//
//*****************************************************************************
void SHA256_processBlockWordWise(uint32_t digest[8], uint32_t Ws[16]);
extern void _SHA256_processBlockWordWise_casm_C28(uint32_t digest[8], uint32_t Ws[16]);
//*****************************************************************************
//
//! Performs core SHA2-256 algorithm on one 512 bit block of data when input
//! is supplied byte-wise.
//! - object->digest will contain the updated digest resulting from
//! hashing the block.
//!
//! \param digest pre-loaded with previous block's digest (or initial
//! digest if call is to process first block)
//! On function return digest will hold the updated digest.
//! \param Ws loaded with data block, including padding as specified by
//! the SHA256 standard.
//
//*****************************************************************************
void SHA256_processBlockByteWise(uint32_t digest[8], uint16_t Ws[64]);
extern void _SHA256_processBlockByteWise_casm_C28(uint32_t digest[8], uint16_t Ws[64]);
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* SHA256_H_ */
@@ -0,0 +1,439 @@
//###########################################################################
//
// FILE: sha384.h
//
// TITLE: SHA-384 header file
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#ifndef SHA384_H_
#define SHA384_H_
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
//! \addtogroup sha384_api SHA384 API
//! @{
//
//*****************************************************************************
#include <stddef.h>
#include <stdint.h>
//*****************************************************************************
//
// SHA-384 object
//
//*****************************************************************************
typedef struct {
uint32_t bitsProcessed; // Only 2^32 bits (512 MiBytes) are supported
int16_t offsetWb; // Byte offset into Ws, used to load message
uint64_t digest[8]; // Holds intermediate/final digest
uint32_t Ws[32];
} SHA384_ObjectWordWise;
typedef struct {
uint32_t bitsProcessed; // Only 2^32 bits (512 MiBytes) are supported
int16_t offsetWb; // Byte offset into Ws, used to load message
uint64_t digest[8]; // Holds intermediate/final digest
uint16_t Ws[128];
} SHA384_ObjectByteWise;
//*****************************************************************************
//
// Handle to the SHA-384 object
//
//*****************************************************************************
typedef SHA384_ObjectWordWise* SHA384_HandleWordWise;
typedef SHA384_ObjectByteWise* SHA384_HandleByteWise;
//*****************************************************************************
//
// Define Macros
//
//*****************************************************************************
/** SHA384- NULL input error */
#define SHA384_STATUS_NULL_INPUT (uint16_t)0x0000
/** SHA384 operation successful */
#define SHA384_STATUS_SUCCESS (uint16_t)0xABCD
/** SHA384- length of input too large */
#define SHA384_STATUS_LENGTH_TOO_LARGE (uint16_t)0xBADA
/** SHA384- input not aligned */
#define SHA384_STATUS_NOT_ALIGNED (uint16_t)0x0BAD
#define SHA384_GETU32(plaintext) (((uint32_t)(plaintext)[0] << 24U) ^ \
((uint32_t)(plaintext)[1] << 16U) ^ \
((uint32_t)(plaintext)[2] << 8U) ^ \
((uint32_t)(plaintext)[3]))
#define SHA384_GETU64(plaintext) (((uint64_t)(plaintext)[0] << 56U) ^ \
((uint64_t)(plaintext)[1] << 48U) ^ \
((uint64_t)(plaintext)[2] << 40U) ^ \
((uint64_t)(plaintext)[3] << 32U) ^ \
((uint64_t)(plaintext)[4] << 24U) ^ \
((uint64_t)(plaintext)[5] << 16U) ^ \
((uint64_t)(plaintext)[6] << 8U) ^ \
((uint64_t)(plaintext)[7]))
#define SHA384_PUTU64(ciphertext, st) \
{ (ciphertext)[0] = (uint16_t)((uint16_t)((st) >> 56U) & 0x00FFU); \
(ciphertext)[1] = (uint16_t)((uint16_t)((st) >> 48U) & 0x00FFU); \
(ciphertext)[2] = (uint16_t)((uint16_t)((st) >> 40U) & 0x00FFU); \
(ciphertext)[3] = (uint16_t)((uint16_t)((st) >> 32U) & 0x00FFU); \
(ciphertext)[4] = (uint16_t)((uint16_t)((st) >> 24U) & 0x00FFU); \
(ciphertext)[5] = (uint16_t)((uint16_t)((st) >> 16U) & 0x00FFU); \
(ciphertext)[6] = (uint16_t)((uint16_t)((st) >> 8U) & 0x00FFU); \
(ciphertext)[7] = (uint16_t)((uint16_t)(st) & 0x00FFU); }
#define SHA384_PUTU32(ciphertext, st) \
{ (ciphertext)[0] = (uint16_t)((uint16_t)((st) >> 24U) & 0x00FFU); \
(ciphertext)[1] = (uint16_t)((uint16_t)((st) >> 16U) & 0x00FFU); \
(ciphertext)[2] = (uint16_t)((uint16_t)((st) >> 8U) & 0x00FFU); \
(ciphertext)[3] = (uint16_t)((uint16_t)(st) & 0x00FFU); }
#define SHA384_SHR(x, a) ((x) >> (a))
#define SHA384_ROTR32(x, n) (( SHA384_SHR(x, n) ) ^ ( (x) << (32 - (n)) ))
#define SHA384_ROTR64(x, n) (( SHA384_SHR(x, n) ) ^ ( (x) << (64 - (n)) ))
//*****************************************************************************
//
// SHA384_CH function from NIST FIPS 180-4, Eq 4.8.
// Implementation is refactored for efficiency.
//
//*****************************************************************************
#define SHA384_CH(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
//*****************************************************************************
//
// SHA384_MAJ function from NIST FIPS 180-4, Eq 4.9.
// Implementation is refactored for efficiency.
//
//*****************************************************************************
#define SHA384_MAJ(x, y, z) ((((y)^(z)) & (x)) ^ ((y) & (z)))
//*****************************************************************************
//
// Big Sigma 0-512 function from NIST FIPS 180-4, Eq 4.10.
//
//*****************************************************************************
#define SHA384_SIGZ(x) (SHA384_ROTR64(x, 28) ^ SHA384_ROTR64(x, 34) ^ \
SHA384_ROTR64(x, 39))
//*****************************************************************************
//
// Big Sigma 1-512 function from NIST FIPS 180-4, Eq 4.11.
//
//*****************************************************************************
#define SHA384_SIG1(x) (SHA384_ROTR64(x, 14) ^ SHA384_ROTR64(x, 18) ^ \
SHA384_ROTR64(x, 41))
//*****************************************************************************
//
// Little Sigma 0-512 function from NIST FIPS 180-4, Eq 4.12.
//
//*****************************************************************************
#define SHA384_SIGMAZ(x) (SHA384_ROTR64(x, 1) ^ SHA384_ROTR64(x, 8) ^ \
SHA384_SHR(x, 7))
//*****************************************************************************
//
// Little Sigma 1-512 function from NIST FIPS 180-4, Eq 4.13.
//
//*****************************************************************************
#define SHA384_SIGMA1(x) (SHA384_ROTR64(x, 19) ^ SHA384_ROTR64(x, 61) ^ \
SHA384_SHR(x, 6))
//*****************************************************************************
//
//! Perform a complete hash operation when input is supplied as 32-bit words,
//! producing a final digest for the data.
//! - This function wraps #SHA384_startWordWise(), #SHA384_addDataWordWise(),
//! and #SHA384_finalizeWordWise().
//! - There is no need to call #SHA384_startWordWise() prior to calling
//! this function.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.)
//!
//! \param handle A 'SHA384_HandleWordWise' handle
//! \param data 32-bit pointer pointing to the starting memory location of
//! the data to be hashed
//! \param length Length of the data (in number of bytes) to be hashed.
//! Note that for word-wise input, length of the data should be
//! a multiple of 4.
//! \param digest Output location for the final digest
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! #SHA384_STATUS_LENGTH_TOO_LARGE -
//! The requested length of data to
//! hash is more than the
//! implementation supports.
//! #SHA384_STATUS_NULL_INPUT - One or
//! more of the pointer inputs is NULL.
//! #SHA384_STATUS_NOT_ALIGNED - Length.
//! is not a multiple of 4
//
//*****************************************************************************
uint16_t SHA384_hashWordWise(SHA384_HandleWordWise handle, uint32_t *data,
size_t length, uint64_t digest[6]);
//*****************************************************************************
//
//! Perform a complete hash operation when input is supplied byte-wise,
//! producing a final digest for the data.
//! - This function wraps #SHA384_startByteWise(), #SHA384_addDataByteWise(),
//! and #SHA384_finalizeByteWise().
//! - There is no need to call #SHA384_startByteWise() prior to calling
//! this function.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.)
//!
//! \param handle A 'SHA384_HandleByteWise' handle
//! \param data 16-bit pointer pointing to the memory location of the
//! starting byte the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed.
//! \param digest Output location for the final digest
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA384_STATUS_LENGTH_TOO_LARGE The requested length of data to
//! hash is more than the
//! implementation supports.
//! \return #SHA384_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA384_hashByteWise(SHA384_HandleByteWise handle, uint16_t *data,
size_t length, uint64_t digest[6]);
//*****************************************************************************
//
//! Initialize a 'SHA384SW_HandleWordWise' handle, preparing for hashing data.
//!
//! \param handle A 'SHA384_HandleWordWise' handle
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA384_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA384_startWordWise(SHA384_HandleWordWise handle);
//*****************************************************************************
//
//! Initialize a 'SHA384SW_HandleByteWise' handle, preparing for hashing data.
//!
//! \param handle A 'SHA384_HandleByteWise' handle
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA384_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA384_startByteWise(SHA384_HandleByteWise handle);
//*****************************************************************************
//
//! Add data to SHA384 operation when inputs are supplied as 32-bit words
//! - Adds data to a hash operation. The @c handle must have been
//! initialized by a call to SHA384_startWordWise first.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.).
//! - After passing in all data to be hashed, call #SHA384_finalizeWordWise()
//! to obtain the final digest.
//!
//! \param handle A 'SHA384_HandleWordWise' handle.
//! \param data 32-bit pointer pointing to the starting memory location of
//! the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed
//! Note that for word-wise input, length of the data should
//! be a multiple of 4.
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA384_STATUS_LENGTH_TOO_LARGE The requested length of data to
//! hash is more than the
//! implementation supports.
//! \return #SHA384_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//! \return #SHA384_STATUS_NOT_ALIGNED Length is not a multiple of 4
//
//*****************************************************************************
uint16_t SHA384_addDataWordWise(SHA384_HandleWordWise handle, uint32_t *data,
size_t length);
//*****************************************************************************
//
//! Add data to SHA384 operation when inputs are supplied byte-wise
//! - Adds data to a hash operation. The @c handle must have been
//! initialized by a call to SHA384_startByteWise first.
//! - The total length of data that can be hashed by this implementation
//! is 512MiB (0x20000000 bytes.).
//! - After passing in all data to be hashed, call #SHA384_finalizeWordWise()
//! to obtain the final digest.
//!
//! \param handle A 'SHA384_HandleByteWise' handle.
//! \param data 16-bit pointer pointing to the memory location of the
//! starting byte the data to be hashed.
//! \param length Length of the data (in number of bytes) to be hashed
//!
//! \return #SHA384_STATUS_SUCCESS hash operation succeeded.
//! #SHA384_STATUS_LENGTH_TOO_LARGE -
//! requested length of data to
//! hash is more than supported length.
//! #SHA384_STATUS_NULL_INPUT- One or
//! more of the pointer inputs is NULL
//
//*****************************************************************************
uint16_t SHA384_addDataByteWise(SHA384_HandleByteWise handle, uint16_t *data,
size_t length);
//*****************************************************************************
//
//! Finalize the SHA384 operation when input is supplied as 32-bit words,
//! creating the final digest.
//! - After calling this function, @c handle should not be used again
//! until it has been reinitialized via a call to #SHA384_startWordWise().
//!
//! \param handle A 'SHA384_HandleWordWise' handle
//! \param digest Output location for the final digest
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA384_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA384_finalizeWordWise(SHA384_HandleWordWise handle,
uint64_t digest[6]);
//*****************************************************************************
//
//! Finalize the SHA384 operation when input is supplied byte-wise,
//! creating the final digest.
//! - After calling this function, @c handle should not be used again
//! until it has been reinitialized via a call to #SHA384_startByteWise().
//!
//! \param handle A 'SHA384_HandleByteWise' handle
//! \param digest Output location for the final digest
//!
//! \return #SHA384_STATUS_SUCCESS The hash operation succeeded.
//! \return #SHA384_STATUS_NULL_INPUT One or more of the pointer inputs
//! is NULL.
//
//*****************************************************************************
uint16_t SHA384_finalizeByteWise(SHA384_HandleByteWise handle,
uint64_t digest[6]);
//*****************************************************************************
//
//! Cancels SHA384 operation by clearing intermediate
//! data stored in the 'SHA384_HandleWordWise' handle.
//! - The handle will not be ready for a new operation until after
//! #SHA384_startWordWise() is called on the handle.
//!
//! \param handle A 'SHA384_HandleWordWise' handle
//!
//
//*****************************************************************************
void SHA384_cancelWordWise(SHA384_HandleWordWise handle);
//*****************************************************************************
//
//! Cancels SHA384 operation by clearing intermediate
//! data stored in the 'SHA384_HandleByteWise' handle.
//! - The handle will not be ready for a new operation until after
//! #SHA384_startByteWise() is called on the handle.
//!
//! \param handle A 'SHA384_HandleByteWise' handle
//!
//
//*****************************************************************************
void SHA384_cancelByteWise(SHA384_HandleByteWise handle);
//*****************************************************************************
//
//! Performs core SHA2-384 algorithm on one 1024 bit block of data when input
//! is supplied as 32-bit words.
//! - object->digest will contain the updated digest resulting from
//! hashing the block.
//!
//! \param digest pre-loaded with previous block's digest (or initial
//! digest if call is to process first block)
//! On function return digest will hold the updated digest.
//! \param Ws loaded with data block, including padding as specified by
//! the SHA384 standard.
//
//*****************************************************************************
void SHA384_processBlockWordWise(uint64_t digest[8], uint64_t Ws[16]);
extern void _SHA384_processBlockWordWise_casm_C28(uint64_t digest[8], uint64_t Ws[16]);
//*****************************************************************************
//
//! Performs core SHA2-384 algorithm on one 1024 bit block of data when input
//! is supplied byte-wise.
//! - object->digest will contain the updated digest resulting from
//! hashing the block.
//!
//! \param digest pre-loaded with previous block's digest (or initial
//! digest if call is to process first block)
//! On function return digest will hold the updated digest.
//! \param Ws loaded with data block, including padding as specified by
//! the SHA384 standard.
//
//*****************************************************************************
void SHA384_processBlockByteWise(uint64_t digest[8], uint16_t Ws[128]);
extern void _SHA384_processBlockByteWise_casm_C28(uint64_t digest[8], uint16_t Ws[128]);
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* SHA384_H_ */
@@ -0,0 +1,822 @@
//###########################################################################
//
// FILE: sha256.c
//
// TITLE: Implementation of the SHA-256 algorithm
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include <sha256.h>
// Uncomment line when copying constants from FLASH to RAM
#pragma DATA_SECTION(SHA256_K, ".TI.ramfunc"); // map the TX data to memory
//*****************************************************************************
//
// SHA-256 round constants
//
//*****************************************************************************
const uint32_t SHA256_K[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
//*****************************************************************************
//
// SHA-256 single call hash function
// Input message : Word-wise
//
//*****************************************************************************
uint16_t SHA256_hashWordWise(SHA256_HandleWordWise handle, uint32_t *data,
size_t length, uint32_t digest[8])
{
uint16_t result;
//
// Initialize the SHA256 handle
//
result = SHA256_startWordWise(handle);
//
// Add data block by block
//
if(result == SHA256_STATUS_SUCCESS) {
result = SHA256_addDataWordWise(handle, data, length);
}
//
// Finalize SHA-256 hashing
//
if(result == SHA256_STATUS_SUCCESS) {
result = SHA256_finalizeWordWise(handle, digest);
}
return(result);
}
//*****************************************************************************
//
// SHA-256 single call hash function
// Input message : Word-wise, High-Low words Swapped
//
//*****************************************************************************
uint16_t SHA256_hashWordWiseSwapped(SHA256_HandleWordWise handle, uint32_t *data,
size_t length, uint32_t digest[8])
{
uint16_t result;
//
// Initialize the SHA256 handle
//
result = SHA256_startWordWise(handle);
//
// Add data block by block
//
if(result == SHA256_STATUS_SUCCESS) {
result = SHA256_addDataWordWiseSwapped(handle, data, length);
}
//
// Finalize SHA-256 hashing
//
if(result == SHA256_STATUS_SUCCESS) {
result = SHA256_finalizeWordWise(handle, digest);
}
return(result);
}
//*****************************************************************************
//
// SHA-256 single call hash function
// Input message : Byte-wise
//
//*****************************************************************************
uint16_t SHA256_hashByteWise(SHA256_HandleByteWise handle, uint16_t *data,
size_t length, uint32_t digest[8])
{
uint16_t result;
//
// Initialize the SHA256 handle
//
result = SHA256_startByteWise(handle);
//
// Add data block by block
//
if(result == SHA256_STATUS_SUCCESS) {
result = SHA256_addDataByteWise(handle, data, length);
}
//
// Finalize SHA-256 hashing
//
if(result == SHA256_STATUS_SUCCESS) {
result = SHA256_finalizeByteWise(handle, digest);
}
return(result);
}
//*****************************************************************************
//
// SHA-256 start function
// Input type : Word-wise
//
//*****************************************************************************
uint16_t SHA256_startWordWise(SHA256_HandleWordWise handle)
{
uint16_t result = SHA256_STATUS_SUCCESS;
if(handle == NULL)
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
//
// Initialize handle with starting values
//
handle->bitsProcessed = 0;
handle->offsetWb = 0;
handle->digest[0] = 0x6A09E667;
handle->digest[1] = 0xBB67AE85;
handle->digest[2] = 0x3C6EF372;
handle->digest[3] = 0xA54FF53A;
handle->digest[4] = 0x510E527F;
handle->digest[5] = 0x9B05688C;
handle->digest[6] = 0x1F83D9AB;
handle->digest[7] = 0x5BE0CD19;
return(result);
}
//*****************************************************************************
//
// SHA-256 start function
// Input type : Byte-wise
//
//*****************************************************************************
uint16_t SHA256_startByteWise(SHA256_HandleByteWise handle)
{
uint16_t result = SHA256_STATUS_SUCCESS;
if(handle == NULL)
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
//
// Initialize handle with starting values
//
handle->bitsProcessed = 0;
handle->offsetWb = 0;
handle->digest[0] = 0x6A09E667;
handle->digest[1] = 0xBB67AE85;
handle->digest[2] = 0x3C6EF372;
handle->digest[3] = 0xA54FF53A;
handle->digest[4] = 0x510E527F;
handle->digest[5] = 0x9B05688C;
handle->digest[6] = 0x1F83D9AB;
handle->digest[7] = 0x5BE0CD19;
return(result);
}
//*****************************************************************************
//
// SHA-256 add data block function
// Input data : Word-wise
//
//*****************************************************************************
uint16_t SHA256_addDataWordWise(SHA256_HandleWordWise handle, uint32_t *data,
size_t length)
{
int16_t i;
size_t dataOffset;
uint16_t result = SHA256_STATUS_SUCCESS;
if((handle == NULL) || (data == NULL))
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
if(length >= 0x20000000U)
{
result = SHA256_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if(((length << 3u) + handle->bitsProcessed) < handle->bitsProcessed)
{
result = SHA256_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if((length & 0x3U) != 0)
{
result = SHA256_STATUS_NOT_ALIGNED;
return(result);
}
dataOffset = 0;
length = length >> 2;
while(dataOffset < length)
{
i = (int16_t) handle->offsetWb;
//
// Load data block into the handle
//
while((i < 16) && (dataOffset < length))
{
handle->Ws[i] = data[dataOffset];
i++;
dataOffset++;
}
handle->offsetWb = (int16_t) i;
//
// After loading a block completely, process it
//
if(handle->offsetWb >= 16)
{
_SHA256_processBlockWordWise_casm_C28(handle->digest, handle->Ws);
handle->offsetWb = 0;
}
}
handle->bitsProcessed += length << 5;
return(result);
}
//*****************************************************************************
//
// SHA-256 add data block function
// Input data : Word-wise , High-Low words Swapped
//
//*****************************************************************************
uint16_t SHA256_addDataWordWiseSwapped(SHA256_HandleWordWise handle, uint32_t *data,
size_t length)
{
int16_t i;
size_t dataOffset;
uint16_t result = SHA256_STATUS_SUCCESS;
if((handle == NULL) || (data == NULL))
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
if(length >= 0x20000000U)
{
result = SHA256_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if(((length << 3u) + handle->bitsProcessed) < handle->bitsProcessed)
{
result = SHA256_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if((length & 0x3U) != 0)
{
result = SHA256_STATUS_NOT_ALIGNED;
return(result);
}
dataOffset = 0;
length = length >> 2;
while(dataOffset < length)
{
i = (int16_t) handle->offsetWb;
//
// Load data block into the handle
//
while((i < 16) && (dataOffset < length))
{
//
// Flip High-Low words
//
uint32_t low_word_32 = (data[dataOffset] & 0xFFFF0000) >> 16;
uint32_t high_word_32 = (data[dataOffset] & 0x0000FFFF) << 16;
handle->Ws[i] = high_word_32 | low_word_32;
i++;
dataOffset++;
}
handle->offsetWb = (int16_t) i;
//
// After loading a block completely, process it
//
if(handle->offsetWb >= 16)
{
_SHA256_processBlockWordWise_casm_C28(handle->digest, handle->Ws);
handle->offsetWb = 0;
}
}
handle->bitsProcessed += length << 5;
return(result);
}
//*****************************************************************************
//
// SHA-256 add data block function
// Input data : Byte-wise
//
//*****************************************************************************
uint16_t SHA256_addDataByteWise(SHA256_HandleByteWise handle, uint16_t *data,
size_t length)
{
int16_t i;
size_t dataOffset;
uint16_t result = SHA256_STATUS_SUCCESS;
if((handle == NULL) || (data == NULL))
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
if(length >= 0x20000000U)
{
result = SHA256_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if(((length << 3u) + handle->bitsProcessed) < handle->bitsProcessed)
{
result = SHA256_STATUS_LENGTH_TOO_LARGE;
return(result);
}
dataOffset = 0;
while(dataOffset < length)
{
i = (int16_t) handle->offsetWb;
//
// Load data block into the handle
//
while((i < 64) && (dataOffset < length))
{
handle->Ws[i] = data[dataOffset];
i++;
dataOffset++;
}
handle->offsetWb = (int16_t) i;
//
// After loading a block completely, process it
//
if(handle->offsetWb >= 64)
{
_SHA256_processBlockByteWise_casm_C28(handle->digest, handle->Ws);
handle->offsetWb = 0;
}
}
handle->bitsProcessed += length << 3;
return(result);
}
//*****************************************************************************
//
// SHA-256 finalize hash function
// Input message : Word-wise
//
//*****************************************************************************
uint16_t SHA256_finalizeWordWise(SHA256_HandleWordWise handle,
uint32_t digest[8])
{
int16_t i;
uint16_t paddedBlocks;
uint16_t result = SHA256_STATUS_SUCCESS;
if((handle == NULL) || (digest == NULL))
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
i = handle->offsetWb;
//
// '1' pad bit
//
handle->Ws[i] = 0x80000000;
i++;
//
// If fewer than 8 bytes (64 bits) remain in current
// block, must pad out the current block and then pad out
// another block. (Need space to store 64 bit value
// of bits processed in the end of the last block.)
//
if(handle->offsetWb >= 14)
{
paddedBlocks = 2;
}
else
{
paddedBlocks = 1;
}
//
// Perform padding
//
do
{
//
// Finish out block with 0 pad.
//
while(i < 15)
{
handle->Ws[i] = 0;
i++;
}
//
// Write bitsProcessed into last block of padding.
// Note: implementation only supports 2^32 bits of input.
//
if(paddedBlocks == 1)
{
handle->Ws[i] = handle->bitsProcessed;
}
else
{
handle->Ws[i] = 0;
}
//
// Process the final block
//
_SHA256_processBlockWordWise_casm_C28(handle->digest, handle->Ws);
i = 0;
} while(--paddedBlocks > 0);
//
// Copy out final digest
//
digest[0] = handle->digest[0];
digest[1] = handle->digest[1];
digest[2] = handle->digest[2];
digest[3] = handle->digest[3];
digest[4] = handle->digest[4];
digest[5] = handle->digest[5];
digest[6] = handle->digest[6];
digest[7] = handle->digest[7];
//
// For security - clear data held by handle
//
SHA256_cancelWordWise(handle);
return(result);
}
//*****************************************************************************
//
// SHA-256 finalize hash function
//
//*****************************************************************************
uint16_t SHA256_finalizeByteWise(SHA256_HandleByteWise handle,
uint32_t digest[8])
{
int16_t i;
uint16_t paddedBlocks;
uint16_t result = SHA256_STATUS_SUCCESS;
if((handle == NULL) || (digest == NULL))
{
result = SHA256_STATUS_NULL_INPUT;
return(result);
}
i = handle->offsetWb;
//
// '1' pad bit
//
handle->Ws[i] = 0x80;
i++;
//
// If fewer than 8 bytes (64 bits) remain in current
// block, must pad out the current block and then pad out
// another block. (Need space to store 64 bit value
// of bits processed in the end of the last block.)
//
if(handle->offsetWb >= 56)
{
paddedBlocks = 2;
}
else
{
paddedBlocks = 1;
}
//
// Perform padding
//
do
{
//
// Finish out block with 0 pad.
//
while(i < 64)
{
handle->Ws[i] = 0;
i++;
}
//
// Write bitsProcessed into last block of padding.
// Note: implementation only supports 2^32 bits of input.
//
if(paddedBlocks == 1)
{
SHA256_PUTU32(&handle->Ws[60], handle->bitsProcessed)
}
//
// Process the final block
//
_SHA256_processBlockByteWise_casm_C28(handle->digest, handle->Ws);
i = 0;
} while(--paddedBlocks > 0);
//
// Copy out final digest
//
digest[0] = handle->digest[0];
digest[1] = handle->digest[1];
digest[2] = handle->digest[2];
digest[3] = handle->digest[3];
digest[4] = handle->digest[4];
digest[5] = handle->digest[5];
digest[6] = handle->digest[6];
digest[7] = handle->digest[7];
//
// For security - clear data held by handle
//
SHA256_cancelByteWise(handle);
return(result);
}
//*****************************************************************************
//
// SHA-256 clear handle
// Input message : Word-wise
//
//*****************************************************************************
void SHA256_cancelWordWise(SHA256_HandleWordWise handle)
{
int16_t i, j;
uint16_t * objAsBytes;
j = sizeof(SHA256_ObjectWordWise);
if(handle != NULL)
{
objAsBytes = (uint16_t *) handle;
for (i = 0; i < j; i++)
{
objAsBytes[i] = 0x0;
}
}
return;
}
//*****************************************************************************
//
// SHA-256 clear handle
// Input message : Byte-wise
//
//*****************************************************************************
void SHA256_cancelByteWise(SHA256_HandleByteWise handle)
{
int16_t i, j;
uint16_t * objAsBytes;
j = sizeof(SHA256_ObjectByteWise);
if(handle != NULL)
{
objAsBytes = (uint16_t *) handle;
for (i = 0; i < j; i++)
{
objAsBytes[i] = 0x0;
}
}
return;
}
//*****************************************************************************
//
// SHA-256 process a block of data
// Input message : Word-wise
//
//*****************************************************************************
void SHA256_processBlockWordWise(uint32_t digest[8], uint32_t Ws[64])
{
uint32_t wt; // Wt from standard
int16_t s; // s is the message schedule index
uint32_t temp1; // T1 from standard
uint32_t temp2; // T2 from standard
//
// Initialize working variables
//
uint32_t a = digest[0];
uint32_t b = digest[1];
uint32_t c = digest[2];
uint32_t d = digest[3];
uint32_t e = digest[4];
uint32_t f = digest[5];
uint32_t g = digest[6];
uint32_t h = digest[7];
//
// Perform 64 rounds of compression function
//
for(s = 0; s < 64; s++)
{
if(s >= 16)
{
Ws[s & 0xF] += SHA256_SIGMA1(Ws[(s + 14) & 0xF]) +
Ws[(s + 9) & 0xF] +
SHA256_SIGMAZ(Ws[(s + 1) & 0xF]);
}
wt = Ws[s & 0xF];
temp1 = h + SHA256_SIG1(e) + SHA256_CH(e, f, g) + SHA256_K[s] + wt;
temp2 = SHA256_SIGZ(a) + SHA256_MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d + temp1;
d = c;
c = b;
b = a;
a = temp1 + temp2;
}
//
// Intermediate digest value
//
digest[0] += a;
digest[1] += b;
digest[2] += c;
digest[3] += d;
digest[4] += e;
digest[5] += f;
digest[6] += g;
digest[7] += h;
}
//*****************************************************************************
//
// SHA-256 process a block of data
// Input message : Byte-wise
//
//*****************************************************************************
void SHA256_processBlockByteWise(uint32_t digest[8], uint16_t Ws[64])
{
uint32_t wt; // Wt from standard
int16_t s, s0; // s is the message schedule index
uint32_t temp1; // T1 from standard
uint32_t temp2; // T2 from standard
//
// Initialize working variables
//
uint32_t a = digest[0];
uint32_t b = digest[1];
uint32_t c = digest[2];
uint32_t d = digest[3];
uint32_t e = digest[4];
uint32_t f = digest[5];
uint32_t g = digest[6];
uint32_t h = digest[7];
//
// Perform 64 rounds of compression function
//
for(s = 0; s < 64; s++)
{
s0 = s << 2;
if(s0 >= 64)
{
wt = SHA256_SIGMA1(SHA256_GETU32(&Ws[(s0-8) & 0x3F])) +
SHA256_GETU32(&Ws[(s0-28) & 0x3F]) +
SHA256_SIGMAZ(SHA256_GETU32(&Ws[(s0-60) & 0x3F])) +
SHA256_GETU32(&Ws[(s0-64) & 0x3F]);
SHA256_PUTU32(&Ws[s0 & 0x3F], wt);
}
else
{
wt = SHA256_GETU32(&Ws[s0]);
}
temp1 = h + SHA256_SIG1(e) + SHA256_CH(e, f, g) + SHA256_K[s] + wt;
temp2 = SHA256_SIGZ(a) + SHA256_MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d + temp1;
d = c;
c = b;
b = a;
a = temp1 + temp2;
}
//
// Intermediate digest value
//
digest[0] += a;
digest[1] += b;
digest[2] += c;
digest[3] += d;
digest[4] += e;
digest[5] += f;
digest[6] += g;
digest[7] += h;
}
//
// End of file
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,729 @@
//###########################################################################
//
// FILE: sha384.c
//
// TITLE: Implementation of the SHA-384 algorithm
//
//###########################################################################
// $Copyright:
// Copyright (C) 2024 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################
#include <sha384.h>
// Uncomment line when copying constants from FLASH to RAM
#pragma DATA_SECTION(SHA384_K, ".TI.ramfunc"); // map the TX data to memory
//*****************************************************************************
//
// SHA-384 round constants
//
//*****************************************************************************
const uint64_t SHA384_K[80] = { 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc,
0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118,
0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,
0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694,
0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65,
0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5,
0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4,
0xc6e00bf33da88fc2, 0xd5a79147930aa725, 0x06ca6351e003826f, 0x142929670a0e6e70,
0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df,
0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b,
0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30,
0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8,
0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8,
0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3,
0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec,
0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b,
0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178,
0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b,
0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c,
0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817};
//*****************************************************************************
//
// SHA-384 single call hash function
// Input message : Word-wise
//
//*****************************************************************************
uint16_t SHA384_hashWordWise(SHA384_HandleWordWise handle, uint32_t *data,
size_t length, uint64_t digest[6])
{
uint16_t result;
//
// Initialize the SHA384 handle
//
result = SHA384_startWordWise(handle);
//
// Add data block by block
//
if(result == SHA384_STATUS_SUCCESS) {
result = SHA384_addDataWordWise(handle, data, length);
}
//
// Finalize SHA-384 hashing
//
if(result == SHA384_STATUS_SUCCESS) {
result = SHA384_finalizeWordWise(handle, digest);
}
return(result);
}
//*****************************************************************************
//
// SHA-384 single call hash function
// Input message : Byte-wise
//
//*****************************************************************************
uint16_t SHA384_hashByteWise(SHA384_HandleByteWise handle, uint16_t *data,
size_t length, uint64_t digest[6])
{
uint16_t result;
//
// Initialize the SHA256 handle
//
result = SHA384_startByteWise(handle);
//
// Add data block by block
//
if(result == SHA384_STATUS_SUCCESS) {
result = SHA384_addDataByteWise(handle, data, length);
}
//
// Finalize SHA-384 hashing
//
if(result == SHA384_STATUS_SUCCESS) {
result = SHA384_finalizeByteWise(handle, digest);
}
return(result);
}
//*****************************************************************************
//
// SHA-384 start function
// Input type : Word-wise
//
//*****************************************************************************
uint16_t SHA384_startWordWise(SHA384_HandleWordWise handle)
{
uint16_t result = SHA384_STATUS_SUCCESS;
if(handle == NULL)
{
result = SHA384_STATUS_NULL_INPUT;
return(result);
}
//
// Initialize handle with starting values
//
handle->bitsProcessed = 0;
handle->offsetWb = 0;
handle->digest[0] = 0xcbbb9d5dc1059ed8;
handle->digest[1] = 0x629a292a367cd507;
handle->digest[2] = 0x9159015a3070dd17;
handle->digest[3] = 0x152fecd8f70e5939;
handle->digest[4] = 0x67332667ffc00b31;
handle->digest[5] = 0x8eb44a8768581511;
handle->digest[6] = 0xdb0c2e0d64f98fa7;
handle->digest[7] = 0x47b5481dbefa4fa4;
return(result);
}
//*****************************************************************************
//
// SHA-384 start function
// Input type : Byte-wise
//
//*****************************************************************************
uint16_t SHA384_startByteWise(SHA384_HandleByteWise handle)
{
uint16_t result = SHA384_STATUS_SUCCESS;
if(handle == NULL)
{
result = SHA384_STATUS_NULL_INPUT;
return(result);
}
//
// Initialize handle with starting values
//
handle->bitsProcessed = 0;
handle->offsetWb = 0;
handle->digest[0] = 0xcbbb9d5dc1059ed8;
handle->digest[1] = 0x629a292a367cd507;
handle->digest[2] = 0x9159015a3070dd17;
handle->digest[3] = 0x152fecd8f70e5939;
handle->digest[4] = 0x67332667ffc00b31;
handle->digest[5] = 0x8eb44a8768581511;
handle->digest[6] = 0xdb0c2e0d64f98fa7;
handle->digest[7] = 0x47b5481dbefa4fa4;
return(result);
}
//*****************************************************************************
//
// SHA-384 add data block function
// Input data : Word-wise
//
//*****************************************************************************
uint16_t SHA384_addDataWordWise(SHA384_HandleWordWise handle, uint32_t *data,
size_t length)
{
int16_t i;
size_t dataOffset;
uint16_t result = SHA384_STATUS_SUCCESS;
if((handle == NULL) || (data == NULL))
{
result = SHA384_STATUS_NULL_INPUT;
return(result);
}
if(length >= 0x20000000U)
{
result = SHA384_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if(((length << 3u) + handle->bitsProcessed) < handle->bitsProcessed)
{
result = SHA384_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if((length & 0x3U) != 0)
{
result = SHA384_STATUS_NOT_ALIGNED;
return(result);
}
dataOffset = 0;
length = length >> 2;
while(dataOffset < length)
{
i = (int16_t) handle->offsetWb;
//
// Load data block into the handle
//
while((i < 32) && (dataOffset < length))
{
handle->Ws[i] = data[dataOffset];
i++;
dataOffset++;
}
handle->offsetWb = (int16_t) i;
//
// After loading a block completely, process it
//
if(handle->offsetWb >= 32)
{
_SHA384_processBlockWordWise_casm_C28(handle->digest, (uint64_t *)handle->Ws);
handle->offsetWb = 0;
}
}
handle->bitsProcessed += length << 5;
return(result);
}
//*****************************************************************************
//
// SHA-384 add data block function
// Input data : Byte-wise
//
//*****************************************************************************
uint16_t SHA384_addDataByteWise(SHA384_HandleByteWise handle, uint16_t *data,
size_t length)
{
int16_t i;
size_t dataOffset;
uint16_t result = SHA384_STATUS_SUCCESS;
if((handle == NULL) || (data == NULL))
{
result = SHA384_STATUS_NULL_INPUT;
return(result);
}
if(length >= 0x20000000U)
{
result = SHA384_STATUS_LENGTH_TOO_LARGE;
return(result);
}
if(((length << 3u) + handle->bitsProcessed) < handle->bitsProcessed)
{
result = SHA384_STATUS_LENGTH_TOO_LARGE;
return(result);
}
dataOffset = 0;
while(dataOffset < length)
{
i = (int16_t) handle->offsetWb;
//
// Load data block into the handle
//
while((i < 128) && (dataOffset < length))
{
handle->Ws[i] = data[dataOffset];
i++;
dataOffset++;
}
handle->offsetWb = (int16_t) i;
//
// After loading a block completely, process it
//
if(handle->offsetWb >= 128)
{
// C-based implementation
// SHA384_processBlockByteWise(handle->digest, handle->Ws);
// ASM implementation
_SHA384_processBlockByteWise_casm_C28(handle->digest, handle->Ws);
handle->offsetWb = 0;
}
}
handle->bitsProcessed += length << 3;
return(result);
}
//*****************************************************************************
//
// SHA-384 finalize hash function
// Input message : Word-wise
//
//*****************************************************************************
uint16_t SHA384_finalizeWordWise(SHA384_HandleWordWise handle,
uint64_t digest[6])
{
int16_t i;
uint16_t paddedBlocks;
uint16_t result = SHA384_STATUS_SUCCESS;
if((handle == NULL) || (digest == NULL))
{
result = SHA384_STATUS_NULL_INPUT;
return(result);
}
i = handle->offsetWb;
//
// '1' pad bit
//
handle->Ws[i] = 0x80000000;
i++;
//
// If fewer than 16 bytes (128 bits) remain in current
// block, must pad out the current block and then pad out
// another block. (Need space to store 128 bit value
// of bits processed in the end of the last block.)
//
if(handle->offsetWb >= 28)
{
paddedBlocks = 2;
}
else
{
paddedBlocks = 1;
}
//
// Perform padding
//
do
{
//
// Finish out block with 0 pad.
//
while(i < 31)
{
handle->Ws[i] = 0;
i++;
}
//
// Write bitsProcessed into last block of padding.
// Note: implementation only supports 2^32 bits of input.
//
if(paddedBlocks == 1)
{
handle->Ws[i] = handle->bitsProcessed;
}
else
{
handle->Ws[i] = 0;
}
//
// Process the final block
//
_SHA384_processBlockWordWise_casm_C28(handle->digest, (uint64_t *)handle->Ws);
i = 0;
} while(--paddedBlocks > 0);
//
// Copy out final digest
//
digest[0] = handle->digest[0];
digest[1] = handle->digest[1];
digest[2] = handle->digest[2];
digest[3] = handle->digest[3];
digest[4] = handle->digest[4];
digest[5] = handle->digest[5];
//
// For security - clear data held by handle
//
SHA384_cancelWordWise(handle);
return(result);
}
//*****************************************************************************
//
// SHA-256 finalize hash function
//
//*****************************************************************************
uint16_t SHA384_finalizeByteWise(SHA384_HandleByteWise handle,
uint64_t digest[6])
{
int16_t i;
uint16_t paddedBlocks;
uint16_t result = SHA384_STATUS_SUCCESS;
if((handle == NULL) || (digest == NULL))
{
result = SHA384_STATUS_NULL_INPUT;
return(result);
}
i = handle->offsetWb;
//
// '1' pad bit
//
handle->Ws[i] = 0x80;
i++;
//
// If fewer than 16 bytes (128 bits) remain in current
// block, must pad out the current block and then pad out
// another block. (Need space to store 128 bit value
// of bits processed in the end of the last block.)
//
if(handle->offsetWb >= 112)
{
paddedBlocks = 2;
}
else
{
paddedBlocks = 1;
}
//
// Perform padding
//
do
{
//
// Finish out block with 0 pad.
//
while(i < 128)
{
handle->Ws[i] = 0;
i++;
}
//
// Write bitsProcessed into last block of padding.
// Note: implementation only supports 2^32 bits of input.
//
if(paddedBlocks == 1)
{
SHA384_PUTU32(&handle->Ws[124], handle->bitsProcessed)
}
//
// Process the final block
//
// C base implementation
// SHA384_processBlockByteWise(handle->digest, handle->Ws);
// ASM implementation
_SHA384_processBlockByteWise_casm_C28(handle->digest, handle->Ws);
i = 0;
} while(--paddedBlocks > 0);
//
// Copy out final digest
//
digest[0] = handle->digest[0];
digest[1] = handle->digest[1];
digest[2] = handle->digest[2];
digest[3] = handle->digest[3];
digest[4] = handle->digest[4];
digest[5] = handle->digest[5];
//
// For security - clear data held by handle
//
SHA384_cancelByteWise(handle);
return(result);
}
//*****************************************************************************
//
// SHA-384 clear handle
// Input message : Word-wise
//
//*****************************************************************************
void SHA384_cancelWordWise(SHA384_HandleWordWise handle)
{
int16_t i, j;
uint16_t * objAsBytes;
j = sizeof(SHA384_ObjectWordWise);
if(handle != NULL)
{
objAsBytes = (uint16_t *) handle;
for (i = 0; i < j; i++)
{
objAsBytes[i] = 0x0;
}
}
return;
}
//*****************************************************************************
//
// SHA-384 clear handle
// Input message : Byte-wise
//
//*****************************************************************************
void SHA384_cancelByteWise(SHA384_HandleByteWise handle)
{
int16_t i, j;
uint16_t * objAsBytes;
j = sizeof(SHA384_ObjectByteWise);
if(handle != NULL)
{
objAsBytes = (uint16_t *) handle;
for (i = 0; i < j; i++)
{
objAsBytes[i] = 0x0;
}
}
return;
}
//*****************************************************************************
//
// SHA-384 process a block of data
// Input message : Word-wise
//
//*****************************************************************************
void SHA384_processBlockWordWise(uint64_t digest[8], uint64_t Ws[16])
{
uint64_t wt; // Wt from standard
int16_t s; // s is the message schedule index
uint64_t temp1; // T1 from standard
uint64_t temp2; // T2 from standard
//
// Initialize working variables
//
uint64_t a = digest[0];
uint64_t b = digest[1];
uint64_t c = digest[2];
uint64_t d = digest[3];
uint64_t e = digest[4];
uint64_t f = digest[5];
uint64_t g = digest[6];
uint64_t h = digest[7];
//
// Perform 80 rounds of compression function
//
for(s = 0; s < 80; s++)
{
if(s >= 16)
{
Ws[s & 0xF] += SHA384_SIGMA1(Ws[(s + 14) & 0xF]) +
Ws[(s + 9) & 0xF] +
SHA384_SIGMAZ(Ws[(s + 1) & 0xF]);
}
else
{
Ws[s] = ((uint64_t)(Ws[s] << 32) | (uint64_t)(Ws[s] >> 32));
}
wt = Ws[s & 0xF];
temp1 = h + SHA384_SIG1(e) + SHA384_CH(e, f, g) + SHA384_K[s] + wt;
temp2 = SHA384_SIGZ(a) + SHA384_MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d + temp1;
d = c;
c = b;
b = a;
a = temp1 + temp2;
}
//
// Intermediate digest value
//
digest[0] += a;
digest[1] += b;
digest[2] += c;
digest[3] += d;
digest[4] += e;
digest[5] += f;
digest[6] += g;
digest[7] += h;
}
//*****************************************************************************
//
// SHA-384 process a block of data
// Input message : Byte-wise
//
//*****************************************************************************
void SHA384_processBlockByteWise(uint64_t digest[8], uint16_t Ws[128])
{
uint64_t wt; // Wt from standard
int16_t s, s0; // s is the message schedule index
uint64_t temp1; // T1 from standard
uint64_t temp2; // T2 from standard
//
// Initialize working variables
//
uint64_t a = digest[0];
uint64_t b = digest[1];
uint64_t c = digest[2];
uint64_t d = digest[3];
uint64_t e = digest[4];
uint64_t f = digest[5];
uint64_t g = digest[6];
uint64_t h = digest[7];
//
// Perform 64 rounds of compression function
//
for(s = 0; s < 80; s++)
{
s0 = s << 3;
if(s >= 16)
{
wt = SHA384_SIGMA1(SHA384_GETU64(&Ws[(s0 + 112) & 0x7F])) +
SHA384_GETU64(&Ws[(s0 + 72) & 0x7F]) +
SHA384_SIGMAZ(SHA384_GETU64(&Ws[(s0 + 8) & 0x7F])) +
SHA384_GETU64(&Ws[s0 & 0x7F]);
SHA384_PUTU64(&Ws[s0 & 0x7F], wt);
}
else
{
wt = SHA384_GETU64(&Ws[s0]);
}
temp1 = h + SHA384_SIG1(e) + SHA384_CH(e, f, g) + SHA384_K[s] + wt;
temp2 = SHA384_SIGZ(a) + SHA384_MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d + temp1;
d = c;
c = b;
b = a;
a = temp1 + temp2;
}
//
// Intermediate digest value
//
digest[0] += a;
digest[1] += b;
digest[2] += c;
digest[3] += d;
digest[4] += e;
digest[5] += f;
digest[6] += g;
digest[7] += h;
}
//
// End of file
//
File diff suppressed because it is too large Load Diff