diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
commit | ef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch) | |
tree | dee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/vm/sha1.h | |
download | coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2 coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip |
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/vm/sha1.h')
-rw-r--r-- | src/vm/sha1.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/vm/sha1.h b/src/vm/sha1.h new file mode 100644 index 0000000000..ed814c0fa9 --- /dev/null +++ b/src/vm/sha1.h @@ -0,0 +1,55 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// +// + +#if defined(FEATURE_CORECLR) +#ifndef SHA1_H_ +#define SHA1_H_ + +// Hasher class, performs no allocation and therefore does not throw or return +// errors. Usage is as follows: +// Create an instance (this initializes the hash). +// Add one or more blocks of input data using AddData(). +// Retrieve the hash using GetHash(). This can be done as many times as desired +// until the object is destructed. Once a hash is asked for, further AddData +// calls will be ignored. There is no way to reset object state (simply +// destroy the object and create another instead). + +#define SHA1_HASH_SIZE 20 // Number of bytes output by SHA-1 + +typedef struct { + DWORD magic_sha1; // Magic value for A_SHA_CTX + DWORD awaiting_data[16]; + // Data awaiting full 512-bit block. + // Length (nbit_total[0] % 512) bits. + // Unused part of buffer (at end) is zero + DWORD partial_hash[5]; + // Hash through last full block + DWORD nbit_total[2]; + // Total length of message so far + // (bits, mod 2^64) +} SHA1_CTX; + +class SHA1Hash +{ +private: + SHA1_CTX m_Context; + BYTE m_Value[SHA1_HASH_SIZE]; + BOOL m_fFinalized; + + void SHA1Init(SHA1_CTX*); + void SHA1Update(SHA1_CTX*, const BYTE*, const DWORD); + void SHA1Final(SHA1_CTX*, BYTE* digest); + +public: + SHA1Hash(); + void AddData(BYTE *pbData, DWORD cbData); + BYTE *GetHash(); +}; + +#endif // SHA1_H_ +#else // !defined(FEATURE_CORECLR) +#include "crypto/sha1.h" +#endif // defined(FEATURE_CORECLR)
\ No newline at end of file |