1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/**
******************************************************************************
* @file hmac_sha512.h
* @author MCD Application Team
* @brief Provides HMAC-SHA512 functions
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Image license SLA0044,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* http://www.st.com/SLA0044
*
******************************************************************************
*/
/*! \page Tutorial_HMACSHA512 HMAC-SHA512 Tutorial
*
* Here follows an example of HMAC-SHA512 functionality.
* Please remember that before starting to call the Init function the context \b requires user
* initialization. \n
* The mFlags, mTagSize, pmKey and mKeySize members must be initialized prior to calling the
* init function. Look at the each function documentation to see what is needed prior of calling.
*
* The API functions to be used are:
* - \ref HMAC_SHA512_Init initialize an \ref HMAC_SHA512ctx_stt context with required tag size, pointer to the key, key size and flags.
* - \ref HMAC_SHA512_Append process input buffers.
* It can be called multiple times.
* - \ref HMAC_SHA512_Finish can be called only one time for the tag generation process.
*
* The following code performs a HMAC-SHA512 authentication of a buffer of size 1024 in 4 Append calls.
* \code
* #include <stdio.h>
* #include "crypto.h"
* int32_t main()
* {
* uint8_t message[1024]={...};
* uint8_t key[12]={...};
* uint8_t tag[4]; // In this example we just need a 4 byte tag
* // outSize is for digest output size, retval is for return value
* int32_t outSize, retval;
* HMAC_SHA512ctx_stt context_st; // The HMAC-SHA512 context
*
* // Initialize Context Flag with default value
* context_st.mFlags = E_HASH_DEFAULT;
* // Set the required digest size to 4
* context_st.mTagSize = 4;
* // Set the pointer to the Key to be used for the authentication
* context_st.pmKey = key;
* // Set the key size
* context_st.mKeySize = sizeof(key);
*
* // call init function
* retval = HMAC_SHA512_Init(&context_st);
* if (retval != HASH_SUCCESS)
* { ... }
*
* // Loop to perform four calls to SHA512_Append, each processing 256 bytes
* for (i = 0; i < 1024; i += 256)
* { //Process i bytes of the message.
* retval = HMAC_SHA512_Append(&context_st, message+i, 256);
* if (retval != HASH_SUCCESS)
* { ... }
* }
* //Generate the message digest
* retval = HMAC_SHA512_Finish(&context_st, tag, &outSize );
* if (retval != HASH_SUCCESS)
* { ... }
* }
* \endcode
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CRL_HMAC_SHA512_H__
#define __CRL_HMAC_SHA512_H__
#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
/** @ingroup HMAC_SHA512
* @{
*/
/**
* @brief HMAC-SHA-512 Context Structure
*/
typedef HMACLctx_stt HMAC_SHA512ctx_stt;
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
int32_t HMAC_SHA512_Init(HMAC_SHA512ctx_stt *P_pHMAC_SHA512ctx);
int32_t HMAC_SHA512_Append(HMAC_SHA512ctx_stt *P_pHMAC_SHA512ctx, const uint8_t *P_pInputBuffer, int32_t P_inputSize);
int32_t HMAC_SHA512_Finish(HMAC_SHA512ctx_stt *P_pHMAC_SHA512ctx, uint8_t *P_pOutputBuffer, int32_t *P_pOutputSize);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __CRL_HMAC_SHA512_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|