Forráskód Böngészése

Added Tiger digest.

woollybah 5 éve
szülő
commit
083c6a2558

+ 1 - 0
digest.mod/doc/intro.bbdoc

@@ -24,6 +24,7 @@ The following is a list of available digests :
 | #Crypto.Ripemd256Digest           | 32 |
 | #Crypto.Blake2BDigest ([TBlake2B_256])  | 32 |
 | #Crypto.SHA3Digest ([TSHA3_224])  | 28 |
+| #Crypto.TigerDigest               | 24 |
 | #Crypto.SHA1Digest                | 20 |
 | #Crypto.Ripemd160Digest           | 20 |
 | #Crypto.Blake2BDigest ([TBlake2B_160])  | 20 |

+ 20 - 0
digest.mod/tests/test.bmx

@@ -13,6 +13,7 @@ Import Crypto.ripemd256digest
 Import Crypto.ripemd160digest
 Import Crypto.ripemd128digest
 Import Crypto.blake2bdigest
+Import Crypto.TigerDigest
 Import BRL.MaxUnit
 
 New TTestSuite.run()
@@ -93,6 +94,9 @@ Type TDigestTest Extends TTest
 	Const BLAKE2B_160_HASH_STRING:String = "3c523ed102ab45a37d54f5610d5a983162fde84f"
 	Global BLAKE2B_160_HASH_ARRAY:Byte[] = [60, 82, 62, 209, 2, 171, 69, 163, 125, 84, 245, 97, 13, 90, 152, 49, 98, 253, 232, 79]
 
+	Const TIGER_HASH_STRING:String = "6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075"
+	Global TIGER_HASH_ARRAY:Byte[] = [109, 18, 164, 30, 114, 230, 68, 240, 23, 182, 240, 226, 247, 180, 76, 98, 133, 240, 109, 213, 210, 197, 176, 117]
+
 	Method testMD5() { test }
 	
 		Local digest:TMessageDigest = GetMessageDigest("MD5")
@@ -371,4 +375,20 @@ Type TDigestTest Extends TTest
 	
 	End Method
 
+	Method testTiger() { test }
+	
+		Local digest:TMessageDigest = GetMessageDigest("TIGER")
+	
+		assertEquals(TIGER_HASH_STRING, digest.Digest(TEST_PHRASE))
+	
+		Local bytes:Byte[] = digest.DigestBytes(TEST_PHRASE)
+
+		assertEquals(TIGER_HASH_ARRAY.length, bytes.length)
+		
+		For Local i:Int = 0 Until TIGER_HASH_ARRAY.length
+			assertEquals(TIGER_HASH_ARRAY[i], bytes[i])
+		Next
+	
+	End Method
+
 End Type

+ 37 - 0
tigerdigest.mod/common.bmx

@@ -0,0 +1,37 @@
+'
+'  Copyright (C) 2019-2020 Bruce A Henderson
+'
+'  This software is provided 'as-is', without any express or implied
+'  warranty.  In no event will the authors be held liable for any damages
+'  arising from the use of this software.
+'
+'  Permission is granted to anyone to use this software for any purpose,
+'  including commercial applications, and to alter it and redistribute it
+'  freely, subject to the following restrictions:
+'
+'  1. The origin of this software must not be misrepresented; you must not
+'     claim that you wrote the original software. If you use this software
+'     in a product, an acknowledgment in the product documentation would be
+'     appreciated but is not required.
+'  2. Altered source versions must be plainly marked as such, and must not be
+'     misrepresented as being the original software.
+'  3. This notice may not be removed or altered from any source distribution.
+'
+SuperStrict
+
+Import Crypto.Digest
+
+
+Import "../libtomcrypt.mod/libtomcrypt/src/headers/*.h"
+Import "../libtomcrypt.mod/libtomcrypt/src/hashes/tiger.c"
+
+Import "glue.c"
+
+
+Extern
+
+	Function bmx_digest_tiger_init:Byte Ptr()
+	Function bmx_digest_tiger_process:Int(handle:Byte Ptr, buf:Byte Ptr, length:Int)
+	Function bmx_digest_tiger_done:Int(handle:Byte Ptr, out:Byte[])
+
+End Extern

