AM64x MCU+ SDK  08.01.00
Crypto SHA

SHA is Secure Hash Algorithm, It is used as a unique value of fixed size representing a large amount of data. Hashes of two sets of data should match if and only if the corresponding data also matches. Small changes to the data result in large unpredictable changes in the hash.The hash size for the SHA512 algorithm is 512 bits and hash size for the SHA256 algorithm is 256 bits.

Features Supported

  • Latest versions of Secure Hash Algorithm SHA-512 and SHA-256
  • Handles different input buffer lengths.
  • It used upto 1024 bits blocks.
  • Accepts 2^128 bits maximum length string.
  • The initial hash values and round constants are 64 bits in SHA-512 and 32 bits in SHA-256.
  • No of rounds 80 for SHA-512 and 64 rounds for SHA 256.
  • Word size 64 bits for SHA-512 and 32 bits for SHA-256.
  • Supports Hmac Sha-512 and Sha-256.

SysConfig Features

Features NOT Supported

Usage Overview

API Sequence

To use the SHA driver to generate hash for differnt data. Use the following APIs:

HMAC API Sequence

To use the HMAC SHA driver to generate hash for differnt data. Use the following APIs:

Initializing the SHA Driver context buffer

  • Crypto_shaOpen() must be called before any other SHA APIs. This function Initializes a SHA context and iterates through the elements of the gCryptoShaConfig[] array. Please note that initializing SHA driver is taken care by the SysConfig generated code.

Generating Hash with SHA Driver

Generating HMAC SHA

  • Set the input parameters using Crypto_ShaParams structure, all necessary parametets set to Crypto_ShaParams variables and call Crypto_shaOpen() for Initialize the Sha ctx. To compute fixed block Hmac hash i.e call Crypto_hmacSha() by updating references to input buffer, length and Output buffer. Hash will be available at output buffer on successful computation. Once SHA computation is done for the required data length, reset the SHA ctx buffer using Crypto_shaClose().

Clearing the SHA Driver context buffer

Important Usage Guidelines

Example Usage

Include the below file to access the APIs

#include<stdio.h>

Hash Example

Crypto_ShaHandle shaHandle;
/* Context memory */
static Crypto_ShaContext gCryptoSha512Context;
uint8_t buf[10]={"abcedfghij"};
int32_t buf_len=10;
uint8_t sha512sum[64];
/* Fixed Block SHA512 computation */
shaHandle = Crypto_shaOpen(&gCryptoSha512Context, &params);
Crypto_shaSingleShot(shaHandle, buf, buf_len, sha512sum);
Crypto_shaClose(shaHandle);
/*For Multi buffer SHA512 computation */
shaHandle = Crypto_shaOpen(&gCryptoSha512Context, &params);
Crypto_shaStarts(shaHandle);
Crypto_shaUpdate(shaHandle, buf, buf_len);
Crypto_shaFinish(shaHandle, sha512sum );
Crypto_shaClose(shaHandle);

API

APIs for CRYPTO SHA

Crypto_shaStarts
int32_t Crypto_shaStarts(Crypto_ShaHandle handle)
This function starts a Secure Hash Algorithm (SHA ) checksum calculation.
Crypto_shaFinish
int32_t Crypto_shaFinish(Crypto_ShaHandle handle, uint8_t *output)
This function finishes the Secure Hash Algorithm (SHA ) operation, and writes the result to the outpu...
Crypto_shaUpdate
int32_t Crypto_shaUpdate(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen)
This function feeds an input buffer into an ongoing Secure Hash Algorithm (SHA ) checksum calculation...
crypto_sha.h
Crypto_ShaParams
Parameters passed during Crypto_shaOpen()
Definition: crypto_sha.h:111
Crypto_shaSingleShot
int32_t Crypto_shaSingleShot(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output)
This function calculates the Secure Hash Algorithm (SHA) checksum of a buffer.
Crypto_ShaHandle
void * Crypto_ShaHandle
Handle to the Crypto SHA driver returned by Crypto_shaOpen()
Definition: crypto_sha.h:98
Crypto_shaOpen
Crypto_ShaHandle Crypto_shaOpen(Crypto_ShaContext *ctx, const Crypto_ShaParams *params)
This function gives the configuration based on type.
Crypto_shaClose
int32_t Crypto_shaClose(Crypto_ShaHandle handle)
This function clears a Secure Hash Algorithm (SHA ) context.