Skip to content

Commit

Permalink
Merge pull request #54 from bandi13/fixBuilds
Browse files Browse the repository at this point in the history
Fix builds
  • Loading branch information
douzzer authored Oct 30, 2024
2 parents 78b0165 + e2dcfaa commit 28ed8f3
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 32 deletions.
4 changes: 4 additions & 0 deletions include/wolfprovider/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ enum wc_HashType wp_nid_to_wc_hash_type(int nid);
int wp_name_to_wc_mgf(OSSL_LIB_CTX* libCtx, const char* name,
const char* propQ);
int wp_mgf1_from_hash(int nid);
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst);
#else
int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst, enum wc_HashType hashType);
#endif

int wp_cipher_from_params(const OSSL_PARAM params[], int* cipher,
const char** cipherName);
Expand Down
16 changes: 16 additions & 0 deletions scripts/utils-general.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ if [ "$UTILS_GENERAL_LOADED" != "yes" ]; then # only set once

export UTILS_GENERAL_LOADED=yes
fi

check_folder_age() {
folderA=$1
folderB=$2
folderA_age=$(find "$folderA" -type f -printf '%T@' | sort -n | tail -n 1)
folderB_age=$(find "$folderB" -type f -printf '%T@' | sort -n | tail -n 1)

if awk "BEGIN {exit !($folderA_age > $folderB_age)}"; then
echo 1
elif awk "BEGIN {exit !($folderA_age < $folderB_age)}"; then
echo -1
else
echo 0
fi
}

2 changes: 1 addition & 1 deletion scripts/utils-openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source ${SCRIPT_DIR}/utils-general.sh

OPENSSL_GIT="https://github.com/openssl/openssl.git"
OPENSSL_TAG=${OPENSSL_TAG:-"openssl-3.0.0"}
OPENSSL_TAG=${OPENSSL_TAG:-"openssl-3.2.0"}
OPENSSL_SOURCE_DIR=${SCRIPT_DIR}/../openssl-source
OPENSSL_INSTALL_DIR=${SCRIPT_DIR}/../openssl-install

