|
59 | 59 | #define WOLFPKCS11_NEED_RSA_RNG |
60 | 60 | #endif |
61 | 61 |
|
| 62 | +#if defined(WOLFPKCS11_TPM) && defined(WOLFSSL_MAXQ10XX_CRYPTO) |
| 63 | + #error "wolfTPM and MAXQ10XX are incompatable with each other." |
| 64 | +#endif |
| 65 | + |
62 | 66 | /* Helper to get size of struct field */ |
63 | 67 | #define FIELD_SIZE(type, field) (sizeof(((type *)0)->field)) |
64 | 68 |
|
@@ -3538,8 +3542,10 @@ static int wp11_Slot_Init(WP11_Slot* slot, int id) |
3538 | 3542 |
|
3539 | 3543 | ret = WP11_Lock_Init(&slot->lock); |
3540 | 3544 | if (ret == 0) { |
3541 | | - #ifdef WOLFPKCS11_TPM |
| 3545 | + #if defined(WOLFPKCS11_TPM) |
3542 | 3546 | ret = wp11_TpmInit(slot); |
| 3547 | + #elif defined (WOLFSSL_MAXQ10XX_CRYPTO) |
| 3548 | + slot->devId = MAXQ_DEVICE_ID; |
3543 | 3549 | #endif |
3544 | 3550 | /* Create the minimum number of unused sessions. */ |
3545 | 3551 | for (i = 0; ret == 0 && i < WP11_SESSION_CNT_MIN; i++) { |
@@ -3605,8 +3611,16 @@ int WP11_Library_Init(void) |
3605 | 3611 |
|
3606 | 3612 | if (libraryInitCount == 0) { |
3607 | 3613 | ret = WP11_Lock_Init(&globalLock); |
3608 | | - if (ret == 0) |
| 3614 | + if (ret == 0) { |
| 3615 | +#ifdef WOLFSSL_MAXQ10XX_CRYPTO |
| 3616 | + ret = wolfCrypt_Init(); |
| 3617 | + if (ret == 0) { |
| 3618 | + ret = wc_InitRng_ex(&globalRandom, NULL, MAXQ_DEVICE_ID); |
| 3619 | + } |
| 3620 | +#else |
3609 | 3621 | ret = wc_InitRng(&globalRandom); |
| 3622 | +#endif |
| 3623 | + } |
3610 | 3624 | for (i = 0; (ret == 0) && (i < slotCnt); i++) { |
3611 | 3625 | ret = wp11_Slot_Init(&slotList[i], i + 1); |
3612 | 3626 | } |
@@ -4725,7 +4739,7 @@ int WP11_Session_SetCbcParams(WP11_Session* session, unsigned char* iv, |
4725 | 4739 | WP11_Data* key; |
4726 | 4740 |
|
4727 | 4741 | /* AES object on session. */ |
4728 | | - ret = wc_AesInit(&cbc->aes, NULL, INVALID_DEVID); |
| 4742 | + ret = wc_AesInit(&cbc->aes, NULL, session->devId); |
4729 | 4743 | if (ret == 0) { |
4730 | 4744 | if (object->onToken) |
4731 | 4745 | WP11_Lock_LockRO(object->lock); |
@@ -7659,7 +7673,7 @@ int WP11_EC_Derive(unsigned char* point, word32 pointLen, unsigned char* key, |
7659 | 7673 | WC_RNG rng; |
7660 | 7674 | #endif |
7661 | 7675 |
|
7662 | | - ret = wc_ecc_init_ex(&pubKey, NULL, INVALID_DEVID); |
| 7676 | + ret = wc_ecc_init_ex(&pubKey, NULL, priv->slot->devId); |
7663 | 7677 | if (ret == 0) { |
7664 | 7678 | ret = wc_ecc_import_x963(point, pointLen, &pubKey); |
7665 | 7679 | } |
@@ -8280,7 +8294,7 @@ int WP11_AesGcm_Encrypt(unsigned char* plain, word32 plainSz, |
8280 | 8294 | word32 authTagSz = gcm->tagBits / 8; |
8281 | 8295 | unsigned char* authTag = enc + plainSz; |
8282 | 8296 |
|
8283 | | - ret = wc_AesInit(&aes, NULL, INVALID_DEVID); |
| 8297 | + ret = wc_AesInit(&aes, NULL, session->devId); |
8284 | 8298 | if (ret == 0) { |
8285 | 8299 | if (secret->onToken) |
8286 | 8300 | WP11_Lock_LockRO(secret->lock); |
@@ -8332,7 +8346,7 @@ int WP11_AesGcm_EncryptUpdate(unsigned char* plain, word32 plainSz, |
8332 | 8346 | word32 authTagSz = gcm->tagBits / 8; |
8333 | 8347 | unsigned char* authTag = gcm->authTag; |
8334 | 8348 |
|
8335 | | - ret = wc_AesInit(&aes, NULL, INVALID_DEVID); |
| 8349 | + ret = wc_AesInit(&aes, NULL, session->devId); |
8336 | 8350 | if (ret == 0) { |
8337 | 8351 | if (secret->onToken) |
8338 | 8352 | WP11_Lock_LockRO(secret->lock); |
@@ -8412,7 +8426,7 @@ int WP11_AesGcm_Decrypt(unsigned char* enc, word32 encSz, unsigned char* dec, |
8412 | 8426 | word32 authTagSz = gcm->tagBits / 8; |
8413 | 8427 | unsigned char* authTag = enc + encSz - authTagSz; |
8414 | 8428 |
|
8415 | | - ret = wc_AesInit(&aes, NULL, INVALID_DEVID); |
| 8429 | + ret = wc_AesInit(&aes, NULL, session->devId); |
8416 | 8430 | if (ret == 0) { |
8417 | 8431 | if (secret->onToken) { |
8418 | 8432 | WP11_Lock_LockRO(secret->lock); |
@@ -8737,7 +8751,7 @@ int WP11_Hmac_Init(CK_MECHANISM_TYPE mechanism, WP11_Object* secret, |
8737 | 8751 | if (ret == 0) |
8738 | 8752 | hmac->hmacSz = wc_HmacSizeByType(hashType); |
8739 | 8753 | if (ret == 0) |
8740 | | - ret = wc_HmacInit(&hmac->hmac, NULL, INVALID_DEVID); |
| 8754 | + ret = wc_HmacInit(&hmac->hmac, NULL, secret->slot->devId); |
8741 | 8755 | if (ret == 0) { |
8742 | 8756 | if (secret->onToken) |
8743 | 8757 | WP11_Lock_LockRO(secret->lock); |
|
0 commit comments