nrfxlib API 2.7.99
Loading...
Searching...
No Matches
ocrypto_rsa_primitives.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 - 2024 Nordic Semiconductor ASA
3 * Copyright (c) since 2013 Oberon microsystems AG
4 *
5 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
6 */
7
8
27#ifndef OCRYPTO_RSA_PRIMITIVES_H
28#define OCRYPTO_RSA_PRIMITIVES_H
29
30#include <stddef.h>
31#include <stdint.h>
32
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38
42#define OCRYPTO_RSA_PUB_KEY_SIZE(bits) ((bits)/32)
43
47#define OCRYPTO_RSA_KEY_SIZE(bits) ((bits)/32*2)
48
52#define OCRYPTO_RSA_CRT_KEY_SIZE(bits) ((bits)/32*7/2)
53
54
58#define OCRYPTO_RSA_PUB_MEM_SIZE(bits) ((bits)/32*11)
59
63#define OCRYPTO_RSA_MEM_SIZE(bits) ((bits)/32*26)
64
68#define OCRYPTO_RSA_CRT_MEM_SIZE(bits) ((bits)/32*14)
69
70
75typedef struct {
77 uint32_t *n;
78 uint32_t e;
79 int blocks; // block size of n
82
86typedef struct {
88 uint32_t *n;
89 uint32_t *d; // x^(e*d) mod n == x
90 int blocks; // block size of n
93
97typedef struct {
99 uint32_t *n;
100 uint32_t *p; // primes, p*q = n
101 uint32_t *q;
102 uint32_t *dp; // d mod (p-1)
103 uint32_t *dq; // d mod (q-1)
104 uint32_t *qinv; // 1/q mod p
105 int blocks; // block size of n
133 uint32_t *key_mem,
134 const uint8_t *n, size_t n_len,
135 uint32_t e);
136
155 ocrypto_rsa_key *key,
156 uint32_t *key_mem,
157 const uint8_t *n, size_t n_len,
158 const uint8_t *d, size_t d_len);
159
185 uint32_t *key_mem,
186 const uint8_t *p, size_t p_len,
187 const uint8_t *q, size_t q_len,
188 const uint8_t *dp, size_t dp_len,
189 const uint8_t *dq, size_t dq_len,
190 const uint8_t *qinv, size_t qi_len);
217 uint8_t *c, size_t c_len,
218 const uint8_t *m, size_t m_len,
219 const ocrypto_rsa_pub_key *pk,
220 uint32_t *mem);
221
240 uint8_t *m, size_t m_len,
241 const uint8_t *c, size_t c_len,
242 const ocrypto_rsa_key *key,
243 uint32_t *mem);
244
263 uint8_t *m, size_t m_len,
264 const uint8_t *c, size_t c_len,
265 const ocrypto_rsa_crt_key *key,
266 uint32_t *mem);
270#ifdef __cplusplus
271}
272#endif
273
274#endif
275
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:97
Definition: ocrypto_rsa_primitives.h:86
Definition: ocrypto_rsa_primitives.h:75