Welcome to mirror list, hosted at ThFree Co, Russian Federation.

aes_gcm.h « GCM « AES « Inc « cryptographic « ble « STM32_WPAN « ST « Middlewares - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e828b02034dfe91562b1d58414ab936eb147fa99 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
  ******************************************************************************
  * @file    aes_gcm.h
  * @author  MCD Application Team
  * @brief   AES in GCM Mode
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; 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
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CRL_AES_GCM_H__
#define __CRL_AES_GCM_H__

#ifdef __cplusplus
extern "C"
{
#endif

  /** @ingroup AESGCMlowlevel
    * @{
    */
  /* Exported types ------------------------------------------------------------*/
  typedef uint32_t poly_t[4]; /*!< Definition of the way a polynomial of max degree 127 is represented */

#if CRL_GFMUL==1
  typedef poly_t table16_t[16]; /*!< Definition of the type used for the precomputed table */
#elif CRL_GFMUL==2
  typedef poly_t table8x16_t[8][16]; /*!< Definition of the type used for the precomputed table */
#elif CRL_GFMUL==0
#else
#error "A value for CRL_GFMUL MUST be provided when INCLUDE_GCM is defined"
#endif

  /** @} */

  /** @ingroup AESGCM
    * @{
    */

  typedef struct
  {
    uint32_t   mContextId; /*!< Unique ID of this AES-GCM Context. \b Not \b used in current implementation. */
    SKflags_et mFlags; /*!< 32 bit mFlags, used to perform keyschedule */
    const uint8_t *pmKey; /*!< Pointer to original Key buffer */
    const uint8_t *pmIv; /*!< Pointer to original Initialization Vector buffer */
    int32_t   mIvSize; /*!< Size of the Initialization Vector in bytes. This must be set by the caller prior to calling Init */
    uint32_t   amIv[4]; /*!< This is the current IV value.*/
    int32_t   mKeySize;   /*!< AES Key length in bytes. This must be set by the caller prior to calling Init */
    const uint8_t *pmTag; /*!< Pointer to Authentication TAG. This value must be set in decryption, and this TAG will be verified */
    int32_t mTagSize; /*!< Size of the Tag to return. This must be set by the caller prior to calling Init */
    int32_t mAADsize;   /*!< Additional authenticated data size. For internal use. */
    int32_t mPayloadSize;   /*!< Payload size. For internal use. */
    poly_t mPartialAuth; /*!< Partial authentication value. For internal use. */
    uint32_t amExpKey[CRL_AES_MAX_EXPKEY_SIZE];   /*!< AES Expanded key. For internal use.  */

#if CRL_GFMUL==0
    poly_t  mPrecomputedValues; /*!< (CRL_GFMUL==0) No precomputed tables, just the polynomial. For internal use. */
#elif CRL_GFMUL==1
    table16_t mPrecomputedValues; /*!< (CRL_GFMUL==1) Precomputation of polynomial according to Shoup's 4-bit table\n (Requires 256 bytes of key-dependent data and 32 bytes of constant data). For internal use. */
#elif CRL_GFMUL==2
    table8x16_t mPrecomputedValues; /*!< (CRL_GFMUL==2) Precomputation of polynomial according to Shoup's 8-bit table\n (Requires 4096 bytes of key-dependent data and 512 bytes of constant data). For internal use. */
#endif
  }
  AESGCMctx_stt; /*!< Structure used only for AES-GCM. Used to store the expanded key and, eventually,
                        precomputed tables, according the the defined value of CRL_GFMUL in config.h */

  /* Exported functions --------------------------------------------------------*/
  /* load the key and ivec, eventually performs key schedule, etc. */
  int32_t AES_GCM_Encrypt_Init(AESGCMctx_stt *P_pAESGCMctx, \
                               const uint8_t *P_pKey,       \
                               const uint8_t *P_pIv);

  /* Header Processing Function */
  int32_t AES_GCM_Header_Append(AESGCMctx_stt *P_pAESGCMctx,    \
                                const uint8_t *P_pInputBuffer, \
                                int32_t        P_inputSize);

  /* launch crypto operation , can be called several times */
  int32_t AES_GCM_Encrypt_Append (AESGCMctx_stt *P_pAESGCMctx,   \
                                  const uint8_t *P_pInputBuffer, \
                                  int32_t        P_inputSize,    \
                                  uint8_t       *P_pOutputBuffer, \
                                  int32_t       *P_pOutputSize);

  /* Possible final output */
  int32_t AES_GCM_Encrypt_Finish (AESGCMctx_stt *P_pAESGCMctx,   \
                                  uint8_t       *P_pOutputBuffer, \
                                  int32_t       *P_pOutputSize);
  \

  /* load the key and ivec, eventually performs key schedule, etc. */
  int32_t AES_GCM_Decrypt_Init (AESGCMctx_stt *P_pAESGCMctx, \
                                const uint8_t *P_pKey,      \
                                const uint8_t *P_pIv);
  \

  /* launch crypto operation , can be called several times */
  int32_t AES_GCM_Decrypt_Append (AESGCMctx_stt *P_pAESGCMctx,   \
                                  const uint8_t *P_pInputBuffer, \
                                  int32_t        P_inputSize,    \
                                  uint8_t       *P_pOutputBuffer, \
                                  int32_t       *P_pOutputSize);
  \

  /* Possible final output */
  int32_t AES_GCM_Decrypt_Finish (AESGCMctx_stt *P_pAESGCMctx,   \
                                  uint8_t       *P_pOutputBuffer, \
                                  int32_t       *P_pOutputSize);


  /** @} */

#ifdef __cplusplus
}
#endif

#endif /* __CRL_AES_GCM_H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/