Skip to content
Permalink
Browse files Browse the repository at this point in the history
Change signature generation to verify by default
  • Loading branch information
SparkiDev committed Nov 27, 2019
1 parent 7cb5fe5 commit 2387851
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions wolfcrypt/src/signature.c
Expand Up @@ -319,6 +319,16 @@ int wc_SignatureGenerateHash(
const byte* hash_data, word32 hash_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len, WC_RNG* rng)
{
return wc_SignatureGenerateHash_ex(hash_type, sig_type, hash_data, hash_len,
sig, sig_len, key, key_len, rng, 1);
}

int wc_SignatureGenerateHash_ex(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* hash_data, word32 hash_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len, WC_RNG* rng, int verify)
{
int ret;

Expand Down Expand Up @@ -393,6 +403,11 @@ int wc_SignatureGenerateHash(
break;
}

if (ret == 0 && verify) {
ret = wc_SignatureVerifyHash(hash_type, sig_type, hash_data, hash_len,
sig, *sig_len, key, key_len);
}

return ret;
}

Expand All @@ -401,6 +416,16 @@ int wc_SignatureGenerate(
const byte* data, word32 data_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len, WC_RNG* rng)
{
return wc_SignatureGenerate_ex(hash_type, sig_type, data, data_len, sig,
sig_len, key, key_len, rng, 1);
}

int wc_SignatureGenerate_ex(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* data, word32 data_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len, WC_RNG* rng, int verify)
{
int ret;
word32 hash_len, hash_enc_len;
Expand Down Expand Up @@ -467,6 +492,11 @@ int wc_SignatureGenerate(
}
}

if (ret == 0 && verify) {
ret = wc_SignatureVerifyHash(hash_type, sig_type, hash_data,
hash_enc_len, sig, *sig_len, key, key_len);
}

#ifdef WOLFSSL_SMALL_STACK
XFREE(hash_data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
Expand Down
11 changes: 11 additions & 0 deletions wolfssl/wolfcrypt/signature.h
Expand Up @@ -62,12 +62,23 @@ WOLFSSL_API int wc_SignatureGenerateHash(
const byte* hash_data, word32 hash_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len, WC_RNG* rng);
WOLFSSL_API int wc_SignatureGenerateHash_ex(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* hash_data, word32 hash_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len, WC_RNG* rng, int verify);
WOLFSSL_API int wc_SignatureGenerate(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* data, word32 data_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len,
WC_RNG* rng);
WOLFSSL_API int wc_SignatureGenerate_ex(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* data, word32 data_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len,
WC_RNG* rng, int verify);

#ifdef __cplusplus
} /* extern "C" */
Expand Down

0 comments on commit 2387851

Please sign in to comment.