summaryrefslogtreecommitdiff
path: root/source/slang
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2022-12-02 16:34:53 +0100
committerGitHub <noreply@github.com>2022-12-02 16:34:53 +0100
commite9b7c66a541636e72659fbfcc9a3f20a85f2bee8 (patch)
treeb65942799ff6267ebe29c8b64056819461621be7 /source/slang
parent92ae4949fe1af28ef31331fd4116c8111c057420 (diff)
Cleanup crypto utilities (#2549)
* Consolidate crypto functions into single module * Migrate rest of code to new crypto module * Fix name conflict
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-compiler.cpp4
-rwxr-xr-xsource/slang/slang-compiler.h52
-rw-r--r--source/slang/slang.cpp45
3 files changed, 49 insertions, 52 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index a5e2003c2..ce0ae4085 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -224,7 +224,7 @@ namespace Slang
}
void EntryPoint::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt entryPointIndex)
{
// CompositeComponentType will have already hashed the relevant entry point's name
@@ -302,7 +302,7 @@ namespace Slang
}
void TypeConformance::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt entryPointIndex)
{
SLANG_UNUSED(entryPointIndex);
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 07e611355..692fefbe2 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -3,7 +3,7 @@
#include "../core/slang-basic.h"
#include "../core/slang-shared-library.h"
-#include "../core/slang-digest-builder.h"
+#include "../core/slang-crypto.h"
#include "../compiler-core/slang-downstream-compiler.h"
#include "../compiler-core/slang-downstream-compiler-util.h"
@@ -297,8 +297,8 @@ namespace Slang
SLANG_NO_THROW void SLANG_MCALL computeDependencyBasedHash(
SlangInt entryPointIndex,
SlangInt targetIndex,
- slang::Digest* outHash) SLANG_OVERRIDE;
- SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE;
+ slang::IBlob** outHash) SLANG_OVERRIDE;
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::IBlob** outHash) SLANG_OVERRIDE;
/// Get the linkage (aka "session" in the public API) for this component type.
Linkage* getLinkage() { return m_linkage; }
@@ -310,13 +310,13 @@ namespace Slang
/// Update the hash builder with the dependencies for this component type.
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) = 0;
/// Update the hash builder with the source contents for this component type.
/// Module should be the only derived ComponentType class which has a meaningful
/// implementation; all others should do nothing.
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) = 0;
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) = 0;
/// Get the number of entry points linked into this component type.
virtual Index getEntryPointCount() = 0;
@@ -516,10 +516,10 @@ namespace Slang
List<RefPtr<ComponentType>> const& childComponents);
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override;
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) override;
List<RefPtr<ComponentType>> const& getChildComponents() { return m_childComponents; };
Index getChildComponentCount() { return m_childComponents.getCount(); }
@@ -598,10 +598,10 @@ namespace Slang
DiagnosticSink* sink);
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -791,10 +791,10 @@ namespace Slang
SLANG_OVERRIDE;
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -894,21 +894,21 @@ namespace Slang
SLANG_NO_THROW void SLANG_MCALL computeDependencyBasedHash(
SlangInt entryPointIndex,
SlangInt targetIndex,
- slang::Digest* outHash) SLANG_OVERRIDE
+ slang::IBlob** outHash) SLANG_OVERRIDE
{
return Super::computeDependencyBasedHash(entryPointIndex, targetIndex, outHash);
}
- SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::IBlob** outHash) SLANG_OVERRIDE
{
return Super::computeContentsBasedHash(outHash);
}
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -1121,21 +1121,21 @@ namespace Slang
SLANG_NO_THROW void SLANG_MCALL computeDependencyBasedHash(
SlangInt entryPointIndex,
SlangInt targetIndex,
- slang::Digest* outHash) SLANG_OVERRIDE
+ slang::IBlob** outHash) SLANG_OVERRIDE
{
return Super::computeDependencyBasedHash(entryPointIndex, targetIndex, outHash);
}
- SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::IBlob** outHash) SLANG_OVERRIDE
{
return Super::computeContentsBasedHash(outHash);
}
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -1317,21 +1317,21 @@ namespace Slang
SLANG_NO_THROW void SLANG_MCALL computeDependencyBasedHash(
SlangInt entryPointIndex,
SlangInt targetIndex,
- slang::Digest* outHash) SLANG_OVERRIDE
+ slang::IBlob** outHash) SLANG_OVERRIDE
{
return Super::computeDependencyBasedHash(entryPointIndex, targetIndex, outHash);
}
- SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::IBlob** outHash) SLANG_OVERRIDE
{
return Super::computeContentsBasedHash(outHash);
}
virtual void updateDependencyBasedHash(
- DigestBuilder& hashBuilder,
+ DigestBuilder<MD5>& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override;
+ virtual void updateContentsBasedHash(DigestBuilder<MD5>& hashBuilder) override;
/// Create a module (initially empty).
Module(Linkage* linkage, ASTBuilder* astBuilder = nullptr);
@@ -1475,8 +1475,8 @@ namespace Slang
StringSlicePool m_mangledExportPool;
List<NodeBase*> m_mangledExportSymbols;
- slang::Digest lastModifiedDigest;
- slang::Digest contentsDigest;
+ MD5::Digest lastModifiedDigest;
+ MD5::Digest contentsDigest;
};
typedef Module LoadedModule;
@@ -1772,7 +1772,7 @@ namespace Slang
// defines, the compiler version, and other compiler options. This is then merged with the hash
// produced for the program to produce a key that can be used with the shader cache.
void updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt targetIndex);
void addTarget(
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index f16f1b186..3b2175fad 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -44,9 +44,6 @@
#include "slang-check-impl.h"
-#include "../core/slang-md5.h"
-#include "../core/slang-digest-util.h"
-
#include "../../slang-tag-version.h"
#include <sys/stat.h>
@@ -1324,7 +1321,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompileRequest(
}
void Linkage::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt targetIndex)
{
// Add the Slang compiler version to the hash
@@ -1693,9 +1690,8 @@ void TranslationUnitRequest::_addSourceFile(SourceFile* sourceFile)
// fake path in the list of file path dependencies. This is needed to account
// for non-file-based dependencies later when shader files are being hashed for
// the shader cache.
-
- slang::Digest sourceHash = DigestUtil::computeDigestForStringSlice(sourceFile->getContent());
- getModule()->addFilePathDependency(DigestUtil::toString(sourceHash));
+ auto sourceHash = MD5::compute(sourceFile->getContent().begin(), sourceFile->getContent().getLength());
+ getModule()->addFilePathDependency(sourceHash.toString());
}
}
@@ -3252,7 +3248,7 @@ ISlangUnknown* Module::getInterface(const Guid& guid)
}
void Module::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt entryPointIndex)
{
// CompositeComponentType will have already hashed this Module's file
@@ -3261,11 +3257,11 @@ void Module::updateDependencyBasedHash(
SLANG_UNUSED(entryPointIndex);
}
-void Module::updateContentsBasedHash(DigestBuilder& builder)
+void Module::updateContentsBasedHash(DigestBuilder<MD5>& builder)
{
auto filePathDependencies = getFilePathDependencies();
- DigestBuilder lastModifiedBuilder;
+ DigestBuilder<MD5> lastModifiedBuilder;
auto statFailed = false;
for (auto file : filePathDependencies)
{
@@ -3279,12 +3275,12 @@ void Module::updateContentsBasedHash(DigestBuilder& builder)
lastModifiedBuilder.append(fileStatus.st_mtime);
}
- slang::Digest temp = lastModifiedBuilder.finalize();
+ MD5::Digest temp = lastModifiedBuilder.finalize();
if (statFailed || temp != lastModifiedDigest)
{
// Either a stat() call failed, or changes were made to at least one of the file dependencies,
// so we will need to re-generate the contents digest and save the new digest.
- DigestBuilder contentsBuilder;
+ DigestBuilder<MD5> contentsBuilder;
for (auto file : filePathDependencies)
{
List<uint8_t> fileContents;
@@ -3292,7 +3288,7 @@ void Module::updateContentsBasedHash(DigestBuilder& builder)
{
// Failure to read the file means this is a digest for the contents of a source
// file which does not live on disk.
- contentsBuilder.append(DigestUtil::fromString(file.getUnownedSlice()));
+ contentsBuilder.append(file);
}
else
{
@@ -3512,9 +3508,9 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getEntryPointCode(
SLANG_NO_THROW void SLANG_MCALL ComponentType::computeDependencyBasedHash(
SlangInt entryPointIndex,
SlangInt targetIndex,
- slang::Digest* outHash)
+ slang::IBlob** outHash)
{
- DigestBuilder builder;
+ DigestBuilder<MD5> builder;
// A note on enums that may be hashed in as part of the following two function calls:
//
@@ -3542,14 +3538,16 @@ SLANG_NO_THROW void SLANG_MCALL ComponentType::computeDependencyBasedHash(
auto entryPointNameOverride = getEntryPointNameOverride(entryPointIndex);
builder.append(entryPointNameOverride);
- *outHash = builder.finalize();
+ auto hash = builder.finalize().toBlob();
+ *outHash = hash.detach();
}
-SLANG_NO_THROW void SLANG_MCALL ComponentType::computeContentsBasedHash(slang::Digest* outHash)
+SLANG_NO_THROW void SLANG_MCALL ComponentType::computeContentsBasedHash(slang::IBlob** outHash)
{
- DigestBuilder builder;
+ DigestBuilder<MD5> builder;
updateContentsBasedHash(builder);
- *outHash = builder.finalize();
+ auto hash = builder.finalize().toBlob();
+ *outHash = hash.detach();
}
SLANG_NO_THROW SlangResult SLANG_MCALL ComponentType::getEntryPointHostCallable(
@@ -3885,7 +3883,7 @@ CompositeComponentType::CompositeComponentType(
}
void CompositeComponentType::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt entryPointIndex)
{
auto componentCount = getChildComponentCount();
@@ -3896,7 +3894,7 @@ void CompositeComponentType::updateDependencyBasedHash(
}
}
-void CompositeComponentType::updateContentsBasedHash(DigestBuilder& builder)
+void CompositeComponentType::updateContentsBasedHash(DigestBuilder<MD5>& builder)
{
auto componentCount = getChildComponentCount();
@@ -4386,7 +4384,7 @@ SpecializedComponentType::SpecializedComponentType(
}
void SpecializedComponentType::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt entryPointIndex)
{
auto specializationArgCount = getSpecializationArgCount();
@@ -4397,7 +4395,6 @@ void SpecializedComponentType::updateDependencyBasedHash(
builder.append(argString);
}
- slang::Digest baseHash;
getBaseComponentType()->updateDependencyBasedHash(builder, entryPointIndex);
}
@@ -4446,7 +4443,7 @@ void RenamedEntryPointComponentType::acceptVisitor(
}
void RenamedEntryPointComponentType::updateDependencyBasedHash(
- DigestBuilder& builder,
+ DigestBuilder<MD5>& builder,
SlangInt entryPointIndex)
{
// CompositeComponentType will have already hashed the name override and file