+ 39 - 0
tigerdigest.mod/glue.c

@@ -0,0 +1,39 @@
+/*
+  Copyright (C) 2019-2020 Bruce A Henderson
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "tomcrypt.h"
+#include "brl.mod/blitz.mod/blitz.h"
+
+hash_state * bmx_digest_tiger_init() {
+	hash_state * state = malloc(sizeof(hash_state));
+	tiger_init(state);
+	return state;
+}
+
+int bmx_digest_tiger_process(hash_state * state, char * buf, int length) {
+	return tiger_process(state, buf, length);
+}
+
+int bmx_digest_tiger_done(hash_state * state, BBArray * out) {
+	BBBYTE * p = (BBBYTE**)BBARRAYDATA(out, 1);
+
+	int res = tiger_done(state, p);
+	tiger_init(state);
+	return res;
+}

+ 79 - 0
tigerdigest.mod/tigerdigest.bmx

@@ -0,0 +1,79 @@
+'
+'  Copyright (C) 2019-2020 Bruce A Henderson
+'
+'  This software is provided 'as-is', without any express or implied
+'  warranty.  In no event will the authors be held liable for any damages
+'  arising from the use of this software.
+'
+'  Permission is granted to anyone to use this software for any purpose,
+'  including commercial applications, and to alter it and redistribute it
+'  freely, subject to the following restrictions:
+'
+'  1. The origin of this software must not be misrepresented; you must not
+'     claim that you wrote the original software. If you use this software
+'     in a product, an acknowledgment in the product documentation would be
+'     appreciated but is not required.
+'  2. Altered source versions must be plainly marked as such, and must not be
+'     misrepresented as being the original software.
+'  3. This notice may not be removed or altered from any source distribution.
+'
+SuperStrict
+
+Rem
+bbdoc: Tiger Digest
+about: 
+See <https://en.wikipedia.org/wiki/Tiger_(hash_function)>
+End Rem
+Module Crypto.TigerDigest
+
+ModuleInfo "CC_OPTS: -DLTC_NO_TEST -DLTC_NO_FILE"
+ModuleInfo "CC_OPTS: -DLTC_TIGER"
+
+Import "common.bmx"
+
+New TTigerDigestRegister
+
+Rem
+bbdoc: A Tiger message digest.
+End Rem
+Type TTiger Extends TMessageDigest
+
+	Method New()
+		digestPtr = bmx_digest_tiger_init()
+	End Method
+
+	Method OutBytes:Int() Override
+		Return 24
+	End Method
+	
+	Rem
+	bbdoc: Updates the hash with @dataLen bytes of data.
+	End Rem
+	Method Update:Int(data:Byte Ptr, dataLen:Int) Override
+		Return bmx_digest_tiger_process(digestPtr, data, dataLen)
+	End Method
+	
+	Rem
+	bbdoc: Finishes hashing and produces the digest, filling @digest with the hashed bytes.
+	about: The hashing state is reset, ready to create a new digest.
+	End Rem
+	Method Finish:Int(digest:Byte[]) Override
+		Assert digest.length >= 24, "Byte array must be at least 24 bytes."
+		Return bmx_digest_tiger_done(digestPtr, digest)
+	End Method
+
+End Type
+
+Type TTigerDigestRegister Extends TDigestRegister
+
+	Method GetDigest:TMessageDigest( name:String ) Override
+		If name.ToUpper() = "TIGER" Then
+			Return New TTiger
+		End If
+	End Method
+
+	Method ToString:String() Override
+		Return "TIGER"
+	End Method
+	
+End Type