nrfxlib API 3.3.99
Loading...
Searching...
No Matches
ocrypto_rsa_primitives.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 - 2025 Nordic Semiconductor ASA
3 * Copyright (c) since 2013 Oberon microsystems AG
4 *
5 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
6 */
7
8
31#ifndef OCRYPTO_RSA_PRIMITIVES_H
32#define OCRYPTO_RSA_PRIMITIVES_H
33
34#include <stddef.h>
35#include <stdint.h>
36
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42
46#define OCRYPTO_RSA_PUB_KEY_SIZE(bits) ((bits)/32)
47
51#define OCRYPTO_RSA_KEY_SIZE(bits) ((bits)/32*2)
52
56#define OCRYPTO_RSA_CRT_KEY_SIZE(bits) ((bits)/32*7/2)
57
58
62#define OCRYPTO_RSA_PUB_MEM_SIZE(bits) ((bits)/32*11)
63
67#define OCRYPTO_RSA_MEM_SIZE(bits) ((bits)/32*26)
68
72#define OCRYPTO_RSA_CRT_MEM_SIZE(bits) ((bits)/32*14)
73
74
79typedef struct {
81 uint32_t *n;
82 uint32_t e;
83 int blocks; // block size of n
86
90typedef struct {
92 uint32_t *n;
93 uint32_t *d; // x^(e*d) mod n == x
94 int blocks; // block size of n
97
101typedef struct {
103 uint32_t *n;
104 uint32_t *p; // primes, p*q = n
105 uint32_t *q;
106 uint32_t *dp; // d mod (p-1)
107 uint32_t *dq; // d mod (q-1)
108 uint32_t *qinv; // 1/q mod p
109 int blocks; // block size of n
138 uint32_t *key_mem,
139 const uint8_t *n, size_t n_len,
140 uint32_t e);
141
160 ocrypto_rsa_key *key,
161 uint32_t *key_mem,
162 const uint8_t *n, size_t n_len,
163 const uint8_t *d, size_t d_len);
164
190 uint32_t *key_mem,
191 const uint8_t *p, size_t p_len,
192 const uint8_t *q, size_t q_len,
193 const uint8_t *dp, size_t dp_len,
194 const uint8_t *dq, size_t dq_len,
195 const uint8_t *qinv, size_t qi_len);
223 uint8_t *c, size_t c_len,
224 const uint8_t *m, size_t m_len,
225 const ocrypto_rsa_pub_key *pk,
226 uint32_t *mem);
227
246 uint8_t *m, size_t m_len,
247 const uint8_t *c, size_t c_len,
248 const ocrypto_rsa_key *key,
249 uint32_t *mem);
250
269 uint8_t *m, size_t m_len,
270 const uint8_t *c, size_t c_len,
271 const ocrypto_rsa_crt_key *key,
272 uint32_t *mem);
276#ifdef __cplusplus
277}
278#endif
279
280#endif
281
int ocrypto_rsa_init_pub_key(ocrypto_rsa_pub_key *key, uint32_t *key_mem, const uint8_t *n, size_t n_len, uint32_t e)
int ocrypto_rsa_init_crt_key(ocrypto_rsa_crt_key *key, uint32_t *key_mem, const uint8_t *p, size_t p_len, const uint8_t *q, size_t q_len, const uint8_t *dp, size_t dp_len, const uint8_t *dq, size_t dq_len, const uint8_t *qinv, size_t qi_len)
int ocrypto_rsa_init_key(ocrypto_rsa_key *key, uint32_t *key_mem, const uint8_t *n, size_t n_len, const uint8_t *d, size_t d_len)
int ocrypto_rsa_crt_exp(uint8_t *m, size_t m_len, const uint8_t *c, size_t c_len, const ocrypto_rsa_crt_key *key, uint32_t *mem)
int ocrypto_rsa_pub_exp(uint8_t *c, size_t c_len, const uint8_t *m, size_t m_len, const ocrypto_rsa_pub_key *pk, uint32_t *mem)
int ocrypto_rsa_exp(uint8_t *m, size_t m_len, const uint8_t *c, size_t c_len, const ocrypto_rsa_key *key, uint32_t *mem)
Definition ocrypto_rsa_primitives.h:101
Definition ocrypto_rsa_primitives.h:90
Definition ocrypto_rsa_primitives.h:79