13
13
14
14
#define SET_FST_ERROR (__code ) if (errorCodeOut) *errorCodeOut = ErrorCode::__code
15
15
16
+ static_assert (sizeof (NCrypto::AesIv) == 16 ); // make sure IV is actually 16 bytes
17
+
16
18
class FSTDataSource
17
19
{
18
20
public:
@@ -868,7 +870,7 @@ static_assert(sizeof(FSTHashedBlock) == BLOCK_SIZE);
868
870
struct FSTCachedRawBlock
869
871
{
870
872
FSTRawBlock blockData;
871
- uint8 ivForNextBlock[ 16 ] ;
873
+ NCrypto::AesIv ivForNextBlock;
872
874
uint64 lastAccess;
873
875
};
874
876
@@ -919,13 +921,13 @@ void FSTVolume::TrimCacheIfRequired(FSTCachedRawBlock** droppedRawBlock, FSTCach
919
921
}
920
922
}
921
923
922
- void FSTVolume::DetermineUnhashedBlockIV (uint32 clusterIndex, uint32 blockIndex, uint8 ivOut[ 16 ] )
924
+ void FSTVolume::DetermineUnhashedBlockIV (uint32 clusterIndex, uint32 blockIndex, NCrypto::AesIv& ivOut)
923
925
{
924
- memset ( ivOut, 0 , sizeof (ivOut)) ;
926
+ ivOut = {} ;
925
927
if (blockIndex == 0 )
926
928
{
927
- ivOut[0 ] = (uint8)(clusterIndex >> 8 );
928
- ivOut[1 ] = (uint8)(clusterIndex >> 0 );
929
+ ivOut. iv [0 ] = (uint8)(clusterIndex >> 8 );
930
+ ivOut. iv [1 ] = (uint8)(clusterIndex >> 0 );
929
931
}
930
932
else
931
933
{
@@ -936,20 +938,20 @@ void FSTVolume::DetermineUnhashedBlockIV(uint32 clusterIndex, uint32 blockIndex,
936
938
auto itr = m_cacheDecryptedRawBlocks.find (cacheBlockId);
937
939
if (itr != m_cacheDecryptedRawBlocks.end ())
938
940
{
939
- memcpy ( ivOut, itr->second ->ivForNextBlock , 16 ) ;
941
+ ivOut = itr->second ->ivForNextBlock ;
940
942
}
941
943
else
942
944
{
943
- cemu_assert (m_sectorSize >= 16 );
945
+ cemu_assert (m_sectorSize >= NCrypto::AesIv::SIZE );
944
946
uint64 clusterOffset = (uint64)m_cluster[clusterIndex].offset * m_sectorSize;
945
- uint8 prevIV[ 16 ] ;
946
- if (m_dataSource->readData (clusterIndex, clusterOffset, blockIndex * m_sectorSize - 16 , prevIV, 16 ) != 16 )
947
+ NCrypto::AesIv prevIV{} ;
948
+ if (m_dataSource->readData (clusterIndex, clusterOffset, blockIndex * m_sectorSize - NCrypto::AesIv::SIZE , prevIV. iv , NCrypto::AesIv::SIZE ) != NCrypto::AesIv::SIZE )
947
949
{
948
950
cemuLog_log (LogType::Force, " Failed to read IV for raw FST block" );
949
951
m_detectedCorruption = true ;
950
952
return ;
951
953
}
952
- memcpy ( ivOut, prevIV, 16 ) ;
954
+ ivOut = prevIV ;
953
955
}
954
956
}
955
957
}
@@ -984,10 +986,10 @@ FSTCachedRawBlock* FSTVolume::GetDecryptedRawBlock(uint32 clusterIndex, uint32 b
984
986
return nullptr ;
985
987
}
986
988
// decrypt hash data
987
- uint8 iv[ 16 ] {};
989
+ NCrypto::AesIv iv{};
988
990
DetermineUnhashedBlockIV (clusterIndex, blockIndex, iv);
989
- memcpy (block->ivForNextBlock , block->blockData .rawData .data () + m_sectorSize - 16 , 16 );
990
- AES128_CBC_decrypt (block->blockData .rawData .data (), block->blockData .rawData .data (), m_sectorSize, m_partitionTitlekey.b , iv);
991
+ std::copy (block->blockData . rawData . data () + m_sectorSize - NCrypto::AesIv::SIZE , block->blockData .rawData .data () + m_sectorSize, block-> ivForNextBlock . iv );
992
+ AES128_CBC_decrypt (block->blockData .rawData .data (), block->blockData .rawData .data (), m_sectorSize, m_partitionTitlekey.b , iv. iv );
991
993
// if this is the next block, then hash it
992
994
if (cluster.hasContentHash )
993
995
{
0 commit comments