@@ -1622,11 +1622,14 @@ void psa_crypto_generator_operations(void)
1622
1622
1623
1623
case PSA_GENERATOR_ABORT : {
1624
1624
status = psa_generator_abort (msg .rhandle );
1625
+ mbedtls_free (msg .rhandle );
1626
+ psa_set_rhandle (msg .handle , NULL );
1625
1627
break ;
1626
1628
}
1627
1629
1628
1630
case PSA_KEY_DERIVATION : {
1629
1631
uint8_t * salt = NULL ;
1632
+ uint8_t * label = NULL ;
1630
1633
1631
1634
if (!psa_crypto_access_control_is_handle_permitted (psa_crypto_ipc .handle ,
1632
1635
msg .client_id )) {
@@ -1635,39 +1638,36 @@ void psa_crypto_generator_operations(void)
1635
1638
}
1636
1639
1637
1640
salt = mbedtls_calloc (1 , msg .in_size [1 ]);
1638
- if (salt == NULL ) {
1641
+ label = mbedtls_calloc (1 , msg .in_size [2 ]);
1642
+ if (salt == NULL || label == NULL ) {
1639
1643
status = PSA_ERROR_INSUFFICIENT_MEMORY ;
1640
- break ;
1641
- }
1644
+ } else {
1645
+ bytes_read = psa_read (msg .handle , 1 , salt , msg .in_size [1 ]);
1646
+ if (bytes_read != msg .in_size [1 ]) {
1647
+ SPM_PANIC ("SPM read length mismatch" );
1648
+ }
1642
1649
1643
- bytes_read = psa_read (msg .handle , 1 , salt ,
1644
- msg .in_size [1 ]);
1645
- if (bytes_read != msg .in_size [1 ]) {
1646
- SPM_PANIC ("SPM read length mismatch" );
1647
- }
1650
+ bytes_read = psa_read (msg .handle , 2 , label , msg .in_size [2 ]);
1651
+ if (bytes_read != msg .in_size [2 ]) {
1652
+ SPM_PANIC ("SPM read length mismatch" );
1653
+ }
1648
1654
1649
- uint8_t * label = mbedtls_calloc (1 , msg .in_size [2 ]);
1650
- if (label == NULL ) {
1651
- status = PSA_ERROR_INSUFFICIENT_MEMORY ;
1652
- mbedtls_free (salt );
1653
- break ;
1654
- }
1655
+ status = psa_key_derivation (msg .rhandle , psa_crypto_ipc .handle ,
1656
+ psa_crypto_ipc .alg ,
1657
+ salt ,
1658
+ msg .in_size [1 ],//salt length
1659
+ label ,
1660
+ msg .in_size [2 ],//label length
1661
+ psa_crypto_ipc .capacity );
1655
1662
1656
- bytes_read = psa_read (msg .handle , 2 , label ,
1657
- msg .in_size [2 ]);
1658
- if (bytes_read != msg .in_size [2 ]) {
1659
- SPM_PANIC ("SPM read length mismatch" );
1660
1663
}
1661
1664
1662
- status = psa_key_derivation (msg .rhandle , psa_crypto_ipc .handle ,
1663
- psa_crypto_ipc .alg ,
1664
- salt ,
1665
- msg .in_size [1 ],//salt length
1666
- label ,
1667
- msg .in_size [2 ],//label length
1668
- psa_crypto_ipc .capacity );
1669
- mbedtls_free (label );
1670
1665
mbedtls_free (salt );
1666
+ mbedtls_free (label );
1667
+ if (status != PSA_SUCCESS ) {
1668
+ mbedtls_free (msg .rhandle );
1669
+ psa_set_rhandle (msg .handle , NULL );
1670
+ }
1671
1671
1672
1672
break ;
1673
1673
}
@@ -1684,20 +1684,24 @@ void psa_crypto_generator_operations(void)
1684
1684
private_key = mbedtls_calloc (1 , msg .in_size [1 ]);
1685
1685
if (private_key == NULL ) {
1686
1686
status = PSA_ERROR_INSUFFICIENT_MEMORY ;
1687
- break ;
1687
+ } else {
1688
+ bytes_read = psa_read (msg .handle , 1 , private_key , msg .in_size [1 ]);
1689
+ if (bytes_read != msg .in_size [1 ]) {
1690
+ SPM_PANIC ("SPM read length mismatch" );
1691
+ }
1692
+
1693
+ status = psa_key_agreement (msg .rhandle , psa_crypto_ipc .handle ,
1694
+ private_key ,
1695
+ msg .in_size [1 ],//private_key length
1696
+ psa_crypto_ipc .alg );
1697
+ mbedtls_free (private_key );
1688
1698
}
1689
1699
1690
- bytes_read = psa_read (msg .handle , 1 , private_key ,
1691
- msg .in_size [1 ]);
1692
- if (bytes_read != msg .in_size [1 ]) {
1693
- SPM_PANIC ("SPM read length mismatch" );
1700
+ if (status != PSA_SUCCESS ) {
1701
+ mbedtls_free (msg .rhandle );
1702
+ psa_set_rhandle (msg .handle , NULL );
1694
1703
}
1695
1704
1696
- status = psa_key_agreement (msg .rhandle , psa_crypto_ipc .handle ,
1697
- private_key ,
1698
- msg .in_size [1 ],//private_key length
1699
- psa_crypto_ipc .alg );
1700
- mbedtls_free (private_key );
1701
1705
break ;
1702
1706
}
1703
1707
@@ -1710,8 +1714,8 @@ void psa_crypto_generator_operations(void)
1710
1714
break ;
1711
1715
}
1712
1716
case PSA_IPC_DISCONNECT : {
1713
- psa_generator_abort (msg .rhandle );
1714
1717
if (msg .rhandle != NULL ) {
1718
+ psa_generator_abort (msg .rhandle );
1715
1719
mbedtls_free (msg .rhandle );
1716
1720
}
1717
1721
0 commit comments