rsa_misc.h
Go to the documentation of this file.
1 /**
2  * @file rsa_misc.h
3  * @brief Helper routines for RSA
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.0
29  **/
30 
31 #ifndef _RSA_MISC_H
32 #define _RSA_MISC_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "pkc/rsa.h"
37 
38 //C++ guard
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 //RSA related functions
44 error_t rsaep(const RsaPublicKey *key, const Mpi *m, Mpi *c);
45 error_t rsadp(const RsaPrivateKey *key, const Mpi *c, Mpi *m);
46 
47 error_t rsasp1(const RsaPrivateKey *key, const Mpi *m, Mpi *s);
48 error_t rsavp1(const RsaPublicKey *key, const Mpi *s, Mpi *m);
49 
50 error_t emePkcs1v15Encode(const PrngAlgo *prngAlgo, void *prngContext,
51  const uint8_t *message, size_t messageLen, uint8_t *em, size_t k);
52 
53 uint32_t emePkcs1v15Decode(uint8_t *em, size_t k, size_t *messageLen);
54 
55 error_t emeOaepEncode(const PrngAlgo *prngAlgo, void *prngContext,
56  const HashAlgo *hash, const char_t *label, const uint8_t *message,
57  size_t messageLen, uint8_t *em, size_t k);
58 
59 uint32_t emeOaepDecode(const HashAlgo *hash, const char_t *label, uint8_t *em,
60  size_t k, size_t *messageLen);
61 
63  const uint8_t *digest, uint8_t *em, size_t emLen);
64 
65 error_t emsaPkcs1v15Verify(const HashAlgo *hash, const uint8_t *digest,
66  const uint8_t *em, size_t emLen);
67 
68 error_t emsaPssEncode(const PrngAlgo *prngAlgo, void *prngContext,
69  const HashAlgo *hash, size_t saltLen, const uint8_t *digest,
70  uint8_t *em, uint_t emBits);
71 
72 error_t emsaPssVerify(const HashAlgo *hash, size_t saltLen,
73  const uint8_t *digest, uint8_t *em, uint_t emBits);
74 
75 void mgf1(const HashAlgo *hash, HashContext *hashContext, const uint8_t *seed,
76  size_t seedLen, uint8_t *data, size_t dataLen);
77 
78 //C++ guard
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif
Generic hash algorithm context.
Arbitrary precision integer.
Definition: mpi.h:102
#define PrngAlgo
Definition: crypto.h:973
error_t rsaep(const RsaPublicKey *key, const Mpi *m, Mpi *c)
RSA encryption primitive.
uint8_t message[]
Definition: chap.h:154
error_t emsaPkcs1v15Verify(const HashAlgo *hash, const uint8_t *digest, const uint8_t *em, size_t emLen)
EMSA-PKCS1-v1_5 verification operation.
Definition: rsa_misc.c:583
uint8_t data[]
Definition: ethernet.h:222
error_t emsaPssVerify(const HashAlgo *hash, size_t saltLen, const uint8_t *digest, uint8_t *em, uint_t emBits)
EMSA-PSS verification operation.
Definition: rsa_misc.c:749
error_t emsaPssEncode(const PrngAlgo *prngAlgo, void *prngContext, const HashAlgo *hash, size_t saltLen, const uint8_t *digest, uint8_t *em, uint_t emBits)
EMSA-PSS encoding operation.
Definition: rsa_misc.c:659
error_t rsavp1(const RsaPublicKey *key, const Mpi *s, Mpi *m)
RSA verification primitive.
Definition: rsa_misc.c:189
error_t emsaPkcs1v15Encode(const HashAlgo *hash, const uint8_t *digest, uint8_t *em, size_t emLen)
EMSA-PKCS1-v1_5 encoding operation.
Definition: rsa_misc.c:519
error_t rsadp(const RsaPrivateKey *key, const Mpi *c, Mpi *m)
RSA decryption primitive.
void mgf1(const HashAlgo *hash, HashContext *hashContext, const uint8_t *seed, size_t seedLen, uint8_t *data, size_t dataLen)
MGF1 mask generation function.
Definition: rsa_misc.c:855
uint32_t emePkcs1v15Decode(uint8_t *em, size_t k, size_t *messageLen)
EME-PKCS1-v1_5 decoding operation.
Definition: rsa_misc.c:277
error_t
Error codes.
Definition: error.h:43
RSA public key.
Definition: rsa.h:57
General definitions for cryptographic algorithms.
RSA public-key cryptography standard.
uint32_t dataLen
Definition: sftp_common.h:229
char char_t
Definition: compiler_port.h:55
uint32_t emeOaepDecode(const HashAlgo *hash, const char_t *label, uint8_t *em, size_t k, size_t *messageLen)
EME-OAEP decoding operation.
Definition: rsa_misc.c:421
uint8_t m
Definition: ndp.h:304
RSA private key.
Definition: rsa.h:68
error_t emePkcs1v15Encode(const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *message, size_t messageLen, uint8_t *em, size_t k)
EME-PKCS1-v1_5 encoding operation.
Definition: rsa_misc.c:209
error_t emeOaepEncode(const PrngAlgo *prngAlgo, void *prngContext, const HashAlgo *hash, const char_t *label, const uint8_t *message, size_t messageLen, uint8_t *em, size_t k)
EME-OAEP encoding operation.
Definition: rsa_misc.c:331
uint8_t s
Definition: igmp_common.h:234
Common interface for hash algorithms.
Definition: crypto.h:1082
unsigned int uint_t
Definition: compiler_port.h:57
error_t rsasp1(const RsaPrivateKey *key, const Mpi *m, Mpi *s)
RSA signature primitive.
Definition: rsa_misc.c:168
uint8_t c
Definition: ndp.h:514