Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers crys_rsa_prim.h Source File

crys_rsa_prim.h

Go to the documentation of this file.
00001 /**************************************************************************************
00002 * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved         *
00003 *                                                                                     *
00004 * This file and the related binary are licensed under the following license:          *
00005 *                                                                                     *
00006 * ARM Object Code and Header Files License, v1.0 Redistribution.                      *
00007 *                                                                                     *
00008 * Redistribution and use of object code, header files, and documentation, without     *
00009 * modification, are permitted provided that the following conditions are met:         *
00010 *                                                                                     *
00011 * 1) Redistributions must reproduce the above copyright notice and the                *
00012 *    following disclaimer in the documentation and/or other materials                 *
00013 *    provided with the distribution.                                                  *
00014 *                                                                                     *
00015 * 2) Unless to the extent explicitly permitted by law, no reverse                     *
00016 *    engineering, decompilation, or disassembly of is permitted.                      *
00017 *                                                                                     *
00018 * 3) Redistribution and use is permitted solely for the purpose of                    *
00019 *    developing or executing applications that are targeted for use                   *
00020 *    on an ARM-based product.                                                         *
00021 *                                                                                     *
00022 * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND                  *
00023 * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT             *
00024 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT,        *
00025 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE          *
00026 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   *
00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED            *
00028 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR              *
00029 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF              *
00030 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING                *
00031 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS                  *
00032 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                        *
00033 **************************************************************************************/
00034 
00035 
00036 
00037 #ifndef CRYS_RSA_PRIM_H
00038 #define CRYS_RSA_PRIM_H
00039 
00040 #include "crys_rsa_types.h"
00041 
00042 #ifdef __cplusplus
00043 extern "C"
00044 {
00045 #endif
00046 
00047 /*!
00048 @file
00049 @brief This module defines the API that implements the [PKCS1_2.1] primitive functions.
00050 @defgroup crys_rsa_prim CryptoCell RSA primitive APIs
00051 @{
00052 @ingroup crys_rsa
00053 
00054 
00055 \note Direct use of primitive functions, rather than schemes to protect data, is strongly discouraged as primitive functions are
00056 susceptible to well-known attacks.
00057 */
00058 
00059 
00060 
00061 /**********************************************************************************/
00062 /*!
00063 @brief Implements the RSAEP algorithm, as defined in [PKCS1_2.1] - 6.1.1.
00064 
00065 @return CRYS_OK on success.
00066 @return A non-zero value from crys_rsa_error.h on failure.
00067  */
00068 CIMPORT_C CRYSError_t  CRYS_RSA_PRIM_Encrypt(
00069                                 CRYS_RSAUserPubKey_t  *UserPubKey_ptr,       /*!< [in]  Pointer to the public key data structure. */
00070                                 CRYS_RSAPrimeData_t   *PrimeData_ptr,        /*!< [in]  Pointer to a temporary structure containing internal buffers. */
00071                                 uint8_t              *Data_ptr,             /*!< [in]  Pointer to the data to encrypt. */
00072                                 uint16_t              DataSize,             /*!< [in]  The size (in bytes) of input data must be &le; modulus size. If is smaller,
00073                                                                                        then the function padds it by zeros on left side up to the modulus size
00074                                                                                    and therefore, after further decrypt operation, its result will contain
00075                                                                                        zero-padding also. If the function is used for recovering the plain data
00076                                                                                        from result of inverse function (CRYS_RSA_PRIM_Decrypt), the input size
00077                                                                                        must be equal to modulus size exactly. */
00078                                 uint8_t              *Output_ptr            /*!< [out] Pointer to the encrypted data. The buffer size must be &ge; the modulus size. */
00079 );
00080 
00081 
00082 /**********************************************************************************/
00083 /*!
00084 @brief Implements the RSADP algorithm, as defined in [PKCS1_2.1] - 6.1.2.
00085 
00086 @return CRYS_OK on success.
00087 @return A non-zero value from crys_rsa_error.h on failure.
00088 
00089 */
00090 CIMPORT_C CRYSError_t  CRYS_RSA_PRIM_Decrypt(
00091                             CRYS_RSAUserPrivKey_t  *UserPrivKey_ptr,     /*!< [in]  Pointer to the private key data structure.
00092                                                                                    The key representation (pair or quintuple) and hence the RSA algorithm
00093                                                                                    (CRT or not-CRT) is determined by enum value in the structure
00094                                            ::CRYS_RSA_Build_PrivKey or ::CRYS_RSA_Build_PrivKeyCRT. */
00095                             CRYS_RSAPrimeData_t    *PrimeData_ptr,       /*!< [in]  Pointer to a temporary structure containing internal buffers required for
00096                                            the RSA operation. */
00097                             uint8_t     *Data_ptr,                      /*!< [in]  Pointer to the data to be decrypted. */
00098                             uint16_t     DataSize,                      /*!< [in]  The size (in bytes) of input data must be &le; modulus size.
00099                                                                                    If the size is smaller (not recommendet), then the data will be zero-padded
00100                                                                                    by the function on left side up to the modulus size and therefore, after further
00101                                                                                    decrypt operation,its result will contain zero-padding also. If the function is used
00102                                                                                    for recovering the plain data from result of inverse function (CRYS_RSA_PRIM_Encrypt),
00103                                                                                    the input size must be equal to modulus size exactly. */
00104                             uint8_t     *Output_ptr                     /*!< [out] Pointer to the decrypted data. The buffer size must be &le; the modulus size. */
00105 );
00106 
00107 
00108 /*!
00109 @brief Implements the RSASP1 algorithm, as defined in [PKCS1_2.1] - 6.2.1, as a call to ::CRYS_RSA_PRIM_Decrypt,
00110 since the signature primitive is identical to the decryption primitive.
00111 */
00112 #define CRYS_RSA_PRIM_Sign CRYS_RSA_PRIM_Decrypt
00113 
00114 /*!
00115 @brief Implements the RSAVP1 algorithm, as defined in [PKCS1_2.1] - 6.2.2, as a call to ::CRYS_RSA_PRIM_Encrypt.
00116 */
00117 #define CRYS_RSA_PRIM_Verify CRYS_RSA_PRIM_Encrypt
00118 
00119 #ifdef __cplusplus
00120 }
00121 #endif
00122 /**
00123 @}
00124  */
00125 #endif