CSPspEmu.Core.Crypto.Kirk.KirkSha1 C# (CSharp) 메소드

KirkSha1() 공개 메소드

Creates a SHA1 Hash Command: 11, 0xB
public KirkSha1 ( byte OutputBuffer, byte InputBuffer, int InputSize ) : void
OutputBuffer byte
InputBuffer byte
InputSize int
리턴 void
        public void KirkSha1(byte* OutputBuffer, byte* InputBuffer, int InputSize)
        {
            //CheckInitialized();

            var Header = (KIRK_SHA1_HEADER*)InputBuffer;
            if (InputSize == 0 || Header->DataSize == 0)
            {
                throw(new KirkException(ResultEnum.PSP_KIRK_DATA_SIZE_IS_ZERO));
            }

            //Size <<= 4;
            //Size >>= 4;
            InputSize &= 0x0FFFFFFF;
            InputSize = (InputSize < Header->DataSize) ? InputSize : Header->DataSize;

            var Sha1Hash = Sha1(
                PointerUtils.PointerToByteArray(InputBuffer + 4, InputSize)
            );

            PointerUtils.Memcpy(OutputBuffer, Sha1Hash, Sha1Hash.Length);
        }

Usage Example

예제 #1
0
		public void TestSha1()
		{
			var Kirk = new Kirk();
			Kirk.kirk_init();

			var Input = new byte[] {
				// Size
				0x20, 0x00, 0x00, 0x00,
				// Data
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			};

			var ExpectedOutput = new byte[]
			{
				0xDE, 0x8A, 0x84, 0x7B, 0xFF, 0x8C, 0x34, 0x3D, 0x69, 0xB8, 0x53, 0xA2,
				0x15, 0xE6, 0xEE, 0x77, 0x5E, 0xF2, 0xEF, 0x96
			};

			var Output = new byte[0x14];

			Assert.AreEqual(0x24, Input.Length);

			fixed (byte* OutputPtr = Output)
			fixed (byte* InputPtr = Input)
			{
				Kirk.KirkSha1(OutputPtr, InputPtr, Input.Length);
			}

			CollectionAssert.AreEqual(ExpectedOutput, Output);
			//Console.WriteLine(BitConverter.ToString(Hash));
		}