Scribunto: Add HashLibrary [#589]

pull/620/head
gnosygnu 5 years ago
parent 9f0cfc27bb
commit 866debd51d

@ -1,145 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
import gplx.core.texts.*; /*Base32Converter*/ import gplx.core.progs.*;
public class Hash_algo_ {
public static Hash_algo New__md5() {return new Hash_algo__md5();}
public static Hash_algo New__sha1() {return new Hash_algo__sha1();}
public static Hash_algo New__sha2_256() {return new Hash_algo__sha2_256();}
public static Hash_algo New__tth_192() {return new Hash_algo__tth_192();}
public static Hash_algo New_by_tid(byte tid) {
switch (tid) {
case Tid__md5: return New__md5();
case Tid__sha1: return New__sha1();
case Tid__sha2_256: return New__sha2_256();
case Tid__tth_192: return New__tth_192();
default: throw Err_.new_unhandled_default(tid);
}
}
public static Hash_algo New(String key) {
if (key == Hash_algo__md5.KEY) return New__md5();
else if (key == Hash_algo__sha1.KEY) return New__sha1();
else if (key == Hash_algo__sha2_256.KEY) return New__sha2_256();
else if (key == Hash_algo__tth_192.KEY) return New__tth_192();
else throw Err_.new_unhandled(key);
}
public static final byte Tid__md5 = 0, Tid__sha1 = 1, Tid__sha2_256 = 2, Tid__tth_192 = 3;
}
abstract class Hash_algo_base implements Hash_algo {
private final MessageDigest md;
private final byte[] trg_bry;
private byte[] tmp_bfr; private final int tmp_bfr_len = 4096;
public Hash_algo_base(MessageDigest md, int trg_bry_len) {
this.md = md; this.trg_bry = new byte[trg_bry_len];
}
public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
public byte[] Hash_bry_as_bry(byte[] src) {
Hash_algo_utl_.Hash_bry(md, src, src.length, trg_bry);
return Bry_.Copy(trg_bry); // NOTE: must copy to return different instances to callers; else callers may hash same instance with different values
}
public String Hash_stream_as_str(Console_adp console, IoStream stream) {return String_.new_a7(Hash_stream_as_bry(console, stream));}
public byte[] Hash_stream_as_bry(Console_adp console, IoStream stream) {
if (tmp_bfr == null) tmp_bfr = new byte[4096];
Hash_algo_utl_.Hash_stream(console, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
return trg_bry;
}
public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {
if (tmp_bfr == null) tmp_bfr = new byte[4096];
Hash_algo_utl_.Hash_stream(prog_ui, stream, md, tmp_bfr, tmp_bfr_len, trg_bry);
return trg_bry;
}
protected static MessageDigest Get_message_digest(String key) {
try {return MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
}
}
class Hash_algo__md5 extends Hash_algo_base {
public Hash_algo__md5() {super(Get_message_digest_instance(), 32);}
public String Key() {return KEY;} public static final String KEY = "md5";
private static MessageDigest Get_message_digest_instance() {
if (md__md5 == null)
md__md5 = Get_message_digest(KEY);
return md__md5;
} private static MessageDigest md__md5;
}
class Hash_algo__sha1 extends Hash_algo_base {
public Hash_algo__sha1() {super(Get_message_digest_instance(), 40);}
public String Key() {return KEY;} public static final String KEY = "sha1";
private static MessageDigest Get_message_digest_instance() {
if (md__sha1 == null)
md__sha1 = Get_message_digest(KEY);
return md__sha1;
} private static MessageDigest md__sha1;
}
class Hash_algo__sha2_256 extends Hash_algo_base {
public Hash_algo__sha2_256() {super(Get_message_digest_instance(), 64);}
public String Key() {return KEY;} public static final String KEY = "sha-256";
private static MessageDigest Get_message_digest_instance() {
if (md__sha2_256 == null)
md__sha2_256 = Get_message_digest(KEY);
return md__sha2_256;
} private static MessageDigest md__sha2_256;
}
class Hash_algo_utl_ {
public static void Hash_bry(MessageDigest md, byte[] src_bry, int src_len, byte[] trg_bry) {
int pos = 0;
while (true) {
if (pos == src_len) break;
int len = 4096;
if (pos + len > src_len) {
len = src_len - pos;
}
md.update(src_bry, pos, len);
pos += len;
}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry, trg_bry);
}
public static void Hash_stream(Console_adp dialog, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
// long pos = 0, len = stream.Len(); // pos and len must be long, else will not hash files > 2 GB
while (true) {
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
if (read < 1) break;
md.update(tmp_bfr, 0, read);
// pos += read;
}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
}
public static void Hash_stream(Gfo_prog_ui prog_ui, IoStream stream, MessageDigest md, byte[] tmp_bfr, int tmp_bfr_len, byte[] trg_bry) {
long pos = prog_ui.Prog_data_cur(), len = prog_ui.Prog_data_end(); // pos and len must be long, else will not hash files > 2 GB
try {
while (true) {
int read = stream.Read(tmp_bfr, 0, tmp_bfr_len); // read stream into tmp_bfr
if (read < 1) break;
md.update(tmp_bfr, 0, read);
if (prog_ui.Prog_notify_and_chk_if_suspended(pos, len)) return;
pos += read;
}
}
finally {stream.Rls();}
byte[] md_bry = md.digest();
gplx.core.encoders.Hex_utl_.Encode_bry(md_bry , trg_bry);
}
public static String To_base_32_str(byte[] ary) {return Base32Converter.Encode(ary);}
}

@ -0,0 +1,66 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
import java.security.MessageDigest;
import java.security.Provider;
import java.security.Security;
import java.security.Provider.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class Security_utl_ {
private static final void List_algos(Provider prov, Class<?> typeClass) {
String type = typeClass.getSimpleName();
List<Service> algos = new ArrayList<Service>();
Set<Service> services = prov.getServices();
for (Service service : services) {
if (service.getType().equalsIgnoreCase(type)) {
algos.add(service);
}
}
if (!algos.isEmpty()) {
System.out.printf(" --- Provider %s, version %.2f --- %n", prov.getName(), prov.getVersion());
for (Service service : algos) {
String algo = service.getAlgorithm();
System.out.printf("Algorithm name: \"%s\"%n", algo);
}
}
// --- find aliases (inefficiently)
Set<Object> keys = prov.keySet();
for (Object key : keys) {
final String prefix = "Alg.Alias." + type + ".";
if (key.toString().startsWith(prefix)) {
String value = prov.get(key.toString()).toString();
System.out.printf("Alias: \"%s\" -> \"%s\"%n",
key.toString().substring(prefix.length()),
value);
}
}
}
public static void main(String[] args) {
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
List_algos(provider, MessageDigest.class);
}
}
}

@ -13,11 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
public interface Hash_algo {
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public interface Hash_algo {// THREAD.UNSAFE
String Key();
byte[] Hash_bry_as_bry(byte[] src);
String Hash_bry_as_str(byte[] src);
String Hash_stream_as_str(gplx.core.consoles.Console_adp console, gplx.core.ios.streams.IoStream src_stream);
byte[] Hash_stream_as_bry(gplx.core.progs.Gfo_prog_ui prog_ui, gplx.core.ios.streams.IoStream src_stream);
void Update_digest(byte[] src, int bgn, int end);
byte[] To_hash_bry();
Hash_algo Clone_hash_algo(); // factory method; note that MessageDigest's are member variables, so always create a new instance
}

@ -0,0 +1,41 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
import gplx.core.security.algos.jre.*; import gplx.core.security.algos.gplx_crypto.*;
public class Hash_algo_ {
public static Hash_algo New__md5() {return Jre_hash_factory.Instance.New_hash_algo(Jre_hash_factory.Key__md5);}
public static Hash_algo New__sha1() {return Jre_hash_factory.Instance.New_hash_algo(Jre_hash_factory.Key__sha1);}
public static Hash_algo New__sha2_256() {return Jre_hash_factory.Instance.New_hash_algo(Jre_hash_factory.Key__sha2_256);}
public static Hash_algo New__tth_192() {return new Hash_algo__tth_192();}
public static Hash_algo New_by_tid(byte tid) {
switch (tid) {
case Tid__md5: return New__md5();
case Tid__sha1: return New__sha1();
case Tid__sha2_256: return New__sha2_256();
case Tid__tth_192: return New__tth_192();
default: throw Err_.new_unhandled_default(tid);
}
}
public static Hash_algo New(String key) {
if (key == Jre_hash_factory.Key__md5) return New__md5();
else if (key == Jre_hash_factory.Key__sha1) return New__sha1();
else if (key == Jre_hash_factory.Key__sha2_256) return New__sha2_256();
else if (key == Hash_algo__tth_192.KEY) return New__tth_192();
else throw Err_.new_unhandled(key);
}
public static final byte Tid__md5 = 0, Tid__sha1 = 1, Tid__sha2_256 = 2, Tid__tth_192 = 3;
}

@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public class Hash_algo__fxt {
private final Hash_algo algo;
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
public void Test__hash(String expd, String raw) {
Tfds.Eq(expd, Hash_algo_utl.Calc_hash_as_str(algo, Bry_.new_u8(raw)));
Tfds.Eq(expd, Hash_algo_utl.Calc_hash_w_prog_as_str(algo, gplx.core.ios.streams.IoStream_.mem_txt_(Io_url_.Empty, raw), gplx.core.consoles.Console_adp_.Noop));
}
}

@ -0,0 +1,19 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public interface Hash_algo_factory {
Hash_algo New_hash_algo(String key);
}

@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
public class Hash_algo_factory__composite implements Hash_algo_factory {
private boolean dirty = true;
private final Ordered_hash hash = Ordered_hash_.New();
private String[] algo_keys;
public String[] Algo_keys() {
if (dirty) {
dirty = false;
int len = hash.Len();
algo_keys = new String[len];
for (int i = 0; i < len; i++) {
algo_keys[i] = ((Hash_algo)hash.Get_at(i)).Key();
}
}
return algo_keys;
}
public Hash_algo New_hash_algo(String key) {
Hash_algo rv = (Hash_algo)hash.Get_by(key);
if (rv == null) {
throw Err_.new_wo_type("hash_algo unknown; key=" + key);
}
return rv.Clone_hash_algo();
}
public Hash_algo_factory__composite Reg_many(Hash_algo_factory factory, String... algo_keys) {
dirty = true;
for (String algo_key : algo_keys) {
if (hash.Has(algo_key)) {
throw Err_.new_wo_type("hash_algo already registered; key=" + algo_key);
}
hash.Add(algo_key, factory.New_hash_algo(algo_key));
}
return this;
}
public Hash_algo_factory__composite Reg_one(Hash_algo_factory factory, String src_key, String trg_key) {
if (hash.Has(trg_key)) {
throw Err_.new_wo_type("hash_algo already registered; name=" + trg_key);
}
hash.Add(trg_key, factory.New_hash_algo(src_key));
return this;
}
}

@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.consoles.*; import gplx.core.progs.*; import gplx.core.ios.streams.*;
import gplx.core.encoders.*;
public class Hash_algo_utl {
public static String Calc_hash_as_str(Hash_algo algo, byte[] bry) {return String_.new_u8(Calc_hash_as_bry(algo, bry));}
public static byte[] Calc_hash_as_bry(Hash_algo algo, byte[] bry) {
if (Type_.Is_assignable_from_by_obj(algo, Hash_algo_w_prog.class)) {
Hash_algo_w_prog algo_w_prog = (Hash_algo_w_prog)algo;
return Bry_.new_u8(algo_w_prog.Calc_hash_w_prog_as_str(IoStream_.ary_(bry), Console_adp_.Noop));
}
algo.Update_digest(bry, 0, bry.length);
return algo.To_hash_bry();
}
public static String Calc_hash_w_prog_as_str(Hash_algo algo, IoStream stream, Console_adp console) {return String_.new_u8(Calc_hash_w_prog_as_bry(algo, stream, console));}
public static byte[] Calc_hash_w_prog_as_bry(Hash_algo algo, IoStream stream, Console_adp console) {
if (Type_.Is_assignable_from_by_obj(algo, Hash_algo_w_prog.class)) {
Hash_algo_w_prog algo_w_prog = (Hash_algo_w_prog)algo;
return Bry_.new_u8(algo_w_prog.Calc_hash_w_prog_as_str(stream, console));
}
return Calc_hash_w_prog_as_bry(algo, stream, Gfo_prog_ui_.Noop);
}
public static byte[] Calc_hash_w_prog_as_bry(Hash_algo algo, IoStream stream, Gfo_prog_ui prog_ui) {
int tmp_bry_len = 4096;
byte[] tmp_bry = new byte[4096];
// pos and len must be long, else will not hash files > 2 GB
long pos = prog_ui.Prog_data_cur();
long len = prog_ui.Prog_data_end();
try {
while (true) {
int read = stream.Read(tmp_bry, 0, tmp_bry_len); // read stream into tmp_bry
if (read < 1) break;
algo.Update_digest(tmp_bry, 0, read);
if (prog_ui.Prog_notify_and_chk_if_suspended(pos, len)) return null;
pos += read;
}
}
finally {stream.Rls();}
byte[] rv = algo.To_hash_bry();
return rv;
}
}

@ -0,0 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.consoles.*; import gplx.core.ios.streams.*;
public interface Hash_algo_w_prog {
String Calc_hash_w_prog_as_str(IoStream stream, Console_adp console);
}

@ -13,16 +13,16 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
import gplx.core.progs.*;
public class Hash_algo__tth_192 implements Hash_algo {
public class Hash_algo__tth_192 implements Hash_algo, Hash_algo_w_prog {
public String Key() {return KEY;} public static final String KEY = "tth192";
public Hash_algo Clone_hash_algo() {return new Hash_algo__tth_192();}
public int BlockSize() {return blockSize;} public void BlockSize_set(int v) {blockSize = v;} int blockSize = 1024;
public String Hash_bry_as_str(byte[] src) {return String_.new_a7(Hash_bry_as_bry(src));}
public byte[] Hash_bry_as_bry(byte[] v) {return Bry_.new_a7(Hash_stream_as_str(Console_adp_.Noop, gplx.core.ios.streams.IoStream_.ary_(v)));}
public byte[] Hash_stream_as_bry(Gfo_prog_ui prog_ui, IoStream stream) {return Bry_.new_a7(Hash_stream_as_str(Console_adp_.Noop, stream));}
public String Hash_stream_as_str(Console_adp dialog, IoStream stream) {
public void Update_digest(byte[] src, int bgn, int end) {throw Err_.new_unimplemented();}
public byte[] To_hash_bry() {throw Err_.new_unimplemented();}
public String Calc_hash_w_prog_as_str(IoStream stream, Console_adp dialog) {
int leafCount = (int)(stream.Len() / blockSize);
HashDlgWtr dialogWtr = HashDlgWtr_.Current;
dialogWtr.Bgn(dialog, stream.Url(), CalcWorkUnits(stream.Len()));
@ -35,7 +35,7 @@ public class Hash_algo__tth_192 implements Hash_algo {
hashMainCount = 0;
HashAllBytes(dialogWtr, stream, leafCount);
byte[] rv = HashAllHashes(dialogWtr);
return Hash_algo_utl_.To_base_32_str(rv);
return gplx.core.texts.Base32Converter.Encode(rv);
}
byte[] CalcHash_next(IoStream stream) {
if (blockA == null || blockA.length != blockSize) blockA = new byte[blockSize];

@ -13,7 +13,7 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.*; /*IoStream*/
public class Hash_algo__tth_192__tst { // REF: http://open-content.net/specs/draft-jchapweske-thex-02.html; DC++ 0.698
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__tth_192());

@ -13,7 +13,7 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.junit.*;
public class Hash_algo__tth_192_tree_tst {
@Test public void CalcRecursiveHalves() {

@ -13,27 +13,33 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.gplx_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.junit.*; import gplx.core.consoles.*; import gplx.core.ios.streams.*; /*IoStream*/
public class Hash_console_wtr_tst {
@Before public void setup() {
Hash_algo__tth_192 algo = new Hash_algo__tth_192();
algo.BlockSize_set(10);
calc = algo;
}
private final Hash_console_wtr_fxt fxt = new Hash_console_wtr_fxt();
@Test public void Basic() {
tst_Status(10, stringAry_(" - hash: 100%"));
tst_Status(11, stringAry_(" - hash: 66%"));
tst_Status(30, stringAry_(" - hash: 40%", " - hash: 60%", " - hash: 100%"));
fxt.Test__Status(10, " - hash: 100%");
fxt.Test__Status(11, " - hash: 66%");
fxt.Test__Status(30, " - hash: 40%", " - hash: 60%", " - hash: 100%");
}
}
class Hash_console_wtr_fxt {
private Hash_algo__tth_192 algo;
public Hash_console_wtr_fxt() {
this.algo = new Hash_algo__tth_192();
algo.BlockSize_set(10);
}
void tst_Status(int count, String[] expdWritten) {
Console_adp__mem dialog = Console_adp_.Dev();
public void Test__Status(int count, String... expd) {
// init
Console_adp__mem console = Console_adp_.Dev();
// exec
String data = String_.Repeat("A", count);
IoStream stream = IoStream_.mem_txt_(Io_url_.Empty, data);
calc.Hash_stream_as_str(dialog, stream);
String[] actlWritten = dialog.Written().To_str_ary();
Tfds.Eq_ary(actlWritten, expdWritten);
algo.Calc_hash_w_prog_as_str(stream, console);
// test
String[] actl = console.Written().To_str_ary();
Tfds.Eq_ary(actl, expd);
}
String[] stringAry_(String... ary) {return ary;}
Hash_algo calc;
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.util.zip.Checksum;
public class Jre_checksum_algo implements Hash_algo {
private final Jre_checksum_factory factory;
private final Checksum checksum;
public Jre_checksum_algo(Jre_checksum_factory factory, String key) {
this.factory = factory;
this.key = key;
this.checksum = factory.New_Checksum(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Jre_checksum_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {checksum.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
long val = checksum.getValue();
String rv = Long.toHexString(val);
return Bry_.new_u8(rv.length() < 8 ? String_.PadBgn(rv, 8, "0") : rv);
}
}

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import java.util.zip.Adler32;
public class Jre_checksum_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Jre_checksum_algo(this, key);
}
public Checksum New_Checksum(String key) {
if (String_.Eq(key, Key__adler32)) return new Adler32();
else if (String_.Eq(key, Key__crc32)) return new CRC32();
else throw Err_.new_unhandled(key);
}
public static String
Key__adler32 = "adler32", Key__crc32 = "crc32"
;
public static final Jre_checksum_factory Instance = new Jre_checksum_factory(); Jre_checksum_factory() {}
}

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.security.MessageDigest;
public class Jre_hash_algo implements Hash_algo {
private final Jre_hash_factory factory;
private final MessageDigest md;
public Jre_hash_algo(Jre_hash_factory factory, String key) {
this.factory = factory;
this.key = key;
this.md = factory.New_algo_under(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Jre_hash_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {md.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
byte[] md_bry = md.digest();
return gplx.core.encoders.Hex_utl_.Encode_bry(md_bry);
}
}

@ -13,9 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.junit.*;
public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
public class Jre_hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/md5/Md5-128.unverified.test-vectors
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__md5());
@Test public void Empty() {fxt.Test__hash("d41d8cd98f00b204e9800998ecf8427e", "");}
@Test public void a() {fxt.Test__hash("0cc175b9c0f1b6a831c399e269772661", "a");}
@ -29,11 +29,3 @@ public class Hash_algo__md5__tst { // REF: https://www.cosic.esat.kuleuven.be/ne
//@Test
public void A__x_1million() {fxt.Test__hash("7707d6ae4e027c70eea2a935c2296f21", String_.Repeat("a", 1000000));}
}
class Hash_algo__fxt {
private final Hash_algo algo;
public Hash_algo__fxt(Hash_algo algo) {this.algo = algo;}
public void Test__hash(String expd, String raw) {
Tfds.Eq(expd, algo.Hash_bry_as_str(Bry_.new_u8(raw)));
Tfds.Eq(expd, algo.Hash_stream_as_str(gplx.core.consoles.Console_adp_.Noop, gplx.core.ios.streams.IoStream_.mem_txt_(Io_url_.Empty, raw)));
}
}

@ -13,9 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.junit.*;
public class Hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
public class Jre_hash_algo__sha1__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha1());
@Test public void Empty() {fxt.Test__hash("da39a3ee5e6b4b0d3255bfef95601890afd80709", "");}
@Test public void a() {fxt.Test__hash("86f7e437faa5a7fce15d1ddcb9eaeaea377667b8", "a");}

@ -13,9 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security; import gplx.*; import gplx.core.*;
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.junit.*;
public class Hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
public class Jre_hash_algo__sha2_256__tst { // REF: https://www.cosic.esat.kuleuven.be/nessie/testvectors/
private final Hash_algo__fxt fxt = new Hash_algo__fxt(Hash_algo_.New__sha2_256());
@Test public void Empty() {fxt.Test__hash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "");}
@Test public void a() {fxt.Test__hash("ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a");}

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.jre; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Jre_hash_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Jre_hash_algo(this, key);
}
public MessageDigest New_algo_under(String key) {
try {return MessageDigest.getInstance(key);}
catch (NoSuchAlgorithmException e) {throw Err_.new_missing_key(key);}
}
public static String
Key__md5 = "md5", Key__sha1 = "sha1", Key__sha2_256 = "sha-256"
;
public static final Jre_hash_factory Instance = new Jre_hash_factory(); Jre_hash_factory() {}
}

@ -17,7 +17,7 @@ package gplx.gfui.imgs; import gplx.*; import gplx.gfui.*;
import org.junit.*;
import gplx.core.consoles.*;
import gplx.core.ios.*;
import gplx.core.security.*;
import gplx.core.security.algos.*;
import gplx.gfui.imgs.*;
public class ImageAdp_tst {
@Before public void setup() {
@ -39,8 +39,8 @@ public class ImageAdp_tst {
Tfds.Eq_true(CompareAble_.Is(CompareAble_.More, afterModifiedTime, beforeModifiedTime));
Hash_algo algo = Hash_algo_.New__md5();
String loadHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(load));
String saveHash = algo.Hash_stream_as_str(Console_adp_.Noop, Io_mgr.Instance.OpenStreamRead(save));
String loadHash = Hash_algo_utl.Calc_hash_as_str(algo, Io_mgr.Instance.LoadFilBry(load));
String saveHash = Hash_algo_utl.Calc_hash_as_str(algo, Io_mgr.Instance.LoadFilBry(save));
Tfds.Eq(loadHash, saveHash);
}
}

@ -13,5 +13,9 @@
<classpathentry exported="true" kind="lib" path="lib/vnu.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Saxon-HE-9.9.1-2.jar"/>
<classpathentry exported="true" kind="src" path="/luaj_xowa"/>
<classpathentry kind="lib" path="lib/utils-1.0.jar"/>
<classpathentry kind="lib" path="lib/bcprov-jdk15on-164.jar"/>
<classpathentry kind="lib" path="lib/gnu-crypto.jar"/>
<classpathentry kind="lib" path="lib/jacksum.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,117 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.security.algos.bouncy_castle.*;
import gplx.core.security.algos.getopt.*;
import gplx.core.security.algos.gnu_crypto.*;
import gplx.core.security.algos.jre.*;
import gplx.core.security.algos.jacksum.*;
public class Hash_algo_factory__php_ {
public static Hash_algo_factory__composite New() {
Hash_algo_factory__composite rv = new Hash_algo_factory__composite();
rv.Reg_many(Bouncy_castle_factory.Instance
, Bouncy_castle_factory.Key__md2, Bouncy_castle_factory.Key__md4, Bouncy_castle_factory.Key__md5
, Bouncy_castle_factory.Key__sha1, Bouncy_castle_factory.Key__sha224, Bouncy_castle_factory.Key__sha256, Bouncy_castle_factory.Key__sha384
);
rv.Reg_one(Bouncy_castle_factory.Instance, Bouncy_castle_factory.Key__sha_512_224, "sha512/224");
rv.Reg_one(Bouncy_castle_factory.Instance, Bouncy_castle_factory.Key__sha_512_256, "sha512/256");
rv.Reg_many(Bouncy_castle_factory.Instance
, Bouncy_castle_factory.Key__sha512
, Bouncy_castle_factory.Key__sha3_224, Bouncy_castle_factory.Key__sha3_256, Bouncy_castle_factory.Key__sha3_384, Bouncy_castle_factory.Key__sha3_512
, Bouncy_castle_factory.Key__ripemd128, Bouncy_castle_factory.Key__ripemd160, Bouncy_castle_factory.Key__ripemd256, Bouncy_castle_factory.Key__ripemd320
, Bouncy_castle_factory.Key__whirlpool
);
rv.Reg_one(Jacksum_factory.Instance, Jacksum_factory.Key__tiger_128, "tiger128,3");
rv.Reg_one(Jacksum_factory.Instance, Jacksum_factory.Key__tiger_160, "tiger160,3");
rv.Reg_one(Jacksum_factory.Instance, Jacksum_factory.Key__tiger_192, "tiger192,3");
rv.Reg_many(Jacksum_factory.Instance, Jacksum_factory.Key__gost);
rv.Reg_many(Jre_checksum_factory.Instance, Jre_checksum_factory.Key__adler32);
// "crc" may be BZ2 CRC; https://stackoverflow.com/questions/40741707/php-hashcrc32-and-crc32-return-different-value
rv.Reg_one(Jre_checksum_factory.Instance, Jre_checksum_factory.Key__crc32, "crc32b"); // PHP crc32b is the equivalent of Java CRC
rv.Reg_many(Getopt_factory.Instance
, Getopt_factory.Key__fnv132, Getopt_factory.Key__fnv164, Getopt_factory.Key__fnv1a32, Getopt_factory.Key__fnv1a64
);
rv.Reg_many(Gnu_haval_factory.Instance
, Gnu_haval_factory.Key__haval128_3, Gnu_haval_factory.Key__haval160_3, Gnu_haval_factory.Key__haval192_3, Gnu_haval_factory.Key__haval224_3, Gnu_haval_factory.Key__haval256_3
, Gnu_haval_factory.Key__haval128_4, Gnu_haval_factory.Key__haval160_4, Gnu_haval_factory.Key__haval192_4, Gnu_haval_factory.Key__haval224_4, Gnu_haval_factory.Key__haval256_4
, Gnu_haval_factory.Key__haval128_5, Gnu_haval_factory.Key__haval160_5, Gnu_haval_factory.Key__haval192_5, Gnu_haval_factory.Key__haval224_5, Gnu_haval_factory.Key__haval256_5
);
return rv;
}
}
/*
URL: https://en.wikipedia.org/w/index.php?title=Module:Sandbox/Gnosygnu&action=edit
SRC: mw.logObject(mw.hash.listAlgorithms())
OUT:
table#1 {
"md2", -- bouncycastle
"md4", -- bouncycastle
"md5", -- bouncycastle
"sha1", -- bouncycastle
"sha224", -- bouncycastle
"sha256", -- bouncycastle
"sha384", -- bouncycastle
"sha512/224", -- bouncycastle
"sha512/256", -- bouncycastle
"sha512", -- bouncycastle
"sha3-224", -- bouncycastle
"sha3-256", -- bouncycastle
"sha3-384", -- bouncycastle
"sha3-512", -- bouncycastle
"ripemd128", -- bouncycastle
"ripemd160", -- bouncycastle
"ripemd256", -- bouncycastle
"ripemd320", -- bouncycastle
"whirlpool", -- bouncycastle
"tiger128,3", -- jacksum
"tiger160,3", -- jacksum
"tiger192,3", -- jacksum
"tiger128,4",
"tiger160,4",
"tiger192,4",
"snefru",
"snefru256",
"gost", -- jacksum; not in bouncycastle (tried GOST3411; GOST3411-2012-256; GOST3411-2012-512)
"gost-crypto",
"adler32", -- jre
"crc32",
"crc32b", -- jre
"fnv132", -- getopt
"fnv1a32", -- getopt
"fnv164", -- getopt
"fnv1a64", -- getopt
"joaat",
"haval128,3", -- gnu-crypto
"haval160,3", -- gnu-crypto
"haval192,3", -- gnu-crypto
"haval224,3", -- gnu-crypto
"haval256,3", -- gnu-crypto
"haval128,4", -- gnu-crypto
"haval160,4", -- gnu-crypto
"haval192,4", -- gnu-crypto
"haval224,4", -- gnu-crypto
"haval256,4", -- gnu-crypto
"haval128,5", -- gnu-crypto
"haval160,5", -- gnu-crypto
"haval192,5", -- gnu-crypto
"haval224,5", -- gnu-crypto
"haval256,5", -- gnu-crypto
}
REF:
* https://www.bouncycastle.org/specifications.html
* https://www.gnu.org/software/gnu-crypto/manual/api/gnu/crypto/hash/BaseHash.html
*/

@ -0,0 +1,48 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.bouncy_castle; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gplx.core.encoders.*;
import java.security.MessageDigest;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class Bouncy_castle_algo implements Hash_algo {
private static boolean Provider_needs_init = true;
private final MessageDigest md;
public Bouncy_castle_algo(String key) {
// register BounceCastleProvider
if (Provider_needs_init) {
Provider_needs_init = false;
Security.addProvider(new BouncyCastleProvider());
}
// get digest
try {
this.key = key;
this.md = MessageDigest.getInstance(key);
}
catch (Exception exc) {
throw Err_.new_wo_type("unknown messageDigest; key=" + key);
}
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Bouncy_castle_algo(key);}
public void Update_digest(byte[] bry, int bgn, int end) {md.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
// get hash
byte[] hash = md.digest();
return Hex_utl_.Encode_bry(hash);
}
}

@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.bouncy_castle; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
public class Bouncy_castle_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Bouncy_castle_algo(key);
}
public static String
Key__md2 = "md2", Key__md4 = "md4", Key__md5 = "md5"
, Key__sha1 = "sha1", Key__sha224 = "sha224", Key__sha256 = "sha256", Key__sha384 = "sha384"
, Key__sha_512_224 = "sha-512/224", Key__sha_512_256 = "sha-512/256", Key__sha512 = "sha512"
, Key__sha3_224 = "sha3-224", Key__sha3_256 = "sha3-256", Key__sha3_384 = "sha3-384", Key__sha3_512 = "sha3-512"
, Key__ripemd128 = "ripemd128", Key__ripemd160 = "ripemd160", Key__ripemd256 = "ripemd256", Key__ripemd320 = "ripemd320"
, Key__whirlpool = "whirlpool"
;
public static final Bouncy_castle_factory Instance = new Bouncy_castle_factory(); Bouncy_castle_factory() {}
}

@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.getopt; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.getopt.util.hash.FNV1;
public class Getopt_algo implements Hash_algo {
private final Getopt_factory factory;
private final FNV1 hash;
private final int pad_min;
public Getopt_algo(Getopt_factory factory, String key) {
this.key = key;
this.factory = factory;
this.pad_min = String_.Has_at_end(key, "32") ? 7 : 15;
this.hash = factory.New_FNV1(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Getopt_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {hash.init(bry, bgn, end);}
public byte[] To_hash_bry() {
long val = hash.getHash();
String rv = Long.toHexString(val);
if (String_.Len(rv) == pad_min)
rv = "0" + rv;
return Bry_.new_u8(rv);
}
}

@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.getopt; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import org.getopt.util.hash.*;
public class Getopt_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Getopt_algo(this, key);
}
public FNV1 New_FNV1(String key) {
if (String_.Eq(key, Key__fnv132)) return new FNV132();
else if (String_.Eq(key, Key__fnv164)) return new FNV164();
else if (String_.Eq(key, Key__fnv1a32)) return new FNV1a32();
else if (String_.Eq(key, Key__fnv1a64)) return new FNV1a64();
else throw Err_.new_unhandled(key);
}
public static String
Key__fnv132 = "fnv132", Key__fnv164 = "fnv164", Key__fnv1a32 = "fnv1a32", Key__fnv1a64 = "fnv1a64"
;
public static final Getopt_factory Instance = new Getopt_factory(); Getopt_factory() {}
}

@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.gnu_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gnu.crypto.hash.Haval;
import gnu.crypto.hash.Tiger;
public class Gnu_haval_algo implements Hash_algo {
private final Gnu_haval_factory factory;
private final Haval haval;
public Gnu_haval_algo(Gnu_haval_factory factory, String key) {
this.factory = factory;
this.key = key;
this.haval = factory.New_Haval(key);
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Gnu_haval_algo(factory, key);}
public void Update_digest(byte[] bry, int bgn, int end) {haval.update(bry, bgn, end);}
public byte[] To_hash_bry() {
byte[] rv = haval.digest();
return gplx.core.encoders.Hex_utl_.Encode_bry(rv);
}
}

@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.gnu_crypto; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gnu.crypto.hash.Haval;
public class Gnu_haval_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Gnu_haval_algo(this, key);
}
public Haval New_Haval(String key) {
// parse key for size; EX: "128" in "haval128,3"
int size = Int_.Parse_or(String_.Mid(key, 5, 8), -1);
switch (size) {
case 128: size = Haval.HAVAL_128_BIT; break;
case 160: size = Haval.HAVAL_160_BIT; break;
case 192: size = Haval.HAVAL_192_BIT; break;
case 224: size = Haval.HAVAL_224_BIT; break;
case 256: size = Haval.HAVAL_256_BIT; break;
default: throw Err_.new_unhandled_default(size);
}
// parse key for round; EX: "3" in "haval128,3"
int round = Int_.Parse_or(String_.Mid(key, 9, 10), -1);
switch (round) {
case 3: round = Haval.HAVAL_3_ROUND; break;
case 4: round = Haval.HAVAL_4_ROUND; break;
case 5: round = Haval.HAVAL_5_ROUND; break;
default: throw Err_.new_unhandled_default(round);
}
return new Haval(size, round);
}
public static String
Key__haval128_3 = "haval128,3", Key__haval160_3 = "haval160,3", Key__haval192_3 = "haval192,3", Key__haval224_3 = "haval224,3", Key__haval256_3 = "haval256,3"
, Key__haval128_4 = "haval128,4", Key__haval160_4 = "haval160,4", Key__haval192_4 = "haval192,4", Key__haval224_4 = "haval224,4", Key__haval256_4 = "haval256,4"
, Key__haval128_5 = "haval128,5", Key__haval160_5 = "haval160,5", Key__haval192_5 = "haval192,5", Key__haval224_5 = "haval224,5", Key__haval256_5 = "haval256,5"
;
public static final Gnu_haval_factory Instance = new Gnu_haval_factory(); Gnu_haval_factory() {}
}

@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.jacksum; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
import gplx.core.encoders.*;
import java.security.NoSuchAlgorithmException;
import jonelo.jacksum.JacksumAPI;
import jonelo.jacksum.algorithm.AbstractChecksum;
public class Jacksum_algo implements Hash_algo {
private final AbstractChecksum checksum;
public Jacksum_algo(String key) {
this.key = key;
try {
this.checksum = JacksumAPI.getChecksumInstance(key);
} catch (NoSuchAlgorithmException nsae) {
throw Err_.new_wo_type("jacksum algo doesn't exist: key=" + key);
}
}
public String Key() {return key;} private final String key;
public Hash_algo Clone_hash_algo() {return new Jacksum_algo(key);}
public void Update_digest(byte[] bry, int bgn, int end) {checksum.update(bry, bgn, end - bgn);}
public byte[] To_hash_bry() {
byte[] rv = checksum.getByteArray();
return gplx.core.encoders.Hex_utl_.Encode_bry(rv);
}
}

@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.algos.jacksum; import gplx.*; import gplx.core.*; import gplx.core.security.*; import gplx.core.security.algos.*;
public class Jacksum_factory implements Hash_algo_factory {
public Hash_algo New_hash_algo(String key) {
return new Jacksum_algo(key);
}
public Object New_Checksum(String key) {
return null;
}
public static String // REF: /source/jonelo/jacksum/JacksumAPI.java
Key__tiger_128 = "tiger-128", Key__tiger_160 = "tiger-160", Key__tiger_192= "tiger-192", Key__gost = "gost"
;
public static final Jacksum_factory Instance = new Jacksum_factory(); Jacksum_factory() {}
}

@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.files; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import gplx.core.security.algos.*;
public class Cksum_list {
public Cksum_list(byte type, Cksum_itm[] itms, long itms_size) {
this.Type = type; this.Itms = itms; this.Itms_size = itms_size;

@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.core.security.files; import gplx.*; import gplx.core.*; import gplx.core.security.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.core.security.algos.*;
public class Cksum_list_tst {
private final Cksum_list_fxt fxt = new Cksum_list_fxt();
@Test public void Basic() {
@ -40,7 +41,7 @@ class Cksum_list_fxt {
}
public Cksum_itm Make__itm(String hash, String file_name, long size) {return new Cksum_itm(Bry_.new_u8(hash), dir.GenSubFil(file_name), size);}
public Cksum_list_fxt Test__parse(String raw, long expd_size, Cksum_itm... expd_itms) {
Cksum_list actl_list = Cksum_list.Parse(gplx.core.security.Hash_algo_.Tid__md5, dir, Bry_.new_u8(raw));
Cksum_list actl_list = Cksum_list.Parse(Hash_algo_.Tid__md5, dir, Bry_.new_u8(raw));
Gftest.Eq__long(expd_size, actl_list.Itms_size);
Gftest.Eq__ary(expd_itms, actl_list.Itms);
return this;

@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*;
import gplx.core.security.*; import gplx.core.security.files.*;
import gplx.core.security.algos.*; import gplx.core.security.files.*;
public class Xobc_cmd__verify_dir extends Xobc_cmd__base {
private final Io_url delete_fil, checksum_fil;
public Xobc_cmd__verify_dir(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_idx, Io_url checksum_fil, Io_url delete_fil) {super(task_mgr, task_id, step_id, cmd_idx);
@ -41,7 +41,7 @@ public class Xobc_cmd__verify_dir extends Xobc_cmd__base {
gplx.core.ios.streams.IoStream stream = Io_mgr.Instance.OpenStreamRead(itm.File_url);
byte[] actl_hash = Bry_.Empty;
this.Prog_data_cur_(prog_data_cur);
try {actl_hash = algo.Hash_stream_as_bry(this, stream);}
try {actl_hash = Hash_algo_utl.Calc_hash_w_prog_as_bry(algo, stream, this);}
finally {stream.Rls();}
prog_data_cur += itm.File_size;
if (this.Prog_notify_and_chk_if_suspended(prog_data_cur, Prog_data_end())) return;

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.centrals.cmds; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.core.progs.*; import gplx.core.security.*;
import gplx.core.progs.*; import gplx.core.security.algos.*;
public class Xobc_cmd__verify_fil extends Xobc_cmd__base {
private final Io_url src_url; private final byte[] expd_hash;
public Xobc_cmd__verify_fil(Xobc_task_mgr task_mgr, int task_id, int step_id, int cmd_id, Io_url src_url, String expd_hash_str, long prog_data_end) {super(task_mgr, task_id, step_id, cmd_id);
@ -30,7 +30,7 @@ public class Xobc_cmd__verify_fil extends Xobc_cmd__base {
Hash_algo algo = Hash_algo_.New__md5();
gplx.core.ios.streams.IoStream stream = Io_mgr.Instance.OpenStreamRead(src_url);
byte[] actl_hash = Bry_.Empty;
try {actl_hash = algo.Hash_stream_as_bry(this, stream);}
try {actl_hash = Hash_algo_utl.Calc_hash_w_prog_as_bry(algo, stream, this);}
finally {stream.Rls();}
if (this.Prog_status() != Gfo_prog_ui_.Status__suspended && !Bry_.Eq(expd_hash, actl_hash))
this.Cmd_exec_err_(Xobc_cmd__verify_fil.Err_make(actl_hash, expd_hash));

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.exports.packs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
import gplx.core.progs.*; import gplx.core.ios.zips.*; import gplx.core.ios.streams.*; import gplx.core.security.*;
import gplx.core.progs.*; import gplx.core.ios.zips.*; import gplx.core.ios.streams.*; import gplx.core.security.algos.*;
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.fsdb.*; import gplx.fsdb.meta.*;
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.hosts.*; import gplx.xowa.addons.bldrs.centrals.tasks.*;
public class Pack_file_mgr {
@ -138,7 +138,7 @@ public class Pack_file_mgr {
Io_url raw_url = raw_urls[i];
IoStream raw_stream = Io_mgr.Instance.OpenStreamRead(raw_url);
byte[] raw_md5 = null;
try {raw_md5 = hash_algo.Hash_stream_as_bry(Gfo_prog_ui_.Noop, raw_stream);}
try {raw_md5 = Hash_algo_utl.Calc_hash_w_prog_as_bry(hash_algo, raw_stream, Gfo_prog_ui_.Noop);}
finally {raw_stream.Rls();}
tmp_bfr.Add(raw_md5).Add_byte_space().Add_byte(Byte_ascii.Star).Add_str_a7(raw_url.NameAndExt()).Add_byte_nl();
raw_size += raw_stream.Len();
@ -156,7 +156,7 @@ public class Pack_file_mgr {
Gfo_log_.Instance.Prog("hashing zip");
IoStream zip_stream = Io_mgr.Instance.OpenStreamRead(zip_url);
byte[] zip_md5 = null;
try {zip_md5 = hash_algo.Hash_stream_as_bry(Gfo_prog_ui_.Noop, zip_stream);}
try {zip_md5 = Hash_algo_utl.Calc_hash_w_prog_as_bry(hash_algo, zip_stream, Gfo_prog_ui_.Noop);}
finally {zip_stream.Rls();}
long zip_len = Io_mgr.Instance.QueryFil(zip_url).Size();

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.exports.packs.splits; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.exports.*; import gplx.xowa.addons.bldrs.exports.packs.*;
import gplx.core.progs.*; import gplx.core.ios.zips.*; import gplx.core.ios.streams.*; import gplx.core.security.*;
import gplx.core.progs.*; import gplx.core.ios.zips.*; import gplx.core.ios.streams.*; import gplx.core.security.algos.*;
import gplx.dbs.*;
import gplx.xowa.wikis.data.*;
import gplx.xowa.addons.bldrs.centrals.dbs.*; import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*; import gplx.xowa.addons.bldrs.centrals.steps.*;
@ -97,7 +97,7 @@ class Pack_mgr {
Io_url raw_url = raw_urls[i];
IoStream raw_stream = Io_mgr.Instance.OpenStreamRead(raw_url);
byte[] raw_md5 = null;
try {raw_md5 = hash_algo.Hash_stream_as_bry(Gfo_prog_ui_.Noop, raw_stream);}
try {raw_md5 = Hash_algo_utl.Calc_hash_w_prog_as_bry(hash_algo, raw_stream, Gfo_prog_ui_.Noop);}
finally {raw_stream.Rls();}
tmp_bfr.Add(raw_md5).Add_byte_space().Add_byte(Byte_ascii.Star).Add_str_a7(raw_url.NameAndExt()).Add_byte_nl();
raw_size += raw_stream.Len();
@ -126,7 +126,7 @@ class Pack_mgr {
Gfo_log_.Instance.Prog("hashing zip");
IoStream zip_stream = Io_mgr.Instance.OpenStreamRead(zip_url);
byte[] zip_md5 = null;
try {zip_md5 = hash_algo.Hash_stream_as_bry(Gfo_prog_ui_.Noop, zip_stream);}
try {zip_md5 = Hash_algo_utl.Calc_hash_w_prog_as_bry(hash_algo, zip_stream, Gfo_prog_ui_.Noop);}
finally {zip_stream.Rls();}
long zip_len = Io_mgr.Instance.QueryFil(zip_url).Size();

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.addons.bldrs.files.cksums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.core.ios.streams.*; import gplx.core.security.*;
import gplx.core.ios.streams.*; import gplx.core.security.algos.*;
import gplx.dbs.*; import gplx.xowa.addons.bldrs.files.cksums.dbs.*;
import gplx.xowa.files.*; import gplx.fsdb.*; import gplx.fsdb.data.*;
public class Xocksum_calc_mgr {
@ -49,7 +49,7 @@ public class Xocksum_calc_mgr {
bin_bry = Bry_.Empty;
}
row.Bin_size_(bin_bry.length);
byte[] md5 = md5_algo.Hash_bry_as_bry(bin_bry);
byte[] md5 = Hash_algo_utl.Calc_hash_as_bry(md5_algo, bin_bry);
if (!Bry_.Eq(md5, row.Cksum_val())) {
row.Cksum_val_(md5);
updates.Add(row);

@ -14,13 +14,13 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.files; import gplx.*; import gplx.xowa.*;
import gplx.core.consoles.*; import gplx.langs.htmls.encoders.*;
import gplx.core.consoles.*; import gplx.langs.htmls.encoders.*; import gplx.core.security.algos.*;
public class Xof_file_wkr_ {
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
private static final Hash_algo md5_hash = Hash_algo_.New__md5();
public static final Gfo_url_encoder Md5_decoder = Gfo_url_encoder_.New__http_url().Init__same__many(Byte_ascii.Plus).Make();
public static byte[] Md5_fast(byte[] v) {
synchronized (md5_hash) {
return md5_hash.Hash_bry_as_bry(v);
return Hash_algo_utl.Calc_hash_as_bry(md5_hash, v);
}
}
public static byte[] Md5(byte[] ttl) {

@ -49,33 +49,3 @@ abstract class Json_itm_wkr__base implements Json_itm_wkr {
public abstract void Read_kv_sub(byte[] key, byte[] val);
private static final byte[] Name_metadata = Bry_.new_a7("@metadata");
}
class Json_itm_wkr__gfs extends Json_itm_wkr__base {
private Xoa_gfs_bldr gfs_bldr = new Xoa_gfs_bldr();
private Xol_csv_parser csv_parser = Xol_csv_parser.Instance;
private Bry_bfr bfr;
public byte[] Xto_bry() {return gfs_bldr.Xto_bry();}
@Override public void Exec_bgn() {
bfr = gfs_bldr.Bfr();
gfs_bldr.Add_proc_init_many("this", "messages", "load_text").Add_paren_bgn().Add_nl();
gfs_bldr.Add_quote_xtn_bgn();
}
@Override public void Exec_end() {
gfs_bldr.Add_quote_xtn_end().Add_paren_end().Add_term_nl();
}
@Override public void Read_kv_sub(byte[] key, byte[] val) {
csv_parser.Save(bfr, key); // key
bfr.Add_byte_pipe(); // |
csv_parser.Save(bfr, val); // val
bfr.Add_byte_nl(); // \n
}
}
class Json_itm_wkr__msgs extends Json_itm_wkr__base {
private Xol_msg_mgr msg_mgr; private boolean dirty;
public void Ctor(boolean dirty, Xol_msg_mgr msg_mgr) {this.dirty = dirty; this.msg_mgr = msg_mgr;}
@Override public void Read_kv_sub(byte[] key, byte[] val) {
Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(key);
Xol_msg_itm_.update_val_(msg_itm, val);
if (dirty) // bldr needs to dirty message to generate lang.gfs; DATE:2014-08-05
msg_itm.Dirty_(true);
}
}

@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.langs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.apps.gfs.*; import gplx.xowa.langs.parsers.*;
class Json_itm_wkr__gfs extends Json_itm_wkr__base {
private Xoa_gfs_bldr gfs_bldr = new Xoa_gfs_bldr();
private Xol_csv_parser csv_parser = Xol_csv_parser.Instance;
private Bry_bfr bfr;
public byte[] Xto_bry() {return gfs_bldr.Xto_bry();}
@Override public void Exec_bgn() {
bfr = gfs_bldr.Bfr();
gfs_bldr.Add_proc_init_many("this", "messages", "load_text").Add_paren_bgn().Add_nl();
gfs_bldr.Add_quote_xtn_bgn();
}
@Override public void Exec_end() {
gfs_bldr.Add_quote_xtn_end().Add_paren_end().Add_term_nl();
}
@Override public void Read_kv_sub(byte[] key, byte[] val) {
csv_parser.Save(bfr, key); // key
bfr.Add_byte_pipe(); // |
csv_parser.Save(bfr, val); // val
bfr.Add_byte_nl(); // \n
}
}

@ -0,0 +1,27 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.langs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
import gplx.xowa.langs.msgs.*;
class Json_itm_wkr__msgs extends Json_itm_wkr__base {
private Xol_msg_mgr msg_mgr; private boolean dirty;
public void Ctor(boolean dirty, Xol_msg_mgr msg_mgr) {this.dirty = dirty; this.msg_mgr = msg_mgr;}
@Override public void Read_kv_sub(byte[] key, byte[] val) {
Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(key);
Xol_msg_itm_.update_val_(msg_itm, val);
if (dirty) // bldr needs to dirty message to generate lang.gfs; DATE:2014-08-05
msg_itm.Dirty_(true);
}
}

@ -14,13 +14,13 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.math; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.envs.*;
import gplx.core.envs.*; import gplx.core.security.algos.*;
import gplx.langs.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*;
class Xomath_html_wtr {
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(512);
private final Xomath_subst_mgr subst_mgr = new Xomath_subst_mgr();
private final gplx.core.security.Hash_algo md5_wkr = gplx.core.security.Hash_algo_.New__md5();
private final Hash_algo md5_wkr = Hash_algo_.New__md5();
private final Bry_fmt
fmt__latex = Bry_fmt.Auto( "<img id='xowa_math_img_~{math_idx}' src='' width='' height=''/><span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>")
, fmt__mathjax = Bry_fmt.Auto("<span id='xowa_math_txt_~{math_idx}'>~{math_text}</span>");
@ -40,7 +40,7 @@ class Xomath_html_wtr {
int uid = page.Xtn__math_uid__next();
if (is_latex) {
byte[] math_src = subst_mgr.Subst(math_bry);
byte[] md5 = md5_wkr.Hash_bry_as_bry(math_src);
byte[] md5 = Hash_algo_utl.Calc_hash_as_bry(md5_wkr, math_src);
// make url
byte dir_spr = Op_sys.Cur().Fsys_dir_spr_byte();

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.scores; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*; import gplx.core.envs.*;
import gplx.core.primitives.*; import gplx.core.envs.*; import gplx.core.security.algos.*;
import gplx.xowa.htmls.*; import gplx.langs.htmls.entitys.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.files.*;
import gplx.xowa.guis.views.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.lnkis.*;
@ -54,7 +54,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
Xox_mgr_base.Xtn_write_escape(app, bfr, code);
bfr.Add(Xoh_consts.Pre_end);
}
private static final gplx.core.security.Hash_algo sha1_hash = gplx.core.security.Hash_algo_.New__sha1();
private static final Hash_algo sha1_hash = Hash_algo_.New__sha1();
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) {
Xowe_wiki wiki = ctx.Wiki(); Xoae_page page = ctx.Page();
Score_xtn_mgr score_xtn = (Score_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Score_xtn_mgr.XTN_KEY);
@ -67,7 +67,7 @@ public class Score_xnde implements Xox_xnde, Mwh_atr_itm_owner1, Xoh_cmd_itm {
if (ly_process.Exe_exists() == Bool_.N_byte) {Html_write_code_as_pre(bfr, app); return;}
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
tmp_bfr.Add(code).Add_byte_pipe().Add_int_bool(lang_is_abc).Add_byte_pipe().Add_int_bool(code_is_raw);
sha1 = sha1_hash.Hash_bry_as_bry(tmp_bfr.To_bry_and_rls()); // NOTE: MW transforms to base32; for now, keep sha1 as raw
sha1 = Hash_algo_utl.Calc_hash_as_bry(sha1_hash, tmp_bfr.To_bry_and_rls()); // NOTE: MW transforms to base32; for now, keep sha1 as raw
sha1_prefix = String_.new_a7(sha1, 0, 8);
output_dir = app.Fsys_mgr().File_dir().GenSubDir_nest(wiki.Domain_str(), "lilypond", Char_.To_str(sha1[0]), Char_.To_str(sha1[1]), String_.new_a7(sha1)); // NOTE: MW also adds an extra level for 8-len; EX: /.../sha1_32_len/sha1_8_len/
png_file = output_dir.GenSubFil(sha1_prefix + ".png");

@ -38,6 +38,7 @@ public class Scrib_core {
lib_message = new Scrib_lib_message(this);
lib_text = new Scrib_lib_text(this);
lib_html = new Scrib_lib_html(this);
lib_hash = new Scrib_lib_hash(this);
lib_wikibase = new Scrib_lib_wikibase(this);
lib_wikibase_entity = new Scrib_lib_wikibase_entity(this);
}
@ -67,6 +68,7 @@ public class Scrib_core {
public Scrib_lib_message Lib_message() {return lib_message;} private Scrib_lib_message lib_message;
public Scrib_lib_text Lib_text() {return lib_text;} private Scrib_lib_text lib_text;
public Scrib_lib_html Lib_html() {return lib_html;} private Scrib_lib_html lib_html;
public Scrib_lib_hash Lib_hash() {return lib_hash;} private Scrib_lib_hash lib_hash;
public Scrib_lib_wikibase Lib_wikibase() {return lib_wikibase;} private Scrib_lib_wikibase lib_wikibase;
public Scrib_lib_wikibase_entity Lib_wikibase_entity() {return lib_wikibase_entity;} private Scrib_lib_wikibase_entity lib_wikibase_entity;
public Scrib_core Init() { // REF:LuaCommon.php!Load
@ -80,7 +82,8 @@ public class Scrib_core {
, root_dir.GenSubFil_nest("engines", "LuaStandalone", "mw_main.lua").Raw()
, root_dir.Raw()
);
Init_register(script_dir, lib_mw, lib_uri, lib_ustring, lib_language, lib_site, lib_title, lib_text, lib_html, lib_message, lib_wikibase, lib_wikibase_entity);
Init_register(script_dir, lib_mw, lib_uri, lib_ustring, lib_language, lib_site, lib_title, lib_text, lib_html, lib_message, lib_hash
, lib_wikibase, lib_wikibase_entity);
xtn_mgr.Lib_mgr().Init_for_core(this, script_dir);
return this;
}

@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.core.security.*; import gplx.core.security.algos.*;
import gplx.xowa.xtns.scribunto.procs.*;
public class Scrib_lib_hash implements Scrib_lib {
public Scrib_lib_hash(Scrib_core core) {}
public String Key() {return "mw.hash";}
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
public Scrib_lib Init() {
procs.Init_by_lib(this, Proc_names);
return this;
}
public Scrib_lib Clone_lib(Scrib_core core) {return new Scrib_lib_hash(core);}
public Scrib_lua_mod Register(Scrib_core core, Io_url script_dir) {
Init();
mod = core.RegisterInterface(this, script_dir.GenSubFil("mw.hash.lua"));
return mod;
}
public Scrib_proc_mgr Procs() {return procs;} private final Scrib_proc_mgr procs = new Scrib_proc_mgr();
public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) {
switch (key) {
case Proc_listAlgorithms: return ListAlgorithms(args, rslt);
case Proc_hashValue: return HashValue(args, rslt);
default: throw Err_.new_unhandled(key);
}
}
private static final int Proc_listAlgorithms = 0, Proc_hashValue = 1;
public static final String Invk_listAlgorithms = "listAlgorithms", Invk_hashValue = "hashValue";
private static final String[] Proc_names = String_.Ary(Invk_listAlgorithms, Invk_hashValue);
public boolean ListAlgorithms(Scrib_proc_args args, Scrib_proc_rslt rslt) {// NOTE:listAlgorithms
return rslt.Init_many_kvs(algo_keys);
}
public boolean HashValue(Scrib_proc_args args, Scrib_proc_rslt rslt) {
// return null if algo_key and val are not given
if (args.Len() != 2)
return rslt.Init_obj(null); // 2 args
// get args
String algo_key = args.Xstr_str_or_null(0);
byte[] val = args.Xstr_bry_or_null(1);
// get algo or fail
Hash_algo algo = algo_factory.New_hash_algo(algo_key);
if (algo == null) {
throw Err_.new_wo_type("Hash_algo is unknown; key=" + algo_key);
}
return rslt.Init_obj(String_.new_u8(Hash_algo_utl.Calc_hash_as_bry(algo, val)));
}
private static final Hash_algo_factory__composite algo_factory = Hash_algo_factory__php_.New();
private static final Keyval[] algo_keys = Make_algo_keys(algo_factory);
private static Keyval[] Make_algo_keys(Hash_algo_factory__composite factory) {
String[] keys = factory.Algo_keys();
int len = keys.length;
Keyval[] rv = new Keyval[len];
for (int i = 0; i < len; i++) {
rv[i] = Keyval_.int_(i + Scrib_core.Base_1, keys[i]);
}
return new Keyval[] {Keyval_.int_(Scrib_core.Base_1, rv)}; // NOTE: this hierarchy is needed for Scribunto; see also Scrib_proc_rslt.Init_bry_ary
}
}

@ -0,0 +1,503 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*;
public class Scrib_lib_hash_tst {
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_hash().Init();
} private Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
@Test public void ListAlgorithms() {
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_hash.Invk_listAlgorithms, Object_.Ary_empty, String_.Concat_lines_nl
( "1="
, " 1=md2"
, " 2=md4"
, " 3=md5"
, " 4=sha1"
, " 5=sha224"
, " 6=sha256"
, " 7=sha384"
, " 8=sha-512/224"
, " 9=sha-512/256"
, " 10=sha512"
, " 11=sha3-224"
, " 12=sha3-256"
, " 13=sha3-384"
, " 14=sha3-512"
, " 15=ripemd128"
, " 16=ripemd160"
, " 17=ripemd256"
, " 18=ripemd320"
, " 19=whirlpool"
, " 20=tiger-128"
, " 21=tiger-160"
, " 22=tiger-192"
, " 23=gost"
, " 24=adler32"
, " 25=crc32"
, " 26=fnv132"
, " 27=fnv164"
, " 28=fnv1a32"
, " 29=fnv1a64"
, " 30=haval128,3"
, " 31=haval160,3"
, " 32=haval192,3"
, " 33=haval224,3"
, " 34=haval256,3"
, " 35=haval128,4"
, " 36=haval160,4"
, " 37=haval192,4"
, " 38=haval224,4"
, " 39=haval256,4"
, " 40=haval128,5"
, " 41=haval160,5"
, " 42=haval192,5"
, " 43=haval224,5"
, " 44=haval256,5"
)
);
}
// OPENSGX: https://github.com/sslab-gatech/opensgx/blob/master/libsgx/mbedtls/tests/suites/test_suite_mdx.data
private static final String[] Test_vectors = new String[]
{ ""
, "a"
, "abc"
, "message digest"
, "abcdefghijklmnopqrstuvwxyz"
};
@Test public void Md2() {
String algo_key = "md2";
Test__HashValue(algo_key, Test_vectors[0], "8350e5a3e24c153df2275c9f80692773");
Test__HashValue(algo_key, Test_vectors[1], "32ec01ec4a6dac72c0ab96fb34c0b5d1");
Test__HashValue(algo_key, Test_vectors[2], "da853b0d3f88d99b30283a69e6ded6bb");
Test__HashValue(algo_key, Test_vectors[3], "ab4f496bfb2a530b219ff33031fe06b0");
Test__HashValue(algo_key, Test_vectors[4], "4e8ddff3650292ab5a4108c3aa47940b");
}
@Test public void Md4() {
String algo_key = "md4";
Test__HashValue(algo_key, Test_vectors[0], "31d6cfe0d16ae931b73c59d7e0c089c0");
Test__HashValue(algo_key, Test_vectors[1], "bde52cb31de33e46245e05fbdbd6fb24");
Test__HashValue(algo_key, Test_vectors[2], "a448017aaf21d8525fc10ae87aa6729d");
Test__HashValue(algo_key, Test_vectors[3], "d9130a8164549fe818874806e1c7014b");
Test__HashValue(algo_key, Test_vectors[4], "d79e1c308aa5bbcdeea8ed63df412da9");
}
@Test public void Md5() {
String algo_key = "md5";
Test__HashValue(algo_key, Test_vectors[0], "d41d8cd98f00b204e9800998ecf8427e");
Test__HashValue(algo_key, Test_vectors[1], "0cc175b9c0f1b6a831c399e269772661");
Test__HashValue(algo_key, Test_vectors[2], "900150983cd24fb0d6963f7d28e17f72");
Test__HashValue(algo_key, Test_vectors[3], "f96b697d7cb7938d525a2f31aaf161d0");
Test__HashValue(algo_key, Test_vectors[4], "c3fcd3d76192e4007dfb496cca67e13b");
}
@Test public void SHA1() {
String algo_key = "sha1";
Test__HashValue(algo_key, Test_vectors[0], "da39a3ee5e6b4b0d3255bfef95601890afd80709");
Test__HashValue(algo_key, Test_vectors[1], "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
Test__HashValue(algo_key, Test_vectors[2], "a9993e364706816aba3e25717850c26c9cd0d89d");
Test__HashValue(algo_key, Test_vectors[3], "c12252ceda8be8994d5fa0290a47231c1d16aae3");
Test__HashValue(algo_key, Test_vectors[4], "32d10c7b8cf96570ca04ce37f2a19d84240d3a89");
}
@Test public void SHA224() {
String algo_key = "sha224";
Test__HashValue(algo_key, Test_vectors[0], "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f");
Test__HashValue(algo_key, Test_vectors[1], "abd37534c7d9a2efb9465de931cd7055ffdb8879563ae98078d6d6d5");
Test__HashValue(algo_key, Test_vectors[2], "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7");
Test__HashValue(algo_key, Test_vectors[3], "2cb21c83ae2f004de7e81c3c7019cbcb65b71ab656b22d6d0c39b8eb");
Test__HashValue(algo_key, Test_vectors[4], "45a5f72c39c5cff2522eb3429799e49e5f44b356ef926bcf390dccc2");
}
@Test public void SHA256() {
String algo_key = "sha256";
Test__HashValue(algo_key, Test_vectors[0], "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
Test__HashValue(algo_key, Test_vectors[1], "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb");
Test__HashValue(algo_key, Test_vectors[2], "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
Test__HashValue(algo_key, Test_vectors[3], "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650");
Test__HashValue(algo_key, Test_vectors[4], "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73");
}
@Test public void SHA384() {
String algo_key = "sha384";
Test__HashValue(algo_key, Test_vectors[0], "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b");
Test__HashValue(algo_key, Test_vectors[1], "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31");
Test__HashValue(algo_key, Test_vectors[2], "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7");
Test__HashValue(algo_key, Test_vectors[3], "473ed35167ec1f5d8e550368a3db39be54639f828868e9454c239fc8b52e3c61dbd0d8b4de1390c256dcbb5d5fd99cd5");
Test__HashValue(algo_key, Test_vectors[4], "feb67349df3db6f5924815d6c3dc133f091809213731fe5c7b5f4999e463479ff2877f5f2936fa63bb43784b12f3ebb4");
}
@Test public void SHA512_224() {
String algo_key = "sha512/224";
Test__HashValue(algo_key, Test_vectors[0], "6ed0dd02806fa89e25de060c19d3ac86cabb87d6a0ddd05c333b84f4");
Test__HashValue(algo_key, Test_vectors[1], "d5cdb9ccc769a5121d4175f2bfdd13d6310e0d3d361ea75d82108327");
Test__HashValue(algo_key, Test_vectors[2], "4634270f707b6a54daae7530460842e20e37ed265ceee9a43e8924aa");
Test__HashValue(algo_key, Test_vectors[3], "ad1a4db188fe57064f4f24609d2a83cd0afb9b398eb2fcaeaae2c564");
Test__HashValue(algo_key, Test_vectors[4], "ff83148aa07ec30655c1b40aff86141c0215fe2a54f767d3f38743d8");
}
@Test public void SHA512_256() {
String algo_key = "sha512/256";
Test__HashValue(algo_key, Test_vectors[0], "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a");
Test__HashValue(algo_key, Test_vectors[1], "455e518824bc0601f9fb858ff5c37d417d67c2f8e0df2babe4808858aea830f8");
Test__HashValue(algo_key, Test_vectors[2], "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23");
Test__HashValue(algo_key, Test_vectors[3], "0cf471fd17ed69d990daf3433c89b16d63dec1bb9cb42a6094604ee5d7b4e9fb");
Test__HashValue(algo_key, Test_vectors[4], "fc3189443f9c268f626aea08a756abe7b726b05f701cb08222312ccfd6710a26");
}
@Test public void SHA512() {
String algo_key = "sha512";
Test__HashValue(algo_key, Test_vectors[0], "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
Test__HashValue(algo_key, Test_vectors[1], "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75");
Test__HashValue(algo_key, Test_vectors[2], "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
Test__HashValue(algo_key, Test_vectors[3], "107dbf389d9e9f71a3a95f6c055b9251bc5268c2be16d6c13492ea45b0199f3309e16455ab1e96118e8a905d5597b72038ddb372a89826046de66687bb420e7c");
Test__HashValue(algo_key, Test_vectors[4], "4dbff86cc2ca1bae1e16468a05cb9881c97f1753bce3619034898faa1aabe429955a1bf8ec483d7421fe3c1646613a59ed5441fb0f321389f77f48a879c7b1f1");
}
@Test public void SHA3_224() {
String algo_key = "sha3-224";
Test__HashValue(algo_key, Test_vectors[0], "6b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7");
Test__HashValue(algo_key, Test_vectors[1], "9e86ff69557ca95f405f081269685b38e3a819b309ee942f482b6a8b");
Test__HashValue(algo_key, Test_vectors[2], "e642824c3f8cf24ad09234ee7d3c766fc9a3a5168d0c94ad73b46fdf");
Test__HashValue(algo_key, Test_vectors[3], "18768bb4c48eb7fc88e5ddb17efcf2964abd7798a39d86a4b4a1e4c8");
Test__HashValue(algo_key, Test_vectors[4], "5cdeca81e123f87cad96b9cba999f16f6d41549608d4e0f4681b8239");
}
@Test public void SHA3_256() {
String algo_key = "sha3-256";
Test__HashValue(algo_key, Test_vectors[0], "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a");
Test__HashValue(algo_key, Test_vectors[1], "80084bf2fba02475726feb2cab2d8215eab14bc6bdd8bfb2c8151257032ecd8b");
Test__HashValue(algo_key, Test_vectors[2], "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532");
Test__HashValue(algo_key, Test_vectors[3], "edcdb2069366e75243860c18c3a11465eca34bce6143d30c8665cefcfd32bffd");
Test__HashValue(algo_key, Test_vectors[4], "7cab2dc765e21b241dbc1c255ce620b29f527c6d5e7f5f843e56288f0d707521");
}
@Test public void SHA3_384() {
String algo_key = "sha3-384";
Test__HashValue(algo_key, Test_vectors[0], "0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004");
Test__HashValue(algo_key, Test_vectors[1], "1815f774f320491b48569efec794d249eeb59aae46d22bf77dafe25c5edc28d7ea44f93ee1234aa88f61c91912a4ccd9");
Test__HashValue(algo_key, Test_vectors[2], "ec01498288516fc926459f58e2c6ad8df9b473cb0fc08c2596da7cf0e49be4b298d88cea927ac7f539f1edf228376d25");
Test__HashValue(algo_key, Test_vectors[3], "d9519709f44af73e2c8e291109a979de3d61dc02bf69def7fbffdfffe662751513f19ad57e17d4b93ba1e484fc1980d5");
Test__HashValue(algo_key, Test_vectors[4], "fed399d2217aaf4c717ad0c5102c15589e1c990cc2b9a5029056a7f7485888d6ab65db2370077a5cadb53fc9280d278f");
}
@Test public void SHA3_512() {
String algo_key = "sha3-512";
Test__HashValue(algo_key, Test_vectors[0], "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26");
Test__HashValue(algo_key, Test_vectors[1], "697f2d856172cb8309d6b8b97dac4de344b549d4dee61edfb4962d8698b7fa803f4f93ff24393586e28b5b957ac3d1d369420ce53332712f997bd336d09ab02a");
Test__HashValue(algo_key, Test_vectors[2], "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0");
Test__HashValue(algo_key, Test_vectors[3], "3444e155881fa15511f57726c7d7cfe80302a7433067b29d59a71415ca9dd141ac892d310bc4d78128c98fda839d18d7f0556f2fe7acb3c0cda4bff3a25f5f59");
Test__HashValue(algo_key, Test_vectors[4], "af328d17fa28753a3c9f5cb72e376b90440b96f0289e5703b729324a975ab384eda565fc92aaded143669900d761861687acdc0a5ffa358bd0571aaad80aca68");
}
@Test public void RipeMD128() {
String algo_key = "ripemd128";
Test__HashValue(algo_key, Test_vectors[0], "cdf26213a150dc3ecb610f18f6b38b46");
Test__HashValue(algo_key, Test_vectors[1], "86be7afa339d0fc7cfc785e72f578d33");
Test__HashValue(algo_key, Test_vectors[2], "c14a12199c66e4ba84636b0f69144c77");
Test__HashValue(algo_key, Test_vectors[3], "9e327b3d6e523062afc1132d7df9d1b8");
Test__HashValue(algo_key, Test_vectors[4], "fd2aa607f71dc8f510714922b371834e");
}
@Test public void RipeMD160() {
String algo_key = "ripemd160";
Test__HashValue(algo_key, Test_vectors[0], "9c1185a5c5e9fc54612808977ee8f548b2258d31");
Test__HashValue(algo_key, Test_vectors[1], "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");
Test__HashValue(algo_key, Test_vectors[2], "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");
Test__HashValue(algo_key, Test_vectors[3], "5d0689ef49d2fae572b881b123a85ffa21595f36");
Test__HashValue(algo_key, Test_vectors[4], "f71c27109c692c1b56bbdceb5b9d2865b3708dbc");
}
@Test public void RipeMD256() {
String algo_key = "ripemd256";
Test__HashValue(algo_key, Test_vectors[0], "02ba4c4e5f8ecd1877fc52d64d30e37a2d9774fb1e5d026380ae0168e3c5522d");
Test__HashValue(algo_key, Test_vectors[1], "f9333e45d857f5d90a91bab70a1eba0cfb1be4b0783c9acfcd883a9134692925");
Test__HashValue(algo_key, Test_vectors[2], "afbd6e228b9d8cbbcef5ca2d03e6dba10ac0bc7dcbe4680e1e42d2e975459b65");
Test__HashValue(algo_key, Test_vectors[3], "87e971759a1ce47a514d5c914c392c9018c7c46bc14465554afcdf54a5070c0e");
Test__HashValue(algo_key, Test_vectors[4], "649d3034751ea216776bf9a18acc81bc7896118a5197968782dd1fd97d8d5133");
}
@Test public void RipeMD320() {
String algo_key = "ripemd320";
Test__HashValue(algo_key, Test_vectors[0], "22d65d5661536cdc75c1fdf5c6de7b41b9f27325ebc61e8557177d705a0ec880151c3a32a00899b8");
Test__HashValue(algo_key, Test_vectors[1], "ce78850638f92658a5a585097579926dda667a5716562cfcf6fbe77f63542f99b04705d6970dff5d");
Test__HashValue(algo_key, Test_vectors[2], "de4c01b3054f8930a79d09ae738e92301e5a17085beffdc1b8d116713e74f82fa942d64cdbc4682d");
Test__HashValue(algo_key, Test_vectors[3], "3a8e28502ed45d422f68844f9dd316e7b98533fa3f2a91d29f84d425c88d6b4eff727df66a7c0197");
Test__HashValue(algo_key, Test_vectors[4], "cabdb1810b92470a2093aa6bce05952c28348cf43ff60841975166bb40ed234004b8824463e6b009");
}
@Test public void Whirlpool() {
String algo_key = "whirlpool";
Test__HashValue(algo_key, Test_vectors[0], "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3");
Test__HashValue(algo_key, Test_vectors[1], "8aca2602792aec6f11a67206531fb7d7f0dff59413145e6973c45001d0087b42d11bc645413aeff63a42391a39145a591a92200d560195e53b478584fdae231a");
Test__HashValue(algo_key, Test_vectors[2], "4e2448a4c6f486bb16b6562c73b4020bf3043e3a731bce721ae1b303d97e6d4c7181eebdb6c57e277d0e34957114cbd6c797fc9d95d8b582d225292076d4eef5");
Test__HashValue(algo_key, Test_vectors[3], "378c84a4126e2dc6e56dcc7458377aac838d00032230f53ce1f5700c0ffb4d3b8421557659ef55c106b4b52ac5a4aaa692ed920052838f3362e86dbd37a8903e");
Test__HashValue(algo_key, Test_vectors[4], "f1d754662636ffe92c82ebb9212a484a8d38631ead4238f5442ee13b8054e41b08bf2a9251c30b6a0b8aae86177ab4a6f68f673e7207865d5d9819a3dba4eb3b");
}
@Test public void Tiger128_3() {
String algo_key = "tiger128,3";
Test__HashValue(algo_key, Test_vectors[0], "3293ac630c13f0245f92bbb1766e1616");
Test__HashValue(algo_key, Test_vectors[1], "77befbef2e7ef8ab2ec8f93bf587a7fc");
Test__HashValue(algo_key, Test_vectors[2], "2aab1484e8c158f2bfb8c5ff41b57a52");
Test__HashValue(algo_key, Test_vectors[3], "d981f8cb78201a950dcf3048751e441c");
Test__HashValue(algo_key, Test_vectors[4], "1714a472eee57d30040412bfcc55032a");
}
@Test public void Tiger160_3() {
String algo_key = "tiger160,3";
Test__HashValue(algo_key, Test_vectors[0], "3293ac630c13f0245f92bbb1766e16167a4e5849");
Test__HashValue(algo_key, Test_vectors[1], "77befbef2e7ef8ab2ec8f93bf587a7fc613e247f");
Test__HashValue(algo_key, Test_vectors[2], "2aab1484e8c158f2bfb8c5ff41b57a525129131c");
Test__HashValue(algo_key, Test_vectors[3], "d981f8cb78201a950dcf3048751e441c517fca1a");
Test__HashValue(algo_key, Test_vectors[4], "1714a472eee57d30040412bfcc55032a0b11602f");
}
@Test public void Tiger192_3() {
String algo_key = "tiger192,3";
Test__HashValue(algo_key, Test_vectors[0], "3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3");
Test__HashValue(algo_key, Test_vectors[1], "77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809");
Test__HashValue(algo_key, Test_vectors[2], "2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93");
Test__HashValue(algo_key, Test_vectors[3], "d981f8cb78201a950dcf3048751e441c517fca1aa55a29f6");
Test__HashValue(algo_key, Test_vectors[4], "1714a472eee57d30040412bfcc55032a0b11602ff37beee9");
}
// NOTE: NOT YET SUPPORTED
// @Test public void Tiger128_4() {
// String algo_key = "tiger128,4";
// Test__HashValue(algo_key, Test_vectors[0], "24cc78a7f6ff3546e7984e59695ca13d");
// Test__HashValue(algo_key, Test_vectors[1], "e2a0e5e38b778421cceafbfe9a37068b");
// Test__HashValue(algo_key, Test_vectors[2], "538883c8fc5f28250299018e66bdf4fd");
// Test__HashValue(algo_key, Test_vectors[3], "a310058241bab4fd815e08a5afef6488");
// Test__HashValue(algo_key, Test_vectors[4], "758fbb6c5ae68a0aa85d2739bcdd9e43");
// }
// @Test public void Tiger160_4() {
// String algo_key = "tiger160,4";
// Test__HashValue(algo_key, Test_vectors[0], "24cc78a7f6ff3546e7984e59695ca13d804e0b68");
// Test__HashValue(algo_key, Test_vectors[1], "e2a0e5e38b778421cceafbfe9a37068b032093fd");
// Test__HashValue(algo_key, Test_vectors[2], "538883c8fc5f28250299018e66bdf4fdb5ef7b65");
// Test__HashValue(algo_key, Test_vectors[3], "a310058241bab4fd815e08a5afef648874b91fc8");
// Test__HashValue(algo_key, Test_vectors[4], "758fbb6c5ae68a0aa85d2739bcdd9e434e2af40f");
// }
// @Test public void Tiger192_4() {
// String algo_key = "tiger192,4";
// Test__HashValue(algo_key, Test_vectors[0], "24cc78a7f6ff3546e7984e59695ca13d804e0b686e255194");
// Test__HashValue(algo_key, Test_vectors[1], "e2a0e5e38b778421cceafbfe9a37068b032093fd36be1635");
// Test__HashValue(algo_key, Test_vectors[2], "538883c8fc5f28250299018e66bdf4fdb5ef7b65f2e91753");
// Test__HashValue(algo_key, Test_vectors[3], "a310058241bab4fd815e08a5afef648874b91fc8be4ed87d");
// Test__HashValue(algo_key, Test_vectors[4], "758fbb6c5ae68a0aa85d2739bcdd9e434e2af40f6aa305ed");
// }
// @Test public void Snefru() {
// String algo_key = "snefru";
// Test__HashValue(algo_key, Test_vectors[0], "8617f366566a011837f4fb4ba5bedea2b892f3ed8b894023d16ae344b2be5881");
// Test__HashValue(algo_key, Test_vectors[1], "45161589ac317be0ceba70db2573ddda6e668a31984b39bf65e4b664b584c63d");
// Test__HashValue(algo_key, Test_vectors[2], "7d033205647a2af3dc8339f6cb25643c33ebc622d32979c4b612b02c4903031b");
// Test__HashValue(algo_key, Test_vectors[3], "c5d4ce38daa043bdd59ed15db577500c071b917c1a46cd7b4d30b44a44c86df8");
// Test__HashValue(algo_key, Test_vectors[4], "9304bb2f876d9c4f54546cf7ec59e0a006bead745f08c642f25a7c808e0bf86e");
// }
// @Test public void Snefru256() {
// String algo_key = "snefru256";
// Test__HashValue(algo_key, Test_vectors[0], "8617f366566a011837f4fb4ba5bedea2b892f3ed8b894023d16ae344b2be5881");
// Test__HashValue(algo_key, Test_vectors[1], "45161589ac317be0ceba70db2573ddda6e668a31984b39bf65e4b664b584c63d");
// Test__HashValue(algo_key, Test_vectors[2], "7d033205647a2af3dc8339f6cb25643c33ebc622d32979c4b612b02c4903031b");
// Test__HashValue(algo_key, Test_vectors[3], "c5d4ce38daa043bdd59ed15db577500c071b917c1a46cd7b4d30b44a44c86df8");
// Test__HashValue(algo_key, Test_vectors[4], "9304bb2f876d9c4f54546cf7ec59e0a006bead745f08c642f25a7c808e0bf86e");
// }
@Test public void Gost() {
String algo_key = "gost";
Test__HashValue(algo_key, Test_vectors[0], "ce85b99cc46752fffee35cab9a7b0278abb4c2d2055cff685af4912c49490f8d");
Test__HashValue(algo_key, Test_vectors[1], "d42c539e367c66e9c88a801f6649349c21871b4344c6a573f849fdce62f314dd");
Test__HashValue(algo_key, Test_vectors[2], "f3134348c44fb1b2a277729e2285ebb5cb5e0f29c975bc753b70497c06a4d51d");
Test__HashValue(algo_key, Test_vectors[3], "ad4434ecb18f2c99b60cbe59ec3d2469582b65273f48de72db2fde16a4889a4d");
Test__HashValue(algo_key, Test_vectors[4], "3b7917937540a4f33ffcb5f37f29e8a9921b0655d7fd568d7cf27291cb897bb4");
}
// NOTE: NOT YET SUPPORTED
// @Test public void Gost_crypto() {
// String algo_key = "gost-crypto";
// Test__HashValue(algo_key, Test_vectors[0], "981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0");
// Test__HashValue(algo_key, Test_vectors[1], "e74c52dd282183bf37af0079c9f78055715a103f17e3133ceff1aacf2f403011");
// Test__HashValue(algo_key, Test_vectors[2], "b285056dbf18d7392d7677369524dd14747459ed8143997e163b2986f92fd42c");
// Test__HashValue(algo_key, Test_vectors[3], "bc6041dd2aa401ebfa6e9886734174febdb4729aa972d60f549ac39b29721ba0");
// Test__HashValue(algo_key, Test_vectors[4], "8cda28cd45ce733e3d0837aed41bdf7fda7d83a6dfe211a0c695259a443250bd");
// }
@Test public void Adler32() {
String algo_key = "adler32";
Test__HashValue(algo_key, Test_vectors[0], "00000001");
Test__HashValue(algo_key, Test_vectors[1], "00620062");
Test__HashValue(algo_key, Test_vectors[2], "024d0127");
Test__HashValue(algo_key, Test_vectors[3], "29750586");
Test__HashValue(algo_key, Test_vectors[4], "90860b20");
}
// NOTE: NOT YET SUPPORTED
// @Test public void Crc32() {
// String algo_key = "crc32";
// Test__HashValue(algo_key, Test_vectors[0], "00000000");
// Test__HashValue(algo_key, Test_vectors[1], "6b9b9319");
// Test__HashValue(algo_key, Test_vectors[2], "73bb8c64");
// Test__HashValue(algo_key, Test_vectors[3], "5703c9bf");
// Test__HashValue(algo_key, Test_vectors[4], "9693bf77");
// }
@Test public void Crc32b() {
String algo_key = "crc32b";
Test__HashValue(algo_key, Test_vectors[0], "00000000");
Test__HashValue(algo_key, Test_vectors[1], "e8b7be43");
Test__HashValue(algo_key, Test_vectors[2], "352441c2");
Test__HashValue(algo_key, Test_vectors[3], "20159d7f");
Test__HashValue(algo_key, Test_vectors[4], "4c2750bd");
}
@Test public void Fnv132() {
String algo_key = "fnv132";
Test__HashValue(algo_key, Test_vectors[0], "811c9dc5");
Test__HashValue(algo_key, Test_vectors[1], "050c5d7e");
Test__HashValue(algo_key, Test_vectors[2], "439c2f4b");
Test__HashValue(algo_key, Test_vectors[3], "62f6de5e");
Test__HashValue(algo_key, Test_vectors[4], "819dafd8");
}
@Test public void Fnv164() {
String algo_key = "fnv164";
Test__HashValue(algo_key, Test_vectors[0], "cbf29ce484222325");
Test__HashValue(algo_key, Test_vectors[1], "af63bd4c8601b7be");
Test__HashValue(algo_key, Test_vectors[2], "d8dcca186bafadcb");
Test__HashValue(algo_key, Test_vectors[3], "028945f18dedb23e");
Test__HashValue(algo_key, Test_vectors[4], "5367ac9a0a6338d8");
}
@Test public void Fnv1a32() {
String algo_key = "fnv1a32";
Test__HashValue(algo_key, Test_vectors[0], "811c9dc5");
Test__HashValue(algo_key, Test_vectors[1], "e40c292c");
Test__HashValue(algo_key, Test_vectors[2], "1a47e90b");
Test__HashValue(algo_key, Test_vectors[3], "b2c0f234");
Test__HashValue(algo_key, Test_vectors[4], "b0bc0c82");
}
@Test public void Fnv1a64() {
String algo_key = "fnv1a64";
Test__HashValue(algo_key, Test_vectors[0], "cbf29ce484222325");
Test__HashValue(algo_key, Test_vectors[1], "af63dc4c8601ec8c");
Test__HashValue(algo_key, Test_vectors[2], "e71fa2190541574b");
Test__HashValue(algo_key, Test_vectors[3], "2dcbcce86fce9934");
Test__HashValue(algo_key, Test_vectors[4], "8450deb1cdc382a2");
}
// NOTE: NOT YET SUPPORTED
// @Test public void Joaat() {
// Test__HashValue(algo_key, Test_vectors[0], "00000000");
// Test__HashValue(algo_key, Test_vectors[1], "ca2e9442");
// Test__HashValue(algo_key, Test_vectors[2], "ed131f5b");
// Test__HashValue(algo_key, Test_vectors[3], "81d3c49b");
// Test__HashValue(algo_key, Test_vectors[4], "b9f5ed0a");
// }
@Test public void Haval128_3() {
String algo_key = "haval128,3";
Test__HashValue(algo_key, Test_vectors[0], "c68f39913f901f3ddf44c707357a7d70");
Test__HashValue(algo_key, Test_vectors[1], "0cd40739683e15f01ca5dbceef4059f1");
Test__HashValue(algo_key, Test_vectors[2], "9e40ed883fb63e985d299b40cda2b8f2");
Test__HashValue(algo_key, Test_vectors[3], "3caf4a79e81adcd6d1716bcc1cef4573");
Test__HashValue(algo_key, Test_vectors[4], "dc502247fb3eb8376109eda32d361d82");
}
@Test public void Haval160_3() {
String algo_key = "haval160,3";
Test__HashValue(algo_key, Test_vectors[0], "d353c3ae22a25401d257643836d7231a9a95f953");
Test__HashValue(algo_key, Test_vectors[1], "4da08f514a7275dbc4cece4a347385983983a830");
Test__HashValue(algo_key, Test_vectors[2], "b21e876c4d391e2a897661149d83576b5530a089");
Test__HashValue(algo_key, Test_vectors[3], "43a47f6f1c016207f08be8115c0977bf155346da");
Test__HashValue(algo_key, Test_vectors[4], "eba9fa6050f24c07c29d1834a60900ea4e32e61b");
}
@Test public void Haval192_3() {
String algo_key = "haval192,3";
Test__HashValue(algo_key, Test_vectors[0], "e9c48d7903eaf2a91c5b350151efcb175c0fc82de2289a4e");
Test__HashValue(algo_key, Test_vectors[1], "b359c8835647f5697472431c142731ff6e2cddcacc4f6e08");
Test__HashValue(algo_key, Test_vectors[2], "a7b14c9ef3092319b0e75e3b20b957d180bf20745629e8de");
Test__HashValue(algo_key, Test_vectors[3], "6c4d9ec368efc96eeea58e132bdb2391c2b3e9d20190f7ea");
Test__HashValue(algo_key, Test_vectors[4], "a25e1456e6863e7d7c74017bb3e098e086ad4be0580d7056");
}
@Test public void Haval224_3() {
String algo_key = "haval224,3";
Test__HashValue(algo_key, Test_vectors[0], "c5aae9d47bffcaaf84a8c6e7ccacd60a0dd1932be7b1a192b9214b6d");
Test__HashValue(algo_key, Test_vectors[1], "731814ba5605c59b673e4caae4ad28eeb515b3abc2b198336794e17b");
Test__HashValue(algo_key, Test_vectors[2], "5bc955220ba2346a948d2848eca37bdd5eca6ecca7b594bd32923fab");
Test__HashValue(algo_key, Test_vectors[3], "edf3e4add009ee89ee8ab03c39a3c749d20a48319c50c3a83861c540");
Test__HashValue(algo_key, Test_vectors[4], "06ae38ebc43db58bd6b1d477c7b4e01b85a1e7b19b0bd088e33b58d1");
}
@Test public void Haval256_3() {
String algo_key = "haval256,3";
Test__HashValue(algo_key, Test_vectors[0], "4f6938531f0bc8991f62da7bbd6f7de3fad44562b8c6f4ebf146d5b4e46f7c17");
Test__HashValue(algo_key, Test_vectors[1], "47c838fbb4081d9525a0ff9b1e2c05a98f625714e72db289010374e27db021d8");
Test__HashValue(algo_key, Test_vectors[2], "8699f1e3384d05b2a84b032693e2b6f46df85a13a50d93808d6874bb8fb9e86c");
Test__HashValue(algo_key, Test_vectors[3], "911d1aad699e1b4a3a0e783bd5e68ba45392cc4915b1a17eca8a49da70879912");
Test__HashValue(algo_key, Test_vectors[4], "72fad4bde1da8c8332fb60561a780e7f504f21547b98686824fc33fc796afa76");
}
@Test public void Haval128_4() {
String algo_key = "haval128,4";
Test__HashValue(algo_key, Test_vectors[0], "ee6bbf4d6a46a679b3a856c88538bb98");
Test__HashValue(algo_key, Test_vectors[1], "5cd07f03330c3b5020b29ba75911e17d");
Test__HashValue(algo_key, Test_vectors[2], "6f2132867c9648419adcd5013e532fa2");
Test__HashValue(algo_key, Test_vectors[3], "faee633871b30771ecda708d66fe6551");
Test__HashValue(algo_key, Test_vectors[4], "b2a73b99775ffb17cd8781b85ec66221");
}
@Test public void Haval160_4() {
String algo_key = "haval160,4";
Test__HashValue(algo_key, Test_vectors[0], "1d33aae1be4146dbaaca0b6e70d7a11f10801525");
Test__HashValue(algo_key, Test_vectors[1], "e0a5be29627332034d4dd8a910a1a0e6fe04084d");
Test__HashValue(algo_key, Test_vectors[2], "77aca22f5b12cc09010afc9c0797308638b1cb9b");
Test__HashValue(algo_key, Test_vectors[3], "429346bb57211af6651060fd02db264fbe9c4365");
Test__HashValue(algo_key, Test_vectors[4], "1c7884af86d11ac120fe5df75cee792d2dfa48ef");
}
@Test public void Haval192_4() {
String algo_key = "haval192,4";
Test__HashValue(algo_key, Test_vectors[0], "4a8372945afa55c7dead800311272523ca19d42ea47b72da");
Test__HashValue(algo_key, Test_vectors[1], "856c19f86214ea9a8a2f0c4b758b973cce72a2d8ff55505c");
Test__HashValue(algo_key, Test_vectors[2], "7e29881ed05c915903dd5e24a8e81cde5d910142ae66207c");
Test__HashValue(algo_key, Test_vectors[3], "e91960a06afbc8bd9f400a16135ed66e2745ef01d6d1cdf7");
Test__HashValue(algo_key, Test_vectors[4], "2e2e581d725e799fda1948c75e85a28cfe1cf0c6324a1ada");
}
@Test public void Haval224_4() {
String algo_key = "haval224,4";
Test__HashValue(algo_key, Test_vectors[0], "3e56243275b3b81561750550e36fcd676ad2f5dd9e15f2e89e6ed78e");
Test__HashValue(algo_key, Test_vectors[1], "742f1dbeeaf17f74960558b44f08aa98bdc7d967e6c0ab8f799b3ac1");
Test__HashValue(algo_key, Test_vectors[2], "124c43d2ba4884599d013e8c872bfea4c88b0b6bf6303974cbe04e68");
Test__HashValue(algo_key, Test_vectors[3], "86e52ecc72ccaec188c17033fafe8b652705fd6a7d9db2e0d10cab92");
Test__HashValue(algo_key, Test_vectors[4], "a0ac696cdb2030fa67f6cc1d14613b1962a7b69b4378a9a1b9738796");
}
@Test public void Haval256_4() {
String algo_key = "haval256,4";
Test__HashValue(algo_key, Test_vectors[0], "c92b2e23091e80e375dadce26982482d197b1a2521be82da819f8ca2c579b99b");
Test__HashValue(algo_key, Test_vectors[1], "e686d2394a49b44d306ece295cf9021553221db132b36cc0ff5b593d39295899");
Test__HashValue(algo_key, Test_vectors[2], "8f409f1bb6b30c5016fdce55f652642261575bedca0b9533f32f5455459142b5");
Test__HashValue(algo_key, Test_vectors[3], "dbcc8e1011df45121d4ff2bb62c6c38949d76084f829c36d5929aee71b261f2f");
Test__HashValue(algo_key, Test_vectors[4], "124f6eb645dc407637f8f719cc31250089c89903bf1db8fac21ea4614df4e99a");
}
@Test public void Haval128_5() {
String algo_key = "haval128,5";
Test__HashValue(algo_key, Test_vectors[0], "184b8482a0c050dca54b59c7f05bf5dd");
Test__HashValue(algo_key, Test_vectors[1], "f23fbe704be8494bfa7a7fb4f8ab09e5");
Test__HashValue(algo_key, Test_vectors[2], "d054232fe874d9c6c6dc8e6a853519ea");
Test__HashValue(algo_key, Test_vectors[3], "c28052dc143c1c70450d3c0504756efe");
Test__HashValue(algo_key, Test_vectors[4], "0efff71d7d14344cba1f4b25f924a693");
}
@Test public void Haval160_5() {
String algo_key = "haval160,5";
Test__HashValue(algo_key, Test_vectors[0], "255158cfc1eed1a7be7c55ddd64d9790415b933b");
Test__HashValue(algo_key, Test_vectors[1], "f5147df7abc5e3c81b031268927c2b5761b5a2b5");
Test__HashValue(algo_key, Test_vectors[2], "ae646b04845e3351f00c5161d138940e1fa0c11c");
Test__HashValue(algo_key, Test_vectors[3], "2ac00ef52871b373eda407d7eafbd225987f33f1");
Test__HashValue(algo_key, Test_vectors[4], "917836a9d27eed42d406f6002e7d11a0f87c404c");
}
@Test public void Haval192_5() {
String algo_key = "haval192,5";
Test__HashValue(algo_key, Test_vectors[0], "4839d0626f95935e17ee2fc4509387bbe2cc46cb382ffe85");
Test__HashValue(algo_key, Test_vectors[1], "5ffa3b3548a6e2cfc06b7908ceb5263595df67cf9c4b9341");
Test__HashValue(algo_key, Test_vectors[2], "d12091104555b00119a8d07808a3380bf9e60018915b9025");
Test__HashValue(algo_key, Test_vectors[3], "8225efabaded623849843546cdf3c8c88e0fdca68f9a5a56");
Test__HashValue(algo_key, Test_vectors[4], "85f1f1c0eca04330cf2de5c8c83cf85a611b696f793284de");
}
@Test public void Haval224_5() {
String algo_key = "haval224,5";
Test__HashValue(algo_key, Test_vectors[0], "4a0513c032754f5582a758d35917ac9adf3854219b39e3ac77d1837e");
Test__HashValue(algo_key, Test_vectors[1], "67b3cb8d4068e3641fa4f156e03b52978b421947328bfb9168c7655d");
Test__HashValue(algo_key, Test_vectors[2], "8081027a500147c512e5f1055986674d746d92af4841abeb89da64ad");
Test__HashValue(algo_key, Test_vectors[3], "877a7b891fce89036fc127756b07923ece3ba7c495922909cc89512e");
Test__HashValue(algo_key, Test_vectors[4], "1b360acff7806502b5d40c71d237cc0c40343d2000ae2f65cf487c94");
}
@Test public void Haval256_5() {
String algo_key = "haval256,5";
Test__HashValue(algo_key, Test_vectors[0], "be417bb4dd5cfb76c7126f4f8eeb1553a449039307b1a3cd451dbfdc0fbbe330");
Test__HashValue(algo_key, Test_vectors[1], "de8fd5ee72a5e4265af0a756f4e1a1f65c9b2b2f47cf17ecf0d1b88679a3e22f");
Test__HashValue(algo_key, Test_vectors[2], "976cd6254c337969e5913b158392a2921af16fca51f5601d486e0a9de01156e7");
Test__HashValue(algo_key, Test_vectors[3], "7ccf22af7f99acd6ac84f176041329e2958fde1419a259d5a4b89d8f4115ad74");
Test__HashValue(algo_key, Test_vectors[4], "c9c7d8afa159fd9e965cb83ff5ee6f58aeda352c0eff005548153a61551c38ee");
}
private void Test__HashValue(String algo, String val, String expd) {
fxt.Test__proc__kvps__flat(lib, Scrib_lib_hash.Invk_hashValue, Object_.Ary(algo, val), expd);
}
}

@ -14,12 +14,12 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.wikias; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.htmls.*; import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.core.security.algos.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Tabber_xnde implements Xox_xnde {
private byte[] id;
private Tabber_tab_itm[] tab_itms_ary;
private static final gplx.core.security.Hash_algo md5_hash = gplx.core.security.Hash_algo_.New__md5();
private static final Hash_algo md5_hash = Hash_algo_.New__md5();
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
@ -27,7 +27,7 @@ public class Tabber_xnde implements Xox_xnde {
// split on "|-|"; EX: "A|-|B" -> tab_1='A'; tab_2='B'
List_adp tab_itms_list = List_adp_.New();
byte[] xnde_body = Xox_xnde_.Extract_body_or_null(src, xnde); if (xnde_body == null) return;
this.id = Id_test == null ? md5_hash.Hash_bry_as_bry(xnde_body) : Id_test;
this.id = Id_test == null ? Hash_algo_utl.Calc_hash_as_bry(md5_hash, xnde_body) : Id_test;
byte[][] tab_itms = Bry_split_.Split(xnde_body, Spr__tab_itms);
for (int i = 0; i < tab_itms.length; ++i) {
byte[] tab_itm = tab_itms[i];

@ -0,0 +1,30 @@
local hash = {}
local php
local util = require 'libraryUtil'
local checkType = util.checkType
function hash.listAlgorithms()
return php.listAlgorithms()
end
function hash.hashValue( algo, value )
checkType( 'hashValue', 1, algo, 'string' )
checkType( 'hashValue', 2, value, 'string' )
return php.hashValue( algo, value )
end
function hash.setupInterface()
-- Boilerplate
php = mw_interface
mw_interface = nil
-- Register this library in the "mw" global
mw = mw or {}
mw.hash = hash
package.loaded['mw.hash'] = hash
end
return hash

@ -66,7 +66,7 @@
<javac includeantruntime="false" target="${jdk}" source="${jdk}" sourcepath=""
srcdir ="${root_dir}/src/400_xowa"
destdir ="${root_dir}/src/400_xowa/bin"
classpath="${root_dir}/src/lib/junit.jar:${root_dir}/src/100_core/bin:${root_dir}/src/110_gfml/bin:${root_dir}/src/140_dbs/bin:${root_dir}/src/150_gfui/bin:${root_dir}/src/gplx.gflucene/bin:${root_dir}/bin/any/java/luaj/luaj_xowa.jar:${root_dir}/bin/any/java/jtidy/jtidy_xowa.jar:${root_dir}/bin/any/java/icu4j/icu4j-57_1.jar:${root_dir}/bin/any/java/vnu/vnu.jar:${root_dir}/bin/any/java/vnu/Saxon-HE-9.9.1-2.jar">
classpath="${root_dir}/src/lib/junit.jar:${root_dir}/src/100_core/bin:${root_dir}/src/110_gfml/bin:${root_dir}/src/140_dbs/bin:${root_dir}/src/150_gfui/bin:${root_dir}/src/gplx.gflucene/bin:${root_dir}/bin/any/java/luaj/luaj_xowa.jar:${root_dir}/bin/any/java/jtidy/jtidy_xowa.jar:${root_dir}/bin/any/java/icu4j/icu4j-57_1.jar:${root_dir}/bin/any/java/vnu/vnu.jar:${root_dir}/bin/any/java/vnu/Saxon-HE-9.9.1-2.jar:${root_dir}/bin/any/java/bouncycastle/bcprov-jdk15on-164.jar:${root_dir}/bin/any/java/getopt/utils-1.0.jar:${root_dir}/bin/any/java/gnu/gnu-crypto.jar:${root_dir}/bin/any/java/jacksum/jacksum.jar">
<compilerarg line="-encoding utf-8"/>
<include name="**/*.java"/>
</javac>

@ -4,7 +4,7 @@
<jar destfile="${xowa_jar_path}">
<manifest>
<attribute name="Main-Class" value="gplx.xowa.Xowa_main"/>
<attribute name="Class-Path" value=". bin/${plat_name}/swt/swt.jar bin/any/java/apache/commons-compress-1.18.jar bin/any/java/jdbc/sqlite/sqlite-jdbc-3.18.0.jar bin/any/java/luaj/luaj_xowa.jar bin/any/java/jtidy/jtidy_xowa.jar bin/any/java/xz/xz-1.5.jar bin/any/java/icu4j/icu4j-57_1.jar bin/any/java/lucene/5.3.0.drd/lucene-core-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-highlighter-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-memory-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-queryparser-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-analyzers-common-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-queries-5.3.0-mobile-2.jar bin/any/java/vnu/vnu.jar bin/any/java/vnu/Saxon-HE-9.9.1-2.jar"/>
<attribute name="Class-Path" value=". bin/${plat_name}/swt/swt.jar bin/any/java/apache/commons-compress-1.18.jar bin/any/java/jdbc/sqlite/sqlite-jdbc-3.18.0.jar bin/any/java/luaj/luaj_xowa.jar bin/any/java/jtidy/jtidy_xowa.jar bin/any/java/xz/xz-1.5.jar bin/any/java/icu4j/icu4j-57_1.jar bin/any/java/lucene/5.3.0.drd/lucene-core-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-highlighter-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-memory-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-queryparser-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-analyzers-common-5.3.0-mobile-2.jar bin/any/java/lucene/5.3.0.drd/lucene-queries-5.3.0-mobile-2.jar bin/any/java/vnu/vnu.jar bin/any/java/vnu/Saxon-HE-9.9.1-2.jar bin/any/java/bouncycastle/bcprov-jdk15on-164.jar bin/any/java/getopt/utils-1.0.jar bin/any/java/gnu/gnu-crypto.jar bin/any/java/jacksum/jacksum.jar"/>
</manifest>
<fileset dir="${root_dir}/src/baselib/bin"/>
<fileset dir="${root_dir}/src/100_core/bin"/>

@ -4,7 +4,7 @@
<jar destfile="./xowa_maven.jar">
<manifest>
<attribute name="Main-Class" value="gplx.xowa.Xowa_main"/>
<attribute name="Class-Path" value=". bin/${plat_name}/swt/swt.jar bin/any/java/apache/commons-compress-1.18.jar bin/any/java/jdbc/sqlite/sqlite-jdbc-3.18.0.jar bin/any/java/luaj/luaj_xowa.jar bin/any/java/jtidy/jtidy_xowa.jar bin/any/java/vnu/vnu.jar bin/any/java/vnu/Saxon-HE-9.9.1-2.jar"/>
<attribute name="Class-Path" value=". bin/${plat_name}/swt/swt.jar bin/any/java/apache/commons-compress-1.18.jar bin/any/java/jdbc/sqlite/sqlite-jdbc-3.18.0.jar bin/any/java/luaj/luaj_xowa.jar bin/any/java/jtidy/jtidy_xowa.jar bin/any/java/vnu/vnu.jar bin/any/java/vnu/Saxon-HE-9.9.1-2.jar bin/any/java/bouncycastle/bcprov-jdk15on-164.jar bin/any/java/getopt/utils-1.0.jar bin/any/java/gnu/gnu-crypto.jar bin/any/java/jacksum/jacksum.jar"/>
</manifest>
<fileset dir="target/classes/"/>
</jar>

@ -125,6 +125,20 @@
<artifactId>Saxon-HE</artifactId>
<version>9.9.1-2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.64</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.gnu/gnu-crypto -->
<dependency>
<groupId>org.gnu</groupId>
<artifactId>gnu-crypto</artifactId>
<version>2.0.1</version>
</dependency>
<!--
<dependency>

@ -11,7 +11,8 @@ $mvn install:install-file -Dfile=bin/any/java/lucene/5.3.0.drd/lucene-memory-5.3
$mvn install:install-file -Dfile=bin/any/java/lucene/5.3.0.drd/lucene-queries-5.3.0-mobile-2.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queries-mobile -Dversion=5.3.0 -Dpackaging=jar
$mvn install:install-file -Dfile=bin/any/java/lucene/5.3.0.drd/lucene-queryparser-5.3.0-mobile-2.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser-mobile -Dversion=5.3.0 -Dpackaging=jar
$mvn install:install-file -Dfile=bin/any/java/jdbc/sqlite/sqlite-jdbc-3.18.0.jar -DgroupId=xowa -DartifactId=sqllite -Dversion=3.18.0 -Dpackaging=jar
$mvn install:install-file -Dfile=bin/any/java/vnu/vnu.jar -DgroupId=xowa -DartifactId=validator -Dversion=18.11.5 -Dpackaging=jar
$mvn install:install-file -Dfile=bin/any/java/getopt/utils-1.0.jar -DgroupId=xowa -DartifactId=getopt -Dversion=1.0.0 -Dpackaging=jar
$mvn install:install-file -Dfile=bin/any/java/jacksum/jacksum.jar -DgroupId=xowa -DartifactId=jacksum -Dversion=1.0.0 -Dpackaging=jar
echo "* XOWA: running"
$mvn clean

Loading…
Cancel
Save