Skip to content

Commit 60de159

Browse files
authored
Merge pull request #7176 from danielinux/iotsafe-sha384
IoT-Safe sha384+sha512 support
2 parents 3db58af + 72e34a8 commit 60de159

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

doc/dox_comments/header_files/iotsafe.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ int wc_iotsafe_ecc_export_private_ex(ecc_key *key, byte *key_id, word16 id_size)
346346

347347
/*!
348348
\ingroup IoTSafe
349-
\brief Sign a pre-computed 256-bit HASH, using a private key previously stored, or pre-provisioned,
349+
\brief Sign a pre-computed HASH, using a private key previously stored, or pre-provisioned,
350350
in the IoT-Safe applet.
351351
352352
\param in pointer to the buffer containing the message hash to sign
@@ -367,7 +367,7 @@ int wc_iotsafe_ecc_sign_hash(byte *in, word32 inlen, byte *out, word32 *outlen,
367367

368368
/*!
369369
\ingroup IoTSafe
370-
\brief Sign a pre-computed 256-bit HASH, using a private key previously stored, or pre-provisioned,
370+
\brief Sign a pre-computed HASH, using a private key previously stored, or pre-provisioned,
371371
in the IoT-Safe applet. Equivalent to \ref wc_iotsafe_ecc_sign_hash "wc_iotsafe_ecc_sign_hash",
372372
except that it can be invoked with a key ID of two or more bytes.
373373
@@ -390,7 +390,7 @@ int wc_iotsafe_ecc_sign_hash_ex(byte *in, word32 inlen, byte *out, word32 *outle
390390

391391
/*!
392392
\ingroup IoTSafe
393-
\brief Verify an ECC signature against a pre-computed 256-bit HASH, using a public key previously stored, or pre-provisioned,
393+
\brief Verify an ECC signature against a pre-computed HASH, using a public key previously stored, or pre-provisioned,
394394
in the IoT-Safe applet. Result is written to res. 1 is valid, 0 is invalid.
395395
Note: Do not use the return value to test for valid. Only use res.
396396
@@ -412,7 +412,7 @@ int wc_iotsafe_ecc_verify_hash(byte *sig, word32 siglen, byte *hash, word32 hash
412412

413413
/*!
414414
\ingroup IoTSafe
415-
\brief Verify an ECC signature against a pre-computed 256-bit HASH, using a public key previously stored, or pre-provisioned,
415+
\brief Verify an ECC signature against a pre-computed HASH, using a public key previously stored, or pre-provisioned,
416416
in the IoT-Safe applet. Result is written to res. 1 is valid, 0 is invalid.
417417
Note: Do not use the return value to test for valid. Only use res.
418418
Equivalent to \ref wc_iotsafe_ecc_verify_hash "wc_iotsafe_ecc_verify_hash",

wolfcrypt/src/port/iotsafe/iotsafe.c

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -749,43 +749,37 @@ static int iotsafe_hkdf_extract(byte* prk, const byte* salt, word32 saltLen,
749749
int ret;
750750
char *resp;
751751
uint16_t hash_algo = 0;
752-
int len;
752+
int hash_len;
753753
uint16_t hash_algo_be = 0;
754754

755755
WOLFSSL_MSG("Enter iotsafe_hkdf_extract");
756-
switch (digest) {
757-
#ifndef NO_SHA256
756+
switch (digest) {
757+
#ifndef NO_SHA256
758758
case WC_SHA256:
759-
hash_algo = (uint16_t)1;
760-
if (ikmLen == 0) {
761-
len = WC_SHA256_DIGEST_SIZE;
762-
}
759+
hash_algo = (uint16_t)1;
760+
hash_len = WC_SHA256_DIGEST_SIZE;
763761
break;
764-
#endif
765-
#ifdef WOLFSSL_SHA384
762+
#endif
763+
#ifdef WOLFSSL_SHA384
766764
case WC_SHA384:
767-
hash_algo = (uint16_t)2;
768-
if (ikmLen == 0) {
769-
len = WC_SHA384_DIGEST_SIZE;
770-
}
765+
hash_algo = (uint16_t)2;
766+
hash_len = WC_SHA384_DIGEST_SIZE;
771767
break;
772-
#endif
773-
#ifdef WOLFSSL_TLS13_SHA512
768+
#endif
769+
#ifdef WOLFSSL_SHA512
774770
case WC_SHA512:
775-
hash_algo = (uint16_t)4;
776-
if (ikmLen == 0) {
777-
len = WC_SHA512_DIGEST_SIZE;
778-
}
771+
hash_algo = (uint16_t)4;
772+
hash_len = WC_SHA512_DIGEST_SIZE;
779773
break;
780-
#endif
774+
#endif
781775
default:
782776
return BAD_FUNC_ARG;
783777
break;
784-
}
778+
}
785779

786780
if (ikmLen == 0) {
787-
ikmLen = len;
788-
XMEMSET(ikm, 0, len);
781+
ikmLen = hash_len;
782+
XMEMSET(ikm, 0, hash_len);
789783
}
790784

791785
#ifdef DEBUG_IOTSAFE
@@ -812,14 +806,12 @@ static int iotsafe_hkdf_extract(byte* prk, const byte* salt, word32 saltLen,
812806
WOLFSSL_MSG("Unexpected reply from HKDF extract");
813807
ret = WC_HW_E;
814808
} else {
815-
816-
ret = hexbuffer_conv(resp, prk, 32);
809+
ret = hexbuffer_conv(resp, prk, hash_len);
817810
if (ret < 0)
818811
ret = WC_HW_E;
819812
else
820813
ret = 0;
821814
}
822-
823815
return ret;
824816
}
825817
#endif

0 commit comments

Comments
 (0)