a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
90 lines
3.0 KiB
C#
90 lines
3.0 KiB
C#
//
|
|
// Mono.Security.Cryptography SHA224 Class implementation
|
|
//
|
|
// Authors:
|
|
// Sebastien Pouliot <sebastien@ximian.com>
|
|
//
|
|
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
// a copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
// the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be
|
|
// included in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
namespace Mono.Security.Cryptography {
|
|
|
|
// FIXME: Remove when (or if) SHA224 moves into corlib
|
|
// (as corlib already have the required constants).
|
|
internal sealed class SHAConstants {
|
|
|
|
private SHAConstants ()
|
|
{
|
|
// Never instantiated.
|
|
}
|
|
|
|
// SHA-224/256 Constants
|
|
// Represent the first 32 bits of the fractional parts of the
|
|
// cube roots of the first sixty-four prime numbers
|
|
public readonly static uint[] K1 = {
|
|
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
|
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
|
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
|
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
|
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
|
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
|
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
|
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
|
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
|
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
|
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
|
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
|
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
|
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
|
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
|
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
|
|
};
|
|
}
|
|
|
|
public abstract class SHA224 : HashAlgorithm {
|
|
|
|
public SHA224 ()
|
|
{
|
|
// SHA-224 hash length are 224 bits long
|
|
HashSizeValue = 224;
|
|
}
|
|
|
|
public static new SHA224 Create ()
|
|
{
|
|
// for this to work we must register ourself with CryptoConfig
|
|
return Create ("SHA224");
|
|
}
|
|
|
|
public static new SHA224 Create (string hashName)
|
|
{
|
|
object o = CryptoConfig.CreateFromName (hashName);
|
|
// in case machine.config isn't configured to use any SHA224 implementation
|
|
if (o == null) {
|
|
o = new SHA224Managed ();
|
|
}
|
|
return (SHA224) o;
|
|
}
|
|
}
|
|
}
|