Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Kanamori <atsushik@microsoft.com>2016-09-30 20:30:28 +0300
committerAtsushi Kanamori <atsushik@microsoft.com>2016-09-30 20:30:28 +0300
commit76dcda45fd29533ddfbb2479c738335e74968649 (patch)
treeb2f89875cdf838ddb91e6793f5f846b16b9d6427 /src/Native/Runtime/strongname.cpp
parentfb87f6b7339d532cdb944719942ea25ef2236db1 (diff)
SHA1 as RuntimeImport (part 2)
Final implementation, replacing the BCrypt and the OpenSSl implementation that never was. Transformations made to sha1.cpp/sha1.h: - Removed CONTRACTL's. - Replace Windows typedefs (not available) with the xplat equivalents: BYTE => UInt8 DWORD => UInt32 DWORDC => const UInt32 BOOL => bool TRUE => true FALSE => false - _ASSERTE => ASSERT - Copy _rotl out of VCLib sources (_rotl() does not resolve on Unix.) - Removed the unreferenced local "OK" (Project N build makes a federal case out of this.) - Added "const" qualifier to AddData pbData.
Diffstat (limited to 'src/Native/Runtime/strongname.cpp')
-rw-r--r--src/Native/Runtime/strongname.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/Native/Runtime/strongname.cpp b/src/Native/Runtime/strongname.cpp
index 7718b5e28..924291767 100644
--- a/src/Native/Runtime/strongname.cpp
+++ b/src/Native/Runtime/strongname.cpp
@@ -10,20 +10,35 @@
#include "CommonTypes.h"
#include "CommonMacros.h"
#include "PalRedhawkCommon.h"
+#include "PalRedhawk.h"
+#include "sha1.h"
//
// Converts a public key into a public key token, by computing the SHA1 of the public key, then taking the last 8 bytes in reverse order.
//
// The only legal value for "cbPublicKeyTokenOut" is 8 - this parameter exists as defense in depth.
//
-COOP_PINVOKE_HELPER(void, RhConvertPublicKeyToPublicKeyToken, (const char* pbPublicKey, int cbPublicKey, char *pbPublicKeyTokenOut, int cbPublicKeyTokenOut))
+
+#define PUBLIC_KEY_TOKEN_LEN 8
+
+COOP_PINVOKE_HELPER(void, RhConvertPublicKeyToPublicKeyToken, (const UInt8* pbPublicKey, int cbPublicKey, UInt8 *pbPublicKeyTokenOut, int cbPublicKeyTokenOut))
{
ASSERT(pbPublicKey != NULL);
ASSERT(pbPublicKeyTokenOut != NULL);
- ASSERT(!"RhConvertPublicKeyToPublicKeyToken not yet implemented.");
- // Nonsense code to keep C++ from complaining about unused parameters.
- pbPublicKeyTokenOut[cbPublicKeyTokenOut - 1] = pbPublicKey[cbPublicKey - 1];
+ if (cbPublicKeyTokenOut != PUBLIC_KEY_TOKEN_LEN)
+ {
+ RhFailFast();
+ }
+
+ SHA1Hash sha1;
+ sha1.AddData(pbPublicKey, cbPublicKey);
+ UInt8* pHash = sha1.GetHash();
+
+ for (int i = 0; i < PUBLIC_KEY_TOKEN_LEN; i++)
+ {
+ pbPublicKeyTokenOut[i] = pHash[SHA1_HASH_SIZE - i - 1];
+ }
return;
}