1 /**
2  * \file rsa.h
3  *
4  * \brief This file provides an API for the RSA public-key cryptosystem.
5  *
6  * The RSA public-key cryptosystem is defined in <em>Public-Key
7  * Cryptography Standards (PKCS) #1 v1.5: RSA Encryption</em>
8  * and <em>Public-Key Cryptography Standards (PKCS) #1 v2.1:
9  * RSA Cryptography Specifications</em>.
10  *
11  */
12 /*
13  *  Copyright (C) 2006-2021, Arm Limited (or its affiliates), All Rights Reserved
14  *  Copyright (C) 2020, STMicroelectronics, All Rights Reserved
15  *  SPDX-License-Identifier: Apache-2.0
16  *
17  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
18  *  not use this file except in compliance with the License.
19  *  You may obtain a copy of the License at
20  *
21  *  http://www.apache.org/licenses/LICENSE-2.0
22  *
23  *  Unless required by applicable law or agreed to in writing, software
24  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  *  See the License for the specific language governing permissions and
27  *  limitations under the License.
28  *
29  *  This file is part of Mbed TLS (https://tls.mbed.org)
30  */
31 #ifndef MBEDTLS_RSA_ALT_H
32 #define MBEDTLS_RSA_ALT_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #if defined(MBEDTLS_RSA_ALT)
39 #include "stm32hal.h"
40 
41 // Regular implementation
42 //
43 
44 /**
45  * \brief   The RSA context structure.
46  *
47  * \note    Direct manipulation of the members of this structure
48  *          is deprecated. All manipulation should instead be done through
49  *          the public interface functions.
50  */
51 typedef struct mbedtls_rsa_context
52 {
53     int MBEDTLS_PRIVATE(ver);        /*!<  Always 0.*/
54     size_t MBEDTLS_PRIVATE(len);     /*!<  The size of \p N in Bytes. */
55 
56     mbedtls_mpi MBEDTLS_PRIVATE(N);  /*!<  The public modulus. */
57     mbedtls_mpi MBEDTLS_PRIVATE(E);  /*!<  The public exponent. */
58 
59     mbedtls_mpi MBEDTLS_PRIVATE(D);  /*!<  The private exponent. */
60     mbedtls_mpi MBEDTLS_PRIVATE(P);  /*!<  The first prime factor. */
61     mbedtls_mpi MBEDTLS_PRIVATE(Q);  /*!<  The second prime factor. */
62 #if defined(GENERATOR_HW_PKA_EXTENDED_API)
63     mbedtls_mpi MBEDTLS_PRIVATE(Phi);/*!<  The Euler tolient function. */
64 #endif
65     mbedtls_mpi MBEDTLS_PRIVATE(DP); /*!<  <code>D % (P - 1)</code>. */
66     mbedtls_mpi MBEDTLS_PRIVATE(DQ); /*!<  <code>D % (Q - 1)</code>. */
67     mbedtls_mpi MBEDTLS_PRIVATE(QP); /*!<  <code>1 / (Q % P)</code>. */
68 
69     mbedtls_mpi MBEDTLS_PRIVATE(RN); /*!<  cached <code>R^2 mod N</code>. */
70 
71     mbedtls_mpi MBEDTLS_PRIVATE(RP); /*!<  cached <code>R^2 mod P</code>. */
72     mbedtls_mpi MBEDTLS_PRIVATE(RQ); /*!<  cached <code>R^2 mod Q</code>. */
73 
74     mbedtls_mpi MBEDTLS_PRIVATE(Vi); /*!<  The cached blinding value. */
75     mbedtls_mpi MBEDTLS_PRIVATE(Vf); /*!<  The cached un-blinding value. */
76 
77     int MBEDTLS_PRIVATE(padding);    /*!< Selects padding mode:
78                                      #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
79                                      #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
80     int MBEDTLS_PRIVATE(hash_id);    /*!< Hash identifier of mbedtls_md_type_t type,
81                                      as specified in md.h for use in the MGF
82                                      mask generating function used in the
83                                      EME-OAEP and EMSA-PSS encodings. */
84 #if defined(MBEDTLS_THREADING_C)
85     mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex);    /*!<  Thread-safety mutex. */
86 #endif
87 }
88 mbedtls_rsa_context;
89 
90 #endif /* MBEDTLS_RSA_ALT */
91 
92 
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif /* MBEDTLS_RSA_ALT_H */
99