Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
rsa.h
00001 /** 00002 * @file rsa.h 00003 * @brief RSA public-key cryptography standard 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneCrypto Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _RSA_H 00030 #define _RSA_H 00031 00032 //Dependencies 00033 #include "crypto.h" 00034 #include "mpi.h" 00035 00036 00037 /** 00038 * @brief RSA public key 00039 **/ 00040 00041 typedef struct 00042 { 00043 Mpi n; ///<Modulus 00044 Mpi e; ///<Public exponent 00045 } RsaPublicKey; 00046 00047 00048 /** 00049 * @brief RSA private key 00050 **/ 00051 00052 typedef struct 00053 { 00054 Mpi n; ///<Modulus 00055 Mpi e; ///<Public exponent 00056 Mpi d; ///<Private exponent 00057 Mpi p; ///<First factor 00058 Mpi q; ///<Second factor 00059 Mpi dp; ///<First factor's CRT exponent 00060 Mpi dq; ///<second factor's CRT exponent 00061 Mpi qinv; ///<CRT coefficient 00062 } RsaPrivateKey; 00063 00064 00065 //RSA related constants 00066 extern const uint8_t PKCS1_OID[8]; 00067 extern const uint8_t RSA_ENCRYPTION_OID[9]; 00068 extern const uint8_t MD5_WITH_RSA_ENCRYPTION_OID[9]; 00069 extern const uint8_t SHA1_WITH_RSA_ENCRYPTION_OID[9]; 00070 extern const uint8_t SHA256_WITH_RSA_ENCRYPTION_OID[9]; 00071 extern const uint8_t SHA384_WITH_RSA_ENCRYPTION_OID[9]; 00072 extern const uint8_t SHA512_WITH_RSA_ENCRYPTION_OID[9]; 00073 extern const uint8_t RSASSA_PKCS1_v1_5_WITH_SHA3_224_OID[9]; 00074 extern const uint8_t RSASSA_PKCS1_v1_5_WITH_SHA3_256_OID[9]; 00075 extern const uint8_t RSASSA_PKCS1_v1_5_WITH_SHA3_384_OID[9]; 00076 extern const uint8_t RSASSA_PKCS1_v1_5_WITH_SHA3_512_OID[9]; 00077 00078 //RSA related functions 00079 void rsaInitPublicKey(RsaPublicKey *key); 00080 void rsaFreePublicKey(RsaPublicKey *key); 00081 void rsaInitPrivateKey(RsaPrivateKey *key); 00082 void rsaFreePrivateKey(RsaPrivateKey *key); 00083 00084 error_t rsaep(const RsaPublicKey *key, const Mpi *m, Mpi *c); 00085 error_t rsadp(const RsaPrivateKey *key, const Mpi *c, Mpi *m); 00086 00087 error_t rsasp1(const RsaPrivateKey *key, const Mpi *m, Mpi *s); 00088 error_t rsavp1(const RsaPublicKey *key, const Mpi *s, Mpi *m); 00089 00090 error_t rsaesPkcs1v15Encrypt(const PrngAlgo *prngAlgo, void *prngContext, const RsaPublicKey *key, 00091 const uint8_t *message, size_t messageLength, uint8_t *ciphertext, size_t *ciphertextLength); 00092 00093 error_t rsaesPkcs1v15Decrypt(const RsaPrivateKey *key, const uint8_t *ciphertext, 00094 size_t ciphertextLength, uint8_t *message, size_t messageSize, size_t *messageLength); 00095 00096 error_t rsassaPkcs1v15Sign(const RsaPrivateKey *key, const HashAlgo *hash, 00097 const uint8_t *digest, uint8_t *signature, size_t *signatureLength); 00098 00099 error_t rsassaPkcs1v15Verify(const RsaPublicKey *key, const HashAlgo *hash, 00100 const uint8_t *digest, const uint8_t *signature, size_t signatureLength); 00101 00102 error_t emsaPkcs1v15Encode(const HashAlgo *hash, 00103 const uint8_t *digest, uint8_t *em, size_t emLength); 00104 00105 error_t emsaPkcs1v15Decode(const uint8_t *em, size_t emLength, const uint8_t **oid, 00106 size_t *oidLength, const uint8_t **digest, size_t *digestLength); 00107 00108 #endif 00109
Generated on Tue Jul 12 2022 17:10:15 by
1.7.2