Expand Down
2 changes: 1 addition & 1 deletion scripts/utils-wolfprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ install_wolfprov() {
init_wolfssl
printf "LD_LIBRARY_PATH: $LD_LIBRARY_PATH\n"

if [ ! -d ${WOLFPROV_INSTALL_DIR} ]; then
if [ ! -d ${WOLFPROV_INSTALL_DIR} ] || [ $(check_folder_age "${WOLFPROV_INSTALL_DIR}" "${WOLFSSL_INSTALL_DIR}") -lt 0 ] || [ $(check_folder_age "${WOLFPROV_INSTALL_DIR}" "${OPENSSL_INSTALL_DIR}") -lt 0 ]; then
printf "\tConfigure wolfProvider ... "
if [ ! -e "${WOLFPROV_SOURCE_DIR}/configure" ]; then
./autogen.sh >>$LOG_FILE 2>&1
Expand Down
78 changes: 68 additions & 10 deletions src/wp_ecdsa_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ typedef struct wp_EcdsaSigCtx {

/** wolfSSL hash object. */
wc_HashAlg hash;
#if LIBWOLFSSL_VERSION_HEX < 0x05007004
/** Hash algorithm to use on data to be signed. */
enum wc_HashType hashType;
#endif

/** Property query string. */
char* propQuery;
Expand Down Expand Up @@ -140,16 +142,21 @@ static wp_EcdsaSigCtx* wp_ecdsa_dupctx(wp_EcdsaSigCtx* srcCtx)
ok = 0;
}

if (ok && (!wp_hash_copy(&srcCtx->hash, &dstCtx->hash,
srcCtx->hashType))) {
if (ok && (!wp_hash_copy(&srcCtx->hash, &dstCtx->hash
#if LIBWOLFSSL_VERSION_HEX < 0x05007004
,srcCtx->hashType
#endif
))) {
ok = 0;
}
if (ok && (!wp_ecc_up_ref(srcCtx->ecc))) {
ok = 0;
}
if (ok) {
dstCtx->ecc = srcCtx->ecc;
#if LIBWOLFSSL_VERSION_HEX < 0x05007004
dstCtx->hashType = srcCtx->hashType;
#endif
dstCtx->op = srcCtx->op;
XMEMCPY(dstCtx->mdName, srcCtx->mdName, sizeof(srcCtx->mdName));
}
Expand Down Expand Up @@ -249,8 +256,14 @@ static int wp_ecdsa_sign(wp_EcdsaSigCtx *ctx, unsigned char *sig,
*sigLen = wc_ecc_sig_size(wp_ecc_get_key(ctx->ecc));
}
else {
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
if ((ctx->hash.type != WC_HASH_TYPE_NONE) &&
(tbsLen != (size_t)wc_HashGetDigestSize(ctx->hash.type)))
#else
if ((ctx->hashType != WC_HASH_TYPE_NONE) &&
(tbsLen != (size_t)wc_HashGetDigestSize(ctx->hashType))) {
(tbsLen != (size_t)wc_HashGetDigestSize(ctx->hashType)))
#endif
{
ok = 0;
}
else if ((ok = wp_ecc_check_usage(ctx->ecc))) {
Expand Down Expand Up @@ -410,17 +423,33 @@ static int wp_ecdsa_setup_md(wp_EcdsaSigCtx *ctx, const char *mdName,
if (mdName != NULL) {
int rc;

#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
ctx->hash.type = wp_name_to_wc_hash_type(ctx->libCtx, mdName, mdProps);
if ((ctx->hash.type == WC_HASH_TYPE_NONE) ||
(ctx->hash.type == WC_HASH_TYPE_MD5))
#else
ctx->hashType = wp_name_to_wc_hash_type(ctx->libCtx, mdName, mdProps);
if ((ctx->hashType == WC_HASH_TYPE_NONE) ||
(ctx->hashType == WC_HASH_TYPE_MD5)) {
(ctx->hashType == WC_HASH_TYPE_MD5))
#endif
{
ok = 0;
}
if ((ctx->hashType == WC_HASH_TYPE_SHA) && (op == EVP_PKEY_OP_SIGN)) {
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
if ((ctx->hash.type == WC_HASH_TYPE_SHA) && (op == EVP_PKEY_OP_SIGN))
#else
if ((ctx->hashType == WC_HASH_TYPE_SHA) && (op == EVP_PKEY_OP_SIGN))
#endif
{
ok = 0;
}

if (ok) {
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_HashInit_ex(&ctx->hash, ctx->hash.type, NULL, INVALID_DEVID);
#else
rc = wc_HashInit_ex(&ctx->hash, ctx->hashType, NULL, INVALID_DEVID);
#endif
if (rc != 0) {
ok = 0;
}
Expand Down Expand Up @@ -475,7 +504,13 @@ static int wp_ecdsa_digest_signverify_update(wp_EcdsaSigCtx *ctx,
const unsigned char *data, size_t dataLen)
{
int ok = 1;
int rc = wc_HashUpdate(&ctx->hash, ctx->hashType, data, (word32)dataLen);
int rc = wc_HashUpdate(&ctx->hash,
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
ctx->hash.type,
#else
ctx->hashType,
#endif
data, (word32)dataLen);
if (rc != 0) {
ok = 0;
}
Expand Down Expand Up @@ -533,15 +568,27 @@ static int wp_ecdsa_digest_sign_final(wp_EcdsaSigCtx *ctx, unsigned char *sig,
ok = 0;
}
else if (sig != NULL) {
int rc = wc_HashFinal(&ctx->hash, ctx->hashType, digest);
int rc = wc_HashFinal(&ctx->hash,
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
ctx->hash.type,
#else
ctx->hashType,
#endif
digest);
if (rc != 0) {
ok = 0;
}
}

if (ok) {
ok = wp_ecdsa_sign(ctx, sig, sigLen, sigSize, digest,
wc_HashGetDigestSize(ctx->hashType));
wc_HashGetDigestSize(
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
ctx->hash.type
#else
ctx->hashType
#endif
));
}

WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
Expand Down Expand Up @@ -594,15 +641,26 @@ static int wp_ecdsa_digest_verify_final(wp_EcdsaSigCtx *ctx, unsigned char *sig,
ok = 0;
}
else {
int rc = wc_HashFinal(&ctx->hash, ctx->hashType, digest);
int rc = wc_HashFinal(&ctx->hash,
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
ctx->hash.type,
#else
ctx->hashType,
#endif
digest);
if (rc != 0) {
ok = 0;
}
}

if (ok) {
ok = wp_ecdsa_verify(ctx,sig, sigLen, digest,
wc_HashGetDigestSize(ctx->hashType));
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
wc_HashGetDigestSize(ctx->hash.type)
#else
wc_HashGetDigestSize(ctx->hashType)
#endif
);
}

WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
Expand Down
12 changes: 10 additions & 2 deletions src/wp_ecx_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ typedef struct wp_EcxSigCtx {

/** wolfSSL hash object. */
wc_HashAlg hash;
#if LIBWOLFSSL_VERSION_HEX < 0x05007004
/** Hash algorithm to use on data to be signed. */
enum wc_HashType hashType;
#endif

/** Property query string. */
char* propQuery;
Expand Down Expand Up @@ -135,16 +137,22 @@ static wp_EcxSigCtx* wp_ecx_dupctx(wp_EcxSigCtx* srcCtx)
ok = 0;
}

if (ok && (!wp_hash_copy(&srcCtx->hash, &dstCtx->hash,
srcCtx->hashType))) {
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
if (ok && (!wp_hash_copy(&srcCtx->hash, &dstCtx->hash)))
#else
if (ok && (!wp_hash_copy(&srcCtx->hash, &dstCtx->hash, srcCtx->hashType)))
#endif
{
ok = 0;
}
if (ok && (!wp_ecx_up_ref(srcCtx->ecx))) {
ok = 0;
}
if (ok) {
dstCtx->ecx = srcCtx->ecx;
#if LIBWOLFSSL_VERSION_HEX < 0x05007004
dstCtx->hashType = srcCtx->hashType;
#endif
dstCtx->op = srcCtx->op;
XMEMCPY(dstCtx->mdName, srcCtx->mdName, sizeof(srcCtx->mdName));
}
Expand Down
63 changes: 62 additions & 1 deletion src/wp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,62 +248,103 @@ int wp_mgf1_from_hash(int nid)
* @return 1 on success.
* @return 0 on failure.
*/
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst)
#else
int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst, enum wc_HashType hashType)
#endif
{
int ok = 1;
int rc = 0;

switch (hashType) {
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
switch (src->type)
#else
switch (hashType)
#endif
{
case WC_HASH_TYPE_MD5:
#ifdef WP_HAVE_MD5
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Md5Copy(&src->alg.md5, &dst->alg.md5);
#else
rc = wc_Md5Copy(&src->md5, &dst->md5);
#endif
#else
ok = 0;
#endif
break;
case WC_HASH_TYPE_SHA:
#ifdef WP_HAVE_SHA1
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_ShaCopy(&src->alg.sha, &dst->alg.sha);
#else
rc = wc_ShaCopy(&src->sha, &dst->sha);
#endif
#else
ok = 0;
#endif
break;
case WC_HASH_TYPE_SHA224:
#ifdef WP_HAVE_SHA224
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha224Copy(&src->alg.sha224, &dst->alg.sha224);
#else
rc = wc_Sha224Copy(&src->sha224, &dst->sha224);
#endif
#else
ok = 0;
#endif
break;
case WC_HASH_TYPE_SHA256:
#ifdef WP_HAVE_SHA256
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha256Copy(&src->alg.sha256, &dst->alg.sha256);
#else
rc = wc_Sha256Copy(&src->sha256, &dst->sha256);
#endif
#else
ok = 0;
#endif
break;
case WC_HASH_TYPE_SHA384:
#ifdef WP_HAVE_SHA384
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha384Copy(&src->alg.sha384, &dst->alg.sha384);
#else
rc = wc_Sha384Copy(&src->sha384, &dst->sha384);
#endif
#else
ok = 0;
#endif
break;
#ifdef WP_HAVE_SHA512
case WC_HASH_TYPE_SHA512:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha512Copy(&src->alg.sha512, &dst->alg.sha512);
#else
rc = wc_Sha512Copy(&src->sha512, &dst->sha512);
#endif
break;
#if LIBWOLFSSL_VERSION_HEX >= 0x05000000
#if !defined(WOLFSSL_NOSHA512_224) && !defined(HAVE_FIPS) && \
!defined(SELF_TEST)
case WC_HASH_TYPE_SHA512_224:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha512_224Copy(&src->alg.sha512, &dst->alg.sha512);
#else
rc = wc_Sha512_224Copy(&src->sha512, &dst->sha512);
#endif
break;
#endif /* !WOLFSSL_NOSHA512_224 */
#if !defined(WOLFSSL_NOSHA512_256) && !defined(HAVE_FIPS) && \
!defined(SELF_TEST)
case WC_HASH_TYPE_SHA512_256:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha512_256Copy(&src->alg.sha512, &dst->alg.sha512);
#else
rc = wc_Sha512_256Copy(&src->sha512, &dst->sha512);
#endif
break;
#endif /* !WOLFSSL_NOSHA512_256 */
#endif /* LIBWOLFSSL_VERSION_HEX >= 0x05000000 */
Expand All @@ -316,16 +357,32 @@ int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst, enum wc_HashType hashType)
#endif /* WP_HAVE_SHA512 */
#ifdef WP_HAVE_SHA3
case WC_HASH_TYPE_SHA3_224:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha3_224_Copy(&src->alg.sha3, &dst->alg.sha3);
#else
rc = wc_Sha3_224_Copy(&src->sha3, &dst->sha3);
#endif
break;
case WC_HASH_TYPE_SHA3_256:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha3_256_Copy(&src->alg.sha3, &dst->alg.sha3);
#else
rc = wc_Sha3_256_Copy(&src->sha3, &dst->sha3);
#endif
break;
case WC_HASH_TYPE_SHA3_384:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha3_384_Copy(&src->alg.sha3, &dst->alg.sha3);
#else
rc = wc_Sha3_384_Copy(&src->sha3, &dst->sha3);
#endif
break;
case WC_HASH_TYPE_SHA3_512:
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
rc = wc_Sha3_512_Copy(&src->alg.sha3, &dst->alg.sha3);
#else
rc = wc_Sha3_512_Copy(&src->sha3, &dst->sha3);
#endif
break;
#else
case WC_HASH_TYPE_SHA3_224:
Expand Down Expand Up @@ -355,6 +412,10 @@ int wp_hash_copy(wc_HashAlg* src, wc_HashAlg* dst, enum wc_HashType hashType)
}
if (rc != 0) {
ok = 0;
#if LIBWOLFSSL_VERSION_HEX >= 0x05007004
} else {
dst->type = src->type;
#endif
}

WOLFPROV_LEAVE(WP_LOG_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
Expand Down
Loading

0 comments on commit 28ed8f3

Please sign in to comment.