2017-06-29 21:23:39 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2017-06-29 22:09:41 +01:00
|
|
|
|
// Filename : SHA512.cs
|
2017-06-29 21:23:39 +01:00
|
|
|
|
// Version : 1.0
|
|
|
|
|
|
// Author(s) : Natalia Portillo
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Component
|
|
|
|
|
|
//
|
|
|
|
|
|
// Revision : $Revision$
|
|
|
|
|
|
// Last change by : $Author$
|
|
|
|
|
|
// Date : $Date$
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Description
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright (C) 2011-2015 Claunia.com
|
|
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
// //$Id$
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using DiscImageChef.Checksums;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Tests.Checksums
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public class SHA512
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
2017-06-29 22:09:41 +01:00
|
|
|
|
static readonly byte[] ExpectedEmpty = { 0xd6, 0x29, 0x26, 0x85, 0xb3, 0x80, 0xe3, 0x38, 0xe0, 0x25, 0xb3, 0x41, 0x5a, 0x90, 0xfe, 0x8f, 0x9d, 0x39, 0xa4, 0x6e, 0x7b, 0xdb, 0xa8, 0xcb, 0x78, 0xc5, 0x0a, 0x33, 0x8c, 0xef, 0xca, 0x74, 0x1f, 0x69, 0xe4, 0xe4, 0x64, 0x11, 0xc3, 0x2d, 0xe1, 0xaf, 0xde, 0xdf, 0xb2, 0x68, 0xe5, 0x79, 0xa5, 0x1f, 0x81, 0xff, 0x85, 0xe5, 0x6f, 0x55, 0xb0, 0xee, 0x7c, 0x33, 0xfe, 0x8c, 0x25, 0xc9 };
|
|
|
|
|
|
static readonly byte[] ExpectedRandom = { 0x6a, 0x0a, 0x18, 0xc2, 0xad, 0xf8, 0x83, 0xac, 0x58, 0xe6, 0x21, 0x96, 0xdb, 0x8d, 0x3d, 0x0e, 0xb9, 0x87, 0xd1, 0x49, 0x24, 0x97, 0xdb, 0x15, 0xb9, 0xfc, 0xcc, 0xb0, 0x36, 0xdf, 0x64, 0xae, 0xdb, 0x3e, 0x82, 0xa0, 0x4d, 0xdc, 0xd1, 0x37, 0x48, 0x92, 0x95, 0x51, 0xf9, 0xdd, 0xab, 0x82, 0xf4, 0x8a, 0x85, 0x3f, 0x9a, 0x01, 0xb5, 0xf2, 0x8c, 0xbb, 0x4a, 0xa5, 0x1b, 0x40, 0x7c, 0xb6 };
|
2017-06-29 21:23:39 +01:00
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public void SHA512EmptyFile()
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
2017-06-29 22:09:41 +01:00
|
|
|
|
SHA512Context ctx = new SHA512Context();
|
|
|
|
|
|
ctx.Init();
|
|
|
|
|
|
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"));
|
2017-06-29 21:23:39 +01:00
|
|
|
|
Assert.AreEqual(ExpectedEmpty, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public void SHA512EmptyData()
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] data = new byte[1048576];
|
|
|
|
|
|
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
fs.Read(data, 0, 1048576);
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
fs.Dispose();
|
2017-06-29 22:09:41 +01:00
|
|
|
|
SHA512Context ctx = new SHA512Context();
|
|
|
|
|
|
ctx.Init();
|
|
|
|
|
|
ctx.Data(data, out byte[] result);
|
2017-06-29 21:23:39 +01:00
|
|
|
|
Assert.AreEqual(ExpectedEmpty, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public void SHA512EmptyInstance()
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] data = new byte[1048576];
|
|
|
|
|
|
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
fs.Read(data, 0, 1048576);
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
fs.Dispose();
|
2017-06-29 22:09:41 +01:00
|
|
|
|
SHA512Context ctx = new SHA512Context();
|
2017-06-29 21:23:39 +01:00
|
|
|
|
ctx.Init();
|
|
|
|
|
|
ctx.Update(data);
|
|
|
|
|
|
byte[] result = ctx.Final();
|
|
|
|
|
|
Assert.AreEqual(ExpectedEmpty, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public void SHA512RandomFile()
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
2017-06-29 22:09:41 +01:00
|
|
|
|
SHA512Context ctx = new SHA512Context();
|
|
|
|
|
|
ctx.Init();
|
|
|
|
|
|
byte[] result = ctx.File(Path.Combine(Consts.TestFilesRoot, "checksums", "random"));
|
2017-06-29 21:23:39 +01:00
|
|
|
|
Assert.AreEqual(ExpectedRandom, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public void SHA512RandomData()
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] data = new byte[1048576];
|
|
|
|
|
|
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
fs.Read(data, 0, 1048576);
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
fs.Dispose();
|
2017-06-29 22:09:41 +01:00
|
|
|
|
SHA512Context ctx = new SHA512Context();
|
|
|
|
|
|
ctx.Init();
|
|
|
|
|
|
ctx.Data(data, out byte[] result);
|
2017-06-29 21:23:39 +01:00
|
|
|
|
Assert.AreEqual(ExpectedRandom, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2017-06-29 22:09:41 +01:00
|
|
|
|
public void SHA512RandomInstance()
|
2017-06-29 21:23:39 +01:00
|
|
|
|
{
|
|
|
|
|
|
byte[] data = new byte[1048576];
|
|
|
|
|
|
FileStream fs = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "random"), FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
fs.Read(data, 0, 1048576);
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
fs.Dispose();
|
2017-06-29 22:09:41 +01:00
|
|
|
|
SHA512Context ctx = new SHA512Context();
|
2017-06-29 21:23:39 +01:00
|
|
|
|
ctx.Init();
|
|
|
|
|
|
ctx.Update(data);
|
|
|
|
|
|
byte[] result = ctx.Final();
|
|
|
|
|
|
Assert.AreEqual(ExpectedRandom, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|