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

aes_low_level.h « Common « 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: 7eef9a5ac78c64d9bf97fe4d1b0f1ab588bd22d3 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
  ******************************************************************************
  * @file    aes_low_level.h
  * @author  MCD Application Team
  * @brief   AES low level functions
  ******************************************************************************
  * @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 __AES_LOW_LEVEL_H__
#define __AES_LOW_LEVEL_H__

#ifdef __cplusplus
extern "C"
{
#endif

  /** @addtogroup AESlowlevel
    * @{
    */

  /*------------------------------------------------------------------------------
  AES - Advanced Encryption Standard
  ------------------------------------------------------------------------------*/
  /* key size:    16 bytes (aes128), 24 bytes (aes192) or 32 bytes (aes256)
  *  block size:  16 bytes */

#define AES_BLOCK_SIZE 4 /*!< Number of (uint32_t) 32 bit words to store an AES block. */

  /*---------------------------AES MACROS---------------------------------------*/

  /** @defgroup AESmacros AES Macros
    * @{
    */

  /** Multiply for 2 each byte of a uint32_t working in parallel mode on each one. */
#define Xtime(x)  ((((x) & 0x7F7F7F7Fu) << 1) ^ ((((x) & 0x80808080u) >> 7) * 0x0000001Bu))

  /** Right shift x of n bytes. */
#define upr(x,n) ((x) >> (8*(n))) | ((x) << (32 - (8*(n))))

  /** Develop of the matrix necessary for the MixColomn procedure. */
#define fwd_mcol(x)  (Xtime(x)^(upr(((x)^Xtime(x)),3)) ^ (upr((x),2)) ^ (upr((x),1)))

  /** Develop of the matrix necessary for the InvMixColomn procedure. */
#define inv_mcol(x)  (f2=Xtime(x),f4=Xtime(f2),f8=Xtime(f4),(x)^=f8, f2^=f4^f8^(upr((f2^(x)),3))^(upr((f4^(x)),2))^(upr((x),1)))


  /** Defines right rotation of a uint32_t by 3.*/
#define rot3(x) (((x) << 8 ) | ((x) >> 24))
  /** Defines right rotation of a uint32_t by 2.*/
#define rot2(x) (((x) << 16) | ((x) >> 16))
  /** Defines right rotation of a uint32_t by 1.*/
#define rot1(x) (((x) << 24) | ((x) >> 8 ))

  /**
   * @}
   */


  /**
   * @}
   */



  /*----- AES 128 ---------------------------------------------------------------- */
  /** @ingroup AES128
    * @{
    */

#define AES_KEY_SIZE         4 /*!< Number of (uint32_t) 32 bit words to store an AES128 key. */
#define AES_EXPKEY_SIZE     44 /*!< Number of (uint32_t) 32 bit words to store an AES128 expanded key. */

  /* According to key computes the expanded key exp for AES128 encryption. */
  void AES128_keyschedule_enc(const uint32_t* key, uint32_t* expkey) ;
  /* According to key computes the expanded key exp for AES128 decryption. */
  void AES128_keyschedule_dec(const uint32_t* key, uint32_t* expkey) ;
  /* AES128 encryption of an AES128 block. */
  void AES128_encrypt(const uint32_t* input_pointer, uint32_t* output_pointer, const uint32_t* expkey) ;
  /* AES128 decryption of an AES128 block. */
  void AES128_decrypt(const uint32_t* input_pointer, uint32_t* output_pointer, const uint32_t* expkey) ;

  /**
   * @}
   */

  /*----- AES 192 ----------------------------------------------------------------*/
  /** @ingroup AES192
    * @{
    */

#define AES192_BLOCK_SIZE    4 /*!< Number of (uint32_t) 32 bit words to store an AES192 block. */
#define AES192_KEY_SIZE      6 /*!< Number of (uint32_t) 32 bit words to store an AES192 key. */
#define AES192_EXPKEY_SIZE  52 /*!< Number of (uint32_t) 32 bit words to store an AES192 expanded key. */

  /* According to key computes the expanded key exp for AES192 encryption.*/
  void AES192_keyschedule_enc(const uint32_t* key, uint32_t* exp) ;
  /* According to key computes the expanded key exp for AES192 decryption. */
  void AES192_keyschedule_dec(const uint32_t* key, uint32_t* exp) ;
  /* AES192 encryption of an AES192 block. */
  void AES192_encrypt(const uint32_t* input_pointer, uint32_t* output_pointer, const uint32_t* expkey) ;
  /* AES192 decryption of an AES192 block. */
  void AES192_decrypt(const uint32_t* input_pointer, uint32_t* output_pointer, const uint32_t* expkey) ;

  /**
   * @}
   */

  /*----- AES 256 ----------------------------------------------------------------*/
  /** @ingroup AES256
    * @{
    */

#define AES256_BLOCK_SIZE    4 /*!< Number of (uint32_t) 32 bit words to store an AES256 block. */
#define AES256_KEY_SIZE      8 /*!< Number of (uint32_t) 32 bit words to store an AES256 key. */
#define AES256_EXPKEY_SIZE  60 /*!< Number of (uint32_t) 32 bit words to store an AES256 expanded key. */

  /* According to key computes the expanded key exp for AES256 encryption. */
  void AES256_keyschedule_enc(const uint32_t* key, uint32_t* exp) ;
  /* According to key computes the expanded key exp for AES256 decryption. */
  void AES256_keyschedule_dec(const uint32_t* key, uint32_t* exp) ;
  /* AES256 encryption of an AES256 block. */
  void AES256_encrypt(const uint32_t* input_pointer, uint32_t* output_pointer, const uint32_t* expkey) ;
  /* AES256 decryption of an AES256 block. */
  void AES256_decrypt(const uint32_t* input_pointer, uint32_t* output_pointer, const uint32_t* expkey) ;

  /**
   * @}
   */

#ifdef __cplusplus
}
#endif


#endif  /*__AES_LOW_LEVEL_H__*/


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