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

monty.h « BN « MATH « Common_ecc_rsa « 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: 5f521ae2bfde655c1ff2ede5a35a3959694a6062 (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
/**
  ******************************************************************************
  * @file    monty.h
  * @author  MCD Application Team
  * @version V3.0.0
  * @date    05-June-2015
  * @brief   Provides Montgomery Operations
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Image SW License Agreement V2, (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/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

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

/* When multiplications are required the routines called are: MultiplyBig() and SquareBig().
*  The implementation of these two functions depends by the value of the constant
*  BASIC_MUL_BIG defined in MulDiv.h. */

#ifdef __cplusplus
extern "C"
{
#endif

  /* Includes ------------------------------------------------------------------*/

  /** @ingroup Monty
    * @{
    */

  /* Exported types ------------------------------------------------------------*/

  /**
    * @brief  Structure used to store Montgomery domain parameters.
    */
  typedef struct
  {
    const BigNum_stt *pmModulusBN;  /*!< The modulus on which are reffered the parameters. */
    BigNum_stt *pmR2;               /*!< The Montgomery Parameter */
    uint32_t mModInvLSW;            /*!<  The least significant word of -(modulus^(-1)) (mod MontRadix). */
    membuf_stt *pmMemBuf;
  }
  montyParams_stt;

  /* Exported functions ------------------------------------------------------- */

  /* Montgomery Modular Operations **********************************************/

  /* Comment:  given an integer x in Zm, the Montgomery residue (o M-residue) is:
  *            xR (mod m), get as: MontyExit(A = x*R^2,T) or
  *             MontyMul(x,R^2,Residuo_x).                                      */

  /* Initializes Montgomery parameters according to the modulus m. (different implementation) */
  int32_t MontyInit (const BigNum_stt *P_pModulusBN, \
                     montyParams_stt *P_pMontyParams, \
                     membuf_stt *P_pMemBuf);
  \
  /* Free R^2 inside the montgomery parameters contained in a montyParams_stt structure */
  void MontyKillR2  (montyParams_stt * P_pMontyParams);

  /* Sets to zero all Montgomery parameters. ************************************/
  void MontyKillAll (montyParams_stt *P_pMontyParams);

  /* y=x(R^-1) (mod m); x from the Montgomery domain it is carried to integer modulo m. */
  int32_t MontyExit (const BigNum_stt *P_pMontyBN,         \
                     BigNum_stt *P_pNormalBN,               \
                     const montyParams_stt *P_pMontyParams);
  \

  /* Montgomery cios multiplication *********************************************/
  int32_t MontyMul (const BigNum_stt * P_pFactor1BN,       \
                    const BigNum_stt * P_pFactor2BN,       \
                    BigNum_stt * P_pProductBN,             \
                    const montyParams_stt *P_pMontyParams);
  \

  /* Exported macros ------------------------------------------------------- */
  /* Squaring in monty domain ***************************************************/
#define MontySqr(P_Base,P_Square,P_pMontyParams) MontyMul((P_Base),(P_Base),(P_Square),(P_pMontyParams))

  /**
    * @}
    */

#ifdef __cplusplus
}
#endif

#endif  /*__CRL_MONTY_H__*/

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