Skip to content

Commit ff1ca0d

Browse files
authored
Merge pull request #119 from SparkiDev/we_pbe
PBES: add PBKDF implementations that call into wolfCrypt
2 parents 432f777 + b26214d commit ff1ca0d

File tree

14 files changed

+984
-10
lines changed

14 files changed

+984
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ make
6363
sudo make install
6464
```
6565

66+
Add `--enable-pwdbased` to the configure command above if PKCS#12 is used in OpenSSL.
67+
6668
Remove `-DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_PSS_SALT_LEN_DISCOVER` and add `--enable-fips=v2` to the configure command above if building from a FIPS bundle and not the git repository.
6769

6870
### wolfEngine
@@ -83,8 +85,7 @@ make check
8385
```
8486

8587
* To build wolfEngine in single-threaded mode, add `--enable-singlethreaded` to the configure command.
86-
* AES-GCM is disabled by default because of the code changes required to OpenSSL. To enable it, add `--enable-aesgcm`.
87-
* AES-CCM is disabled by default for the same reason. To enable it, add `--enable-aesccm`.
88+
* To build wolfEngine with PBES support (used with PKCS #12), add `--enable-pbe`. Note: wolfSSL must have been configured with `--enable-pwdbased`.
8889
* To disable support for loading wolfEngine dynamically, add `--disable-dynamic-engine`.
8990
* To build a static version of wolfEngine, add `--enable-static`.
9091
* To use a custom user_settings.h file to override the defines produced by `./configure`, add `--enable-usersettings` and place a user_settings.h file with the defines you want in the include directory. See the root of the project for an example user_settings.h.

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ then
589589
fi
590590

591591

592+
AC_ARG_ENABLE([pbe],
593+
[AS_HELP_STRING([--enable-pbe],[Enable PBE (default: disabled)])],
594+
[ ENABLED_PBE=$enableval ],
595+
[ ENABLED_PBE=no ]
596+
)
597+
598+
if test "$ENABLED_PBE" = "yes"
599+
then
600+
AM_CFLAGS="$AM_CFLAGS -DWE_HAVE_PBE"
601+
fi
602+
603+
592604
# Check enable options
593605
if test "$ENABLED_DIGEST" = "yes"
594606
then
@@ -694,6 +706,7 @@ echo " * - P-224: $ENABLED_EC_P224"
694706
echo " * - P-256: $ENABLED_EC_P256"
695707
echo " * - P-384: $ENABLED_EC_P384"
696708
echo " * - P-521: $ENABLED_EC_P521"
709+
echo " * PBE: $ENABLED_PBE"
697710
echo ""
698711
echo "---"
699712

include/wolfengine/we_internal.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#if OPENSSL_VERSION_NUMBER >= 0x10101000L
5858
#include <openssl/cmac.h>
5959
#endif
60+
#include <openssl/pkcs12.h>
6061

6162
#include <wolfssl/options.h>
6263
#include <wolfssl/wolfcrypt/hash.h>
@@ -73,11 +74,23 @@
7374
#include <wolfssl/wolfcrypt/asn_public.h>
7475
#include <wolfssl/wolfcrypt/ecc.h>
7576
#include <wolfssl/wolfcrypt/random.h>
77+
#include <wolfssl/wolfcrypt/pwdbased.h>
7678

7779
#include <wolfengine/we_openssl_bc.h>
7880

7981
#include <wolfengine/we_logging.h>
8082

83+
#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
84+
/* Function is a printf style function. Pretend parameter is string literal.
85+
*
86+
* @param s [in] Index of string literal. Index from 1.
87+
* @param v [in] Index of first argument to check. 0 means don't.
88+
*/
89+
#define WE_PRINTF_FUNC(s, v) __attribute__((__format__ (__printf__, s, v)))
90+
#else
91+
#define WE_PRINTF_FUNC(s, v)
92+
#endif
93+
8194
#if defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION)
8295
/*
8396
* Global FIPS checks flag.
@@ -290,6 +303,14 @@ extern EVP_PKEY_METHOD *we_ec_p521_method;
290303
int we_init_ecc_meths(void);
291304
int we_init_ec_key_meths(void);
292305

306+
/*
307+
* PBE method
308+
*/
309+
310+
#ifdef WE_HAVE_PBE
311+
int we_init_pbe_keygen(void);
312+
#endif
313+
293314
int wolfengine_bind(ENGINE *e, const char *id);
294315

295316
#endif /* INTERNAL_H */

include/wolfengine/we_logging.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ enum wolfEngine_LogComponents {
8585
WE_LOG_PK = 0x0010, /* public key algorithms (RSA, ECC) */
8686
WE_LOG_KE = 0x0020, /* key agreement (DH, ECDH) */
8787
WE_LOG_ENGINE = 0x0040, /* all engine specific logs */
88+
WE_LOG_PBE = 0x0080, /* password base encryption algorithms */
8889

8990
/* log all compoenents */
9091
WE_LOG_COMPONENTS_ALL = (WE_LOG_RNG
@@ -93,7 +94,8 @@ enum wolfEngine_LogComponents {
9394
| WE_LOG_CIPHER
9495
| WE_LOG_PK
9596
| WE_LOG_KE
96-
| WE_LOG_ENGINE),
97+
| WE_LOG_ENGINE
98+
| WE_LOG_PBE),
9799

98100
/* default compoenents logged */
99101
WE_LOG_COMPONENTS_DEFAULT = WE_LOG_COMPONENTS_ALL

scripts/openssl-unit-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ build_wolfssl() {
290290
./configure LDFLAGS="-L$OPENSSL_SOURCE $WOLFENGINE_EXTRA_LDFLAGS" \
291291
CPPFLAGS="$WOLFENGINE_EXTRA_CPPFLAGS" \
292292
--with-openssl=$OPENSSL_SOURCE \
293+
$WOLFENGINE_EXTRA_OPTS \
293294
--enable-debug 2>&1 | tee -a $LOGFILE
294295
if [ "${PIPESTATUS[0]}" != 0 ]; then
295296
printf "config failed\n"

src/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ libwolfengine_la_SOURCES += src/we_internal.c
1717
libwolfengine_la_SOURCES += src/we_logging.c
1818
libwolfengine_la_SOURCES += src/we_mac.c
1919
libwolfengine_la_SOURCES += src/we_openssl_bc.c
20+
libwolfengine_la_SOURCES += src/we_pbe.c
2021
libwolfengine_la_SOURCES += src/we_random.c
2122
libwolfengine_la_SOURCES += src/we_rsa.c
2223
libwolfengine_la_SOURCES += src/we_tls_prf.c

src/we_internal.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,11 @@ static int wolfengine_init(ENGINE *e)
919919
}
920920
#endif
921921
#endif
922+
#ifdef WE_HAVE_PBE
923+
if (ret == 1) {
924+
we_init_pbe_keygen();
925+
}
926+
#endif
922927

923928
#endif
924929

src/we_logging.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static void wolfengine_log(const int logLevel, const int component,
182182
* @param fmt [IN] Log message format string.
183183
* @param vargs [IN] Variable arguments, used with format string, fmt.
184184
*/
185+
WE_PRINTF_FUNC(3, 0)
185186
static void wolfengine_msg_internal(int component, int logLevel,
186187
const char* fmt, va_list vlist)
187188
{
@@ -200,6 +201,7 @@ static void wolfengine_msg_internal(int component, int logLevel,
200201
* @param fmt [IN] Log message format string.
201202
* @param vargs [IN] Variable arguments, used with format string, fmt.
202203
*/
204+
WE_PRINTF_FUNC(2, 3)
203205
void WOLFENGINE_MSG(int component, const char* fmt, ...)
204206
{
205207
va_list vlist;
@@ -215,6 +217,7 @@ void WOLFENGINE_MSG(int component, const char* fmt, ...)
215217
* @param fmt [IN] Log message format string.
216218
* @param vargs [IN] Variable arguments, used with format string, fmt.
217219
*/
220+
WE_PRINTF_FUNC(2, 3)
218221
void WOLFENGINE_MSG_VERBOSE(int component, const char* fmt, ...)
219222
{
220223
va_list vlist;

0 commit comments

Comments
 (0)