Skip to content

Commit 478c063

Browse files
Merge pull request #7159 from dgarske/features_20240122
Add PK Callback CMake support. Document `wc_RsaDirect`
2 parents 3cbffd3 + fa87e22 commit 478c063

4 files changed

Lines changed: 57 additions & 21 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,13 +1753,15 @@ else()
17531753
list(APPEND WOLFSSL_DEFINITIONS "-DWC_NO_ASYNC_THREADING")
17541754
endif()
17551755

1756-
# TODO: - cryptodev
1757-
# - Session export
1756+
# TODO: - Session export
17581757

17591758
add_option("WOLFSSL_CRYPTOCB"
17601759
"Enable crypto callbacks (default: disabled)"
17611760
"no" "yes;no")
17621761

1762+
add_option("WOLFSSL_PKCALLBACKS"
1763+
"Enable public key callbacks (default: disabled)"
1764+
"no" "yes;no")
17631765

17641766
add_option("WOLFSSL_OLD_NAMES"
17651767
"Keep backwards compat with old names (default: enabled)"
@@ -1960,6 +1962,11 @@ if(WOLFSSL_CRYPTOCB)
19601962
list(APPEND WOLFSSL_DEFINITIONS "-DWOLF_CRYPTO_CB")
19611963
endif()
19621964

1965+
# Public Key Callbacks
1966+
if(WOLFSSL_PKCALLBACKS)
1967+
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_PK_CALLBACKS")
1968+
endif()
1969+
19631970
if(WOLFSSL_OCSPSTAPLING)
19641971
list(APPEND WOLFSSL_DEFINITIONS "-DHAVE_CERTIFICATE_STATUS_REQUEST" "-DHAVE_TLS_EXTENSIONS")
19651972
override_cache(WOLFSSL_OCSP "yes")

doc/dox_comments/header_files-ja/rsa.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// error initializing RSA key
1414
}
1515
\endcode
16-
\sa wc_RsaInitCavium
1716
\sa wc_FreeRsaKey
1817
\sa wc_RsaSetRNG
1918
*/
@@ -47,7 +46,6 @@ int wc_InitRsaKey(RsaKey* key, void* heap);
4746
}
4847
\endcode
4948
\sa wc_InitRsaKey
50-
\sa wc_RsaInitCavium
5149
\sa wc_FreeRsaKey
5250
\sa wc_RsaSetRNG
5351
*/

doc/dox_comments/header_files/rsa.h

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
}
2828
\endcode
2929
30-
\sa wc_RsaInitCavium
3130
\sa wc_FreeRsaKey
3231
\sa wc_RsaSetRNG
3332
*/
@@ -77,7 +76,6 @@ int wc_InitRsaKey(RsaKey* key, void* heap);
7776
\endcode
7877
7978
\sa wc_InitRsaKey
80-
\sa wc_RsaInitCavium
8179
\sa wc_FreeRsaKey
8280
\sa wc_RsaSetRNG
8381
*/
@@ -133,6 +131,51 @@ int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng);
133131
*/
134132
int wc_FreeRsaKey(RsaKey* key);
135133

134+
/*!
135+
\ingroup RSA
136+
137+
\brief Function that does the RSA operation directly with no padding. The input
138+
size must match key size. Typically this is
139+
used when padding is already done on the RSA input.
140+
141+
\return size On successfully encryption the size of the encrypted buffer
142+
is returned
143+
\return RSA_BUFFER_E RSA buffer error, output too small or input too large
144+
145+
\param in buffer to do operation on
146+
\param inLen length of input buffer
147+
\param out buffer to hold results
148+
\param outSz gets set to size of result buffer. Should be passed in as length
149+
of out buffer. If the pointer "out" is null then outSz gets set to the
150+
expected buffer size needed and LENGTH_ONLY_E gets returned.
151+
\param key initialized RSA key to use for encrypt/decrypt
152+
\param type if using private or public key (RSA_PUBLIC_ENCRYPT,
153+
RSA_PUBLIC_DECRYPT, RSA_PRIVATE_ENCRYPT, RSA_PRIVATE_DECRYPT)
154+
\param rng initialized WC_RNG struct
155+
156+
_Example_
157+
\code
158+
int ret;
159+
WC_RNG rng;
160+
RsaKey key;
161+
byte in[256];
162+
byte out[256];
163+
word32 outSz = (word32)sizeof(out);
164+
165+
166+
ret = wc_RsaDirect(in, (word32)sizeof(in), out, &outSz, &key,
167+
RSA_PRIVATE_ENCRYPT, &rng);
168+
if (ret < 0) {
169+
//handle error
170+
}
171+
\endcode
172+
173+
\sa wc_RsaPublicEncrypt
174+
\sa wc_RsaPrivateDecrypt
175+
*/
176+
int wc_RsaDirect(byte* in, word32 inLen, byte* out, word32* outSz,
177+
RsaKey* key, int type, WC_RNG* rng);
178+
136179
/*!
137180
\ingroup RSA
138181

wolfcrypt/src/rsa.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,21 +2868,9 @@ static int wc_RsaFunctionAsync(const byte* in, word32 inLen, byte* out,
28682868
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_RSA */
28692869

28702870
#if defined(WC_RSA_DIRECT) || defined(WC_RSA_NO_PADDING)
2871-
/* Function that does the RSA operation directly with no padding.
2872-
*
2873-
* in buffer to do operation on
2874-
* inLen length of input buffer
2875-
* out buffer to hold results
2876-
* outSz gets set to size of result buffer. Should be passed in as length
2877-
* of out buffer. If the pointer "out" is null then outSz gets set to
2878-
* the expected buffer size needed and LENGTH_ONLY_E gets returned.
2879-
* key RSA key to use for encrypt/decrypt
2880-
* type if using private or public key {RSA_PUBLIC_ENCRYPT,
2881-
* RSA_PUBLIC_DECRYPT, RSA_PRIVATE_ENCRYPT, RSA_PRIVATE_DECRYPT}
2882-
* rng wolfSSL RNG to use if needed
2883-
*
2884-
* returns size of result on success
2885-
*/
2871+
/* Performs direct RSA computation without padding. The input and output must
2872+
* match the key size (ex: 2048-bits = 256 bytes). Returns the size of the
2873+
* output on success or negative value on failure. */
28862874
int wc_RsaDirect(byte* in, word32 inLen, byte* out, word32* outSz,
28872875
RsaKey* key, int type, WC_RNG* rng)
28882876
{

0 commit comments

Comments
 (